Saturday 10 July 2021

Play Audio from linux laptop to andriod device

 Hi All,
If you want to stream audio from linux to andriod devices lets do it.

I wanted this requirement because I have a old laptop. Speaker of the laptop are broken. I have installed xUbuntu on the laptop as limitation of RAM. 

You just need to install pactl.

Get the list of audio sources :
1) pactl list

2) Then start the audio server:

pactl load-module module-simple-protocol-tcp rate=48000 format=s16le channels=2 source=<SOURCE> record=true port=<PORT (eg 8000)>

source=number of source
port=port to which server listen.

e.g command

pactl load-module module-simple-protocol-tcp rate=48000 format=s16le channels=2 source=0 record=true port=8000


3) Download simple protocol player for andriod play store.

Enjoy the audio.

Cheers !!!

Let me know your feedback after you test it. I tested it. It works smooth. Still would test latecy on diffrent sample rates.

Multiple smart phones can be connected.

Friday 2 April 2021

Make your own pocket linux workstation.

We all know today mobiles are equivalent powerful as desktop. Then why we cant use our mobile as desktop ? I dont know how many of you asked yourself the same question. But yes I was exploring various methods available to use my mobile as work station, which I can carry anywhere just in pocket.

Many mobile company like samsung at already giving the support of connecting the HDMI to mobile from type c connection. Very less know feature samsung give in the their galaxy series of mobile is "DeX". Its when you connect hdmi cable to the type C connection (you will need docker or some converter to do it) you get a complete desktop view parallely one can use the mobile phone. Isn't it exciting !!!

On google play store there are many emulators of window,linux etc desktop are available. One can start the emulator and share the mobile screen to TV or connect type-C to hdmi. In this method your mobile is occupied with your desktop screen. For me this is less productive method, as I want my mobile me independent of the desktop usage.
Please note : Not all mobile support type-c to hdmi connection. please once check with your manufacturer about the support.

Besides this mostly all mobile today support mouse,keyboard,usb harddrive,usb pendrive peripheral support.(havnt checked USB camera support).

One of the most effective and productive way I found to achieve desktop environment in any mobile with no additional hardware. I am across https://andronix.app/. This is the android app available to guide you to the easy steps to get started.
- You need to install Termux android application. Its a bash terminal for android devices.

- Then to install the desktop enviroment need to run below command.

pkg update -y && pkg install curl proot tar -y && curl https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/Installer/Debian/debian-xfce.sh | bash

install window manager :

pkg update -y && pkg install curl proot tar -y && curl https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/Installer/Debian/debian-awesome.sh | bash

- Keep your wifi connected and check your mobile ipaddress by running
$ifconfig
On the termux.

 -once this is done. On the terminal you will find a bash script. Just run the script for example:
./start_debian

- This will put you to the terminal of your linux. Now to get Desktop UI you need to start
$vncserver-start -localhost no

- Get any VNC client install on the smart TV or your computer and give your Ipaddress and 5901 port address.

You are done. Now you can access your mobile power to its fullest and parallely use mobile for you daily work.

Some of my reviews :   
I have been uses this from the month. Its working perfectly. Performance would depend on your mobile phone. I am using a mid range smart phone with more than 50% memory used still I dont see a big performance degradation.
Yes. As we are using it as remote desktop there would be some delay. I would not feel same as native workstation. But for me thats okay. As I can work from anyplace with my environment in place.

I am writing this blog from the mobile desktop itself. Cheers !!!

 
Disclaimer : I have written this blog at 3 Apr 21. This is still in research phase. People are finding new ways to achieve this.
Please reach me <jaikothari10@gmail.com> or comment if you have more knowledge to add or anything similar you have explored. 

Friday 6 September 2019

Firewall in Ubuntu

The UFW firewall is the default firewall that ships standard with the Ubuntu Linux DistributionUFW stands for Uncomplicated Firewall.
  • To enable the ufw firewall, open a new Terminal window and execute the following command:
     
    sudo ufw enable
     
  • To disable the ufw firewall, open a new Terminal windows and execute the following command:
     
    sudo ufw disable
     
  • To view the status of the ufw execute the below command:
    sudo ufw status
     
     
    How do I disable the firewall in Ubuntu Linux server edition? How do I turn off the firewall in Ubuntu Linux version 12.04 or 14.04 LTS server?

    The latest version of Ubuntu comes with a program called ufw. It is used for managing a Linux firewall and aims to provide an easy to use interface for the user. [donotprint][/donotprint]

    A Note About ufw

    As I said earlier, the latest version of Ubuntu comes with ufw (now it is the default firewall configuration tool for Ubuntu). It is developed to ease iptables firewall configuration, ufw provides a user friendly way to create an IPv4 or IPv6 host-based firewall.

    List ufw firewall rules, enter:

    $ sudo ufw status verbose
    Sample outputs:
    Status: active
    Logging: on (low)
    Default: deny (incoming), allow (outgoing), deny (routed)
    New profiles: skip
     
    To                         Action      From
    --                         ------      ----
    71.81.22.14 80/tcp        ALLOW IN    Anywhere
    71.81.22.15 80/tcp        ALLOW IN    Anywhere
     

    To disable ufw based firewall, enter:

    $ sudo ufw disable4


    List current firewall rules and stop firewall (old method)

    You can type the following command to see if firewall is active or not (open a terminal or ssh session and type the following command):
    $ sudo iptables -L -n
    Sample outputs:
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:53 
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:53 
    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:67 
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:67 
     
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    ACCEPT     all  --  0.0.0.0/0            192.168.122.0/24    state RELATED,ESTABLISHED 
    ACCEPT     all  --  192.168.122.0/24     0.0.0.0/0           
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable 
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable 
     
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination
    You can save existing firewall rules as follows:
    $ sudo iptables-save > firewall.rules
    Finally, type the following commands to stop firewall and flush all the rules:
    $ sudo iptables -X
    $ sudo iptables -t nat -F
    $ sudo iptables -t nat -X
    $ sudo iptables -t mangle -F
    $ sudo iptables -t mangle -X
    $ sudo iptables -P INPUT ACCEPT
    $ sudo iptables -P FORWARD ACCEPT
    $ sudo iptables -P OUTPUT ACCEPT


     

Linux: The hole trick to bypass firewall restriction

Have you ever wondered how P2P software like Skype directly exchanges data when both client desktop sitting behind a firewall that only permits outgoing traffic.

This article explains how Skype & Co. get round firewalls using the hole trick. From the article:
Peer-to-peer software applications are a network administrator’s nightmare. In order to be able to exchange packets with their counterpart as directly as possible they use subtle tricks to punch holes in firewalls, which shouldn’t actually be letting in packets from the outside world.

This is a good article and a good idea carried out by Skype. This is not exactly a new concept (just search for NAT2NAT using google and you will get more information about this hack). Author has doen good job explaining the whole concept in clear language

How do I bypass Linux firewall restriction?

This article also covers DIY hole punching using standard hping2 and nc (netcat) tools under Linux. From the article:
Firstly start a UDP listener on UDP port 14141 on the local/1 console behind the firewall:

local/1# nc -u -l -p 14141
 
An external computer “remote” then attempts to contact it.

remote# echo "hello" | nc -p 53 -u local-fw 14141

However, as expected nothing is received on local/1 and, thanks to the firewall, nothing is returned to remote. Now on a second console, local/2, hping2, our universal tool for generating IP packets, punches a hole in the firewall:
 
local/2# hping2 -c 1 -2 -s 14141 -p 53 remote

As long as remote is behaving itself, it will send back a “port unreachable” response via ICMP – however this is of no consequence. On the second attempt
 
remote# echo "hello" | nc -p 53 -u local-fw 14141

The netcat listener on console local/1 then coughs up a “hello” – the UDP packet from outside has passed through the firewall and arrived at the computer behind it.
Right now there is no perfect solution exists, if you are using Linux based firewall to avoid abuse.

Saturday 15 July 2017

Get hands on Valgrind Utility

Valgrind utility can be used for many purpose
- Memory error detection
- Two Thread error detection
- A cache
- Branch prediction profiler
- A call-graph generating cache profiler, and a heap profiler. It also includes two experimental tools: a heap/stack/global array overrun detector, and a SimPoint basic block vector generator.

Before using the valgrind you need to install it on your computer. Installation process might defer according to the linux flavour you are using. I am using opensuse linux.

#zypper install valgrind

How Do I use valgrind?

Before running the program you need to put the command:

valgrind --leak-check=yes ./a.out arg1 arg2
valgrind --log-file=outfile.file --leak-check=yes --tool=memcheck ./a.out arg1 arg2

You can use other option like:
 --leak-check=full --show-leak-kinds=all

-A program running under Valgrind is not executed directly by the CPU. Instead it runs on a synthetic CPU provided by Valgrind. This is why a debugger cannot debug your program when it runs on Valgrind

 
 


 

Thursday 31 December 2015

RTSP RTCP and RTP

RTSP(Real-Time Stream Protocol )Is an application layer protocol based on the text, in the aspect of grammarand some message parameters, similar to the RTSP protocol and HTTP protocol.
RTSP is used to transfer control media flow is established, it plays the role of "remote control" for multimedia services. RTSP itself is not used for streaming data. Delivery of media data can be done by RTP/RTCP protocol.
The basic process of RTSP operation
First of all, the client connects to the streaming server and send an OPTIONS command received from the server response query method provided by the server, sending DESCRIBE commands to query a media file of SDP information. The streaming server through a SDP description of response, response information including the flow quantity, the media type and other information. The client analysis described in the SDP, and for each flow sends aSETUP command in SETUP session, the command tells the server to the client for receiving media data port. Streaming media connection setup is completed, the client sends a PLAY command, the server begins streaming data. During playback the client can play to the server to send PAUSE and other command and control flow. Communication is completed, the client can send the TERADOWN command to end a streaming session.
Is a complete client and server through Wireshark capture by RTSP interaction. Black font indicates that the client request, red font server response.

OPTIONS rtsp://10.34.3.80/D:/a.264 RTSP/1.0

CSeq: 2

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

RTSP/1.0 200 OK

CSeq: 2

Date: Tue, Jul 22 2014 02:41:21 GMT

Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER

DESCRIBE rtsp://10.34.3.80/D:/a.264 RTSP/1.0

CSeq: 3

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Accept: application/sdp

RTSP/1.0 200 OK

CSeq: 3

Date: Tue, Jul 22 2014 02:41:21 GMT

Content-Base: rtsp://10.34.3.80/D:/a.264/

Content-Type: application/sdp

Content-Length: 494

 

v=0

o=- 1405995833260880 1 IN IP4 10.34.3.80

s=H.264 Video, streamed by the LIVE555 Media Server

i=D:/a.264

t=0 0

a=tool:LIVE555 Streaming Media v2014.07.04

a=type:broadcast

a=control:*

a=range:npt=0-

a=x-qt-text-nam:H.264 Video, streamed by the LIVE555 Media Server

a=x-qt-text-inf:D:/a.264

m=video 0 RTP/AVP 96

c=IN IP4 0.0.0.0

b=AS:500

a=rtpmap:96 H264/90000

a=fmtp:96 packetization-mode=1;profile-level-id=42001E;sprop-parameter-sets=Z0IAHpWoLQSZ,aM48gA==

a=control:track1

SETUP rtsp://10.34.3.80/D:/a.264/track1 RTSP/1.0

CSeq: 4

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Transport: RTP/AVP;unicast;client_port=60094-60095

RTSP/1.0 200 OK

CSeq: 4

Date: Tue, Jul 22 2014 02:41:25 GMT

Transport: RTP/AVP;unicast;destination=10.34.3.80;source=10.34.3.80;client_port=60094-60095;server_port=6970-6971

Session: 54DAFD56;timeout=65

PLAY rtsp://10.34.3.80/D:/a.264/ RTSP/1.0

CSeq: 5

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Session: 54DAFD56

Range: npt=0.000-

RTSP/1.0 200 OK

CSeq: 5

Date: Tue, Jul 22 2014 02:41:25 GMT

Range: npt=0.000-

Session: 54DAFD56

RTP-Info: url=rtsp://10.34.3.80/D:/a.264/track1;seq=10244;rtptime=2423329550

GET_PARAMETER rtsp://10.34.3.80/D:/a.264/ RTSP/1.0

CSeq: 6

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Session: 54DAFD56

RTSP/1.0 200 OK

CSeq: 6

Date: Tue, Jul 22 2014 02:41:25 GMT

Session: 54DAFD56

Content-Length: 10

 

//Termination

TEARDOWN rtsp://10.34.3.80/D:/a.264/ RTSP/1.0

CSeq: 7

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Session: 54DAFD56

RTSP/1.0 200 OK

CSeq: 7

Date: Wed, Jul 30 2014 07:13:35 GMT

Can be found in the format of RTSP protocol and HTTP protocol is very similar, are text based protocol, grammar is basically the same. But they are not the same, the main difference:
Firstly, the method name is different. RTSP added DESCRIBE, SETUP, PLAY etc.
Secondly, the HTTP protocol is stateless protocol, sending no method between the apparent order relation. While the RTSP is a state of the protocol, the existing order relation method.
In HTTP protocol, data can be transmitted within the belt load data, such as Webpage data. While the RTSP only provides streaming control, does not deliver streaming media data. Streaming media data can be transmitted by way of RTP/RTCP.
Two, the RTSP message
1 RTSP request message format
The method name URL RTSP version CRLF
Message header CRLF CRLF
Enter the message body
Method names including OPTIONS, DESCRIBE, SETUP, PLAY, TEARDOWN etc.
URL is the recipient's address, such as: RTSP://192.168.0.1/video1.3gp.
The RTSP version is RTSP/1.0
The message of each will end with a newline, in order to facilitate the identification of the message header, the last line of the two carriage return.
The message body sometimes is optional.
2 response message format
RTSP version of the state code corresponding to the text interpretation newline
Message header CRLF CRLF
Enter the message body
The RTSP version is RTSP/1.0.
Status code indicates the corresponding message execution results.
Partial status code and text explanation list as follows:
The status code text explanation
"200" The success of OK implementation
"400" Bad Request error request
"404" Not Found not found
"500" Internal Internal Server Error server error
3 different methods in detail
(1)OPTIONS
The client uses OPTION to query the server to provide. The server in the public field are given to provide their own set of methods. From the above data can be seen in this server provides OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, GET_PARAMETER, SET_PARAMETER, PAUSE,, etc.
The OPTIONS method is not necessary. The client can bypass the OPTIONS, directly to the server to send other messages.
The CSeq field represents the request number. Each client request will be assigned a number. Each request message will correspond to a same ordinal response message.
The OPTIONS message can be sent at any time. Some clients will timing OPTION to send the message to the server. While the server can also be whether the timing of received OPTIONS messages through judging whether the client online. But not all clients and servers to do so.
User Agent
The domain for user identification. Different companies or different client. The domain of different client message of content are not the same. Sometimes indicates the client version number, model and so on.
Using VLC as the client specified in the field below the dialogue, and to publish the number and use the LIVE555 version of the library.
OPTIONS rtsp://10.34.3.80/D:/a.264 RTSP/1.0

CSeq: 2                                                                                              //Request number

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

RTSP/1.0 200 OK

CSeq: 2                                                                                              //Reply No.

Date: Tue, Jul 22 2014 02:41:21 GMT

Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER

(2)DESCRIBE
The DESCRIBE message is sent by the client to the server for the client, get relevant description request media file specified in the link, is generally SDP information. SDP(Session Description Protocol)Contains a description, media encoding type, media session rate and other information. For streaming media services, the following domain is in the SDP must contain.
"a=control:"
"a=range:"
"a=rtpmap:"
"a=fmtp:"
When a video contains audio also includes video, there will be more than one of the above structure. Each media description starts with M. The green and yellow background font respectively on the video and audio mediadescription. The Accept field in the request is used to specify the client can receive media description information types, here for the SDP information.
DESCRIBE rtsp://10.34.3.80/D:/a.264 RTSP/1.0

CSeq: 3

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Accept: application/sdp                                //Request access to SDP information

RTSP/1.0 200 OK

CSeq: 3

Date: Tue, Jul 22 2014 02:41:21 GMT

Content-Base: rtsp://10.34.3.80/D:/a.264/                   //Specify a media description information

Content-Type: application/sdp                                   //The type of request

Content-Length: 494                                                //The length of SDP

 

v=0                                            //Version SDP protocol version

o=- 1405995833260880 1 IN IP4 10.34.3.80            //Origion session originator information

s=H.264 Video, streamed by the LIVE555 Media Server  //The session name

 

i=D:/a.264                                                              //Description information session

t=0 0                                                                      //The session start and end time

a=tool:LIVE555 Streaming Media v2014.07.04          //Attribute

a=type:broadcast

a=control:*                                                             //Control information

a=range:npt=0-

a=x-qt-text-nam:H.264 Video, streamed by the LIVE555 Media Server

a=x-qt-text-inf:D:/a.264

m=video 0 RTP/AVP 96            //Support the sender media types (video) information

c=IN IP4 0.0.0.0               //Session connection information, spending real media stream using the IP address. 

b=AS:500                                //Video bandwidth

a=rtpmap:96 H264/90000          //The media attribute, video (H264 video format, 90000 sampling rate)

a=fmtp:96 packetization-mode=1;profile-level-id=42001E;sprop-parameter-sets=Z0IAHpWoLQSZ,aM48gA==

a=control:track1                       //The video using track 1

 

m=audio 0 RTP/AVP 97         //Media type (audio) following are to describe the information of the audio

b=AS:19                              //Audio bandwidth

a=rtpmap:97 MP4A-LATM/11025/1     //Video format (MP4A-LATM video format, 11025 sampling rate)

a=fmtp:97 profile-level-id=15; object=2; cpresent=0; config=40002A103FC0

a=mpeg4-esid:101=x-envivio-verid:00011118

a=control:trackID=2               /The audio using track 2

M is also called the media, described the sender support media type and other information, to explain in detail.
m=audio 3458 RTP/AVP 0 96 97
The first parameter to audio for media name: show the audio type.
The second parameter is the port number 3488, showed that UE in the local port to send 3458 audio stream.
The third parameter RTP/AVP as the transport protocol, RTP protocol based on UDP.
Fourth to seven parameters for the four kinds of payload type number support.
a=rtpmap:0 PCMU
a=rtpmap:96 G726-32/8000
a=rtpmap:97 AMR-WB
Properties for a media, to attribute the name: attribute value method.
Format: a=rtpmap:<payload type > <encoding name>
Payload type 0 fixed assigned to PCMU,
Coding scheme payload type 96 corresponding to G.726, dynamic distribution.
Payload type 97 corresponding encoding for the adaptive multi rate wideband coding (AMR-WB), dynamic allocation.
For the video
m=video 3400 RTP/AVP 98 99
The first parameter to the video for the media name: show the video type.
The second parameter is the port number 3400, showed that UE in the local port 3400 send video stream.
The third parameter RTP/AVP as the transport protocol, said RTP over UDP.
Fourth, five parameters are given. Two kinds of payload type number
a=rtpmap:98 MPV
a=rtpmap:99 H.261
Coding scheme payload Type 98 corresponding to MPV, dynamic distribution.
Payload type 97 corresponding encoding for the H.261, as dynamic allocation.
(3)SETUP
The SETUP message is used to determine the transfer mechanism, establishing a RTSP session. The client can also set up RTSP again after sending a SETUP request to change the transmission parameters for playing streaming media server may agree with these parameters. If you do not agree, will respond "455 Method Not Valid In This State".
The head of the Transport Request field in the data transmission parameters specified acceptable to the client,
The Transport header field in Response contains the server after confirmation of transmission parameters.
If the request does not contain a SessionID, then the server will produce a SessionID.
SETUP rtsp://10.34.3.80/D:/a.264/track1 RTSP/1.0   //Track1 said to set the channel 1.

CSeq: 4

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)   //The client version information

Transport: RTP/AVP;unicast;client_port=60094-60095       //RTP/AVP said the RTP agreement transmission parameters over, UDP, unicast unicast, multicast is used to distinguish. Client_port agreed by the client RTP RTCP port 60094, port 60095

RTSP/1.0 200 OK

CSeq: 4

Date: Tue, Jul 22 2014 02:41:25 GMT

Transport: RTP/AVP;unicast;destination=10.34.3.80;source=10.34.3.80;client_port=60094-60095;server_port=6970-6971 //The server specified by the transmission parameters

Session: 54DAFD56;timeout=65    //SessionID          
From the top of the SETUP session can be seen in the RTP port even said, RTCP for the TCP port adjacent odd port.
Shown above is RTP over UDP. The following for the use of RTP over TCP SETUP dialogue.
SETUP rtsp://10.34.3.80/D:/a.264/track1 RTSP/1.0   //Track1 said to set the channel 1.

CSeq: 4

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)  

Transport: RTP/AVP/TCP;unicast;interleaved= 0-1

RTSP/1.0 200 OK

CSeq: 4

Date: Tue, Jul 22 2014 02:41:25 GMT

Transport:

 RTP/AVP/TCP;interleaved=0-1

Session: 54DAFD56;timeout=65

You can see the Transport SETUP command for the RTP/AVP/TCP field, and many a interleaved=0-1 field. Because the RTP over TCP RTP and RTCP packets are sent to the same TCP port, so use the interleaved value to distinguish whether the RTP or the RTCP package. Interleaved=0 said the RTP packet, RTCP packet interleaved=1.
(4)PLAY
The PLAY method notifies the server according to the mechanism of SETUP specified in the start data transfer. The server will PLAY message from the specified start time range to transmit data, until the end of. The server may be PLAY requests in the queue, after an PLAY request needs to wait before an PLAY request is completed can be implemented.
Range specifies the playback start time. If you receive a message in the specified time, so play immediately began.
Excluding the first Range PLAY request is legitimate, the media began to flow from the position in the world, until the media stream is suspended. If the media flow through PAUSE pause, media contribute at the point of suspension to transmission. If the media stream is playing, so the PLAY request will not work. The client can use this to test whether the server survival.
PLAY rtsp://10.34.3.80/D:/a.264/ RTSP/1.0

CSeq: 5

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Session: 54DAFD56                 //SessionID, Returns the SETUP response

Range: npt=0.000-   /                /The specified start playing time

RTSP/1.0 200 OK

CSeq: 5

Date: Tue, Jul 22 2014 02:41:25 GMT

Range: npt=0.000- 

Session: 54DAFD56

RTP-Info: url=rtsp://10.34.3.80/D:/a.264/track1;seq=10244;rtptime=2423329550  //RTP information


The Url field is a streaming link address corresponds to the RTP parameter, the SEQ field of streaming media first packet sequence number, rtptime for the range domain corresponding to the RTP timestamp
(5)PAUSE
PAUSE message server paused transmission stream transmission. If the request URL specific media stream, then only the media player is suspended. You can specify only pause audio, then play will mute. If the request URL specifies a set of flow, then the transmission of all streams in the group will be suspended. The server may not support PAUSE message. For example, the real-time stream may not support pause. When a server does not support a message, will respond to the client"501 Not Implemented".
PAUSE request may contain a Range head, is used to specify the media stream pause time point, called the point of suspension. The head of the Range must contain a precise value, instead of a time range. If the Range header specifies a time beyond the scope of the PLAY request, the server will return"457 Invalid Range" . If Range is missing, then immediately suspend suspended in received news media stream transmission, and will pause point set to the current playback time.
(6) TEARDOWN
TEARDOWN for the termination of a given URL media streaming, and release the related resources and the media stream.
Three, RTP/RTCP protocol
RTP is the real time transport protocol (Real-Time Transport Protocol) abbreviation. The real time transport protocol for multimedia data flow. Usually based on UDP, can also be based on TCP. Some people will be classified as application layer protocol, also some people will return to its transport layer protocol, which can be. The Rtp protocol provides a timestamp and sequence number. Timestamp sender is arranged in sampling, after the receiver, in accordance with the time stamp are playing. RTP itself only to ensure the transmission of real-time data, and not for in order delivery of data packets for reliable transport mechanism, also do not provide flow and congestion control, it relies on RTCP to provide these services.
The version number (V): 0-1 2b is used to identify the version of RTP used in.
Fill bits (P): 2 1b if the bit is set to 1, the tail of the RTP package with padding bytes added.
Extended (X):3 1b if the bit is set to 1, the tail of the RTP packets with additional extension header.
CSRC counter (CC): the number of CSRC 4-7 4B fixed head following after.
The marked position (M): 8 1b interpretation of the bit by the configuration document.
Load type (PT): type 9-15 7b identifies the RTP load.
Serial number (SN): 16- 31 16b sender sending each a RTP package will be the domain value plus 1, the receiver can be detected by the sequence number to determine whether the RTP packet loss. Note: the initial sequence number value is random.
Time stamp: sampling time of the first byte of the packet in 32 32b. The time stamp is an initial value, and increased with the passage of time. Even if no packets are sent, the time stamp will not increase. The time stamp is removing jitter and synchronize the essential.
SSRC: synchronization source identifier: 32b RTP package source, cannot have the same two SSRC value in the same session of RTP. This field is based on the algorithm of randomly generated certain.
CSRC List: contribution to the source list 0-15, each 32B to all RTP package source new packet identifier for a RTP mixer's contribution.
The RTCP protocol
RTCP is the real time control protocol (Real-Time Control Protocol) abbreviation. RTCP is usually used in conjunction with the RTP, is used to manage the transmission quality in the current process between the exchange of information. During the RTP session, the participants periodically transmitting RTCP packet, RTCP packet contains the number of sent packets, the number of lost packets and other statistical data. The server can use to change the transmission rate of the dynamic information, or even change the payload type. With the use of RTP and RTCP, can effectively and with minimal cost to achieve the best transmission efficiency, very suitable for the transmission of real time flow.
RTSP usually uses RTP protocol to transport real-time streaming, RTP general use of even and odd port, port RTCP using adjacent, namely the RTP port number +1.
In the RTCP communication control, RTCP protocol function is realized by different types of RTCP packages. RTCP is also based on the UDP packet transmission, there are five main types of packets:
1.SR: The sender report, issued by the application sends a RTP datagram or end.
2.RR: The receiving end report, but the application is not accepted by sending a RTP datagram or from the end.
3.SDES: source description, the carrier identification information associated with the session members, such as user name, e-mail, phone etc.
4.BYE: notify other members left, back in the notice will exit the session.
5.APP: defined by the application itself, as an extension to the RTCP protocol.
Version (V) with the RTP Baotou: Department of
Fill (P) with the RTP Baotou: Department of.
The receiving report counter (RC): number of the receiving report of block 5B in the SR package.
Packet type (PT): 8bit SR packet type 200
Length (length) of:SR package to 32bit for 1 units of length minus 1
Synchrotron source (SSRC) synchronization source identifier:SR packet transmission. As with the corresponding RTP package SSRC.
NTP timestamp (Network Time Protocol): SR absolute time packets when. Used to synchronize different flow.
RTP timestamp: corresponding to the NTP timestamp, with the same initial value and the timestamp in the RTP package.
Send's Packet count: From the beginning of the total number of bytes of data to produce effective this time the SR package in the sender transmits data, excluding the head and filling, the sender SSRC, the domain to be cleared.
The SSRC identifier synchronization source n: contained in the report is the statistical information packets received from the source.
Loss rate: the last show from SR or RR packets sent according to the loss rate from the source n sends a RTP packet.
The cumulative loss of data: accept the total number of SSRC_n packets to send SR the time SSRC_n transmission loss of RTP from the beginning.
Extended maximum sequence number received from the maximum sequence number: data from the RTP package SSRC_n received.
Receiving jitter (Interarrival jitter):RTP packet reception time variance estimation.
The last time SR time stamp (Last SR): the latest from NTP timestamp SSRC_n received SR packets in the intermediate 32bit. If you have not received SR packet, is 0.
The last time dependent SR delay (Delay since Last SR): from the last SSRC_n received SR packet to the packet transmission delay.
Audio and video synchronization
Transmission of audio and video stream in two different RTP session, each RTP packet has its own time stamp, while the RTCP package in the NPT field (Network Protocol Time) absolute time saved can be used to set the audio and video are mapped to the same time axis, so as to realize the synchronization of audio and video.
The position of each protocol in TCP/IP
This article will introduce the LIVE555 Foundation.

Thursday 19 November 2015

setuid() system call

Have you thought what if your application which is running in you want to make system call which need to run as root user then how to make it work ???

May that why you are here !!!!

   #include <stdio.h>
   #include <stdlib.h>
   #include <sys/types.h>
   #include <unistd.h>

   int main()
   {
   setuid(0);
   system("kill 1090");
   return 0;
   }

$ gcc program.c -o program
$ sudo chown root.root program
$ sudo chmod 4755 program
$ ./program

The setuidsetgid, and sticky Permissions

Contributed by Tom Rhodes.
Other than the permissions already discussed, there are three other specific settings that all administrators should know about. They are the setuidsetgid, andsticky permissions.
These settings are important for some UNIX® operations as they provide functionality not normally granted to normal users. To understand them, the difference between the real user ID and effective user ID must be noted.
The real user ID is the UID who owns or starts the process. The effective UID is the user ID the process runs as. As an example, passwd(1) runs with the real user ID when a user changes their password. However, in order to update the password database, the command runs as the effective ID of the root user. This allows users to change their passwords without seeing a Permission Denied error.
The setuid permission may be set by prefixing a permission set with the number four (4) as shown in the following example:
# chmod 4755 suidexample.sh
ref:https://www.freebsd.org/doc/handbook/permissions.html