How to play RTSP Streaming Media on ophone Platform

Source: Internet
Author: User

How to play RTSP Streaming Media on ophone Platform
RTSP (Real Time Streaming Protocol) is an application layer protocol in the TCP/IP protocol system. This Protocol defines how one-to-multiple applications can effectively transmit multimedia data over an IP network.
RTSP can be well supported by mainstream players. With the development of smart mobile phones, more and more mobile phones are beginning to support the RTSP protocol. This article mainly discusses two methods of RTSP playback on ophone.

Method 1: Call the player of the system for RTSP playback
This class is mainly used for videoview. The videoview class can load images from different data sources, such as resource files and network addresses. By calculating the size of the videoview window, you can conveniently scale and rotate the video.
The following describes how to implement playback.
(1) modify the maim. xml file and add the videoview control.

<Videoview <br/> Android: Id = "@ + ID/videoviewdisplay" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <br/> </videoview> 

    (2) modify the source file and add the playback code.

    Public void playrtsp () <br/>{< br/> string Path = "rtsp: // 210.21.229.142: 1113/stream2"; <br/> videoview mvideoview = (videoview) findviewbyid (R. id. videoviewdisplay); <br/> mvideoview. setvideopath (PATH); <br/> mvideoview. requestfocus (); <br/> mvideoview. start (); <br/>} 

    You can call the playrtsp function to play RTSP Streaming Media. After testing, multiple RTSP streams can be played. You only need to add multiple videoview controls to the main. xml file. Another key point is that the RTSP stream cannot be played on the simulator and needs to be tested on the real machine.
     
    Method 2: use the code to implement the RTSP protocol and complete video data decoding and display by yourself

    The transmission process of the RTSP protocol can be understood as the negotiation process between the client and the server. Therefore, the RTSP messages can be divided into request messages and response messages.
    A simple negotiation process is described below:
    (1) the client sends the option command to the server and asks which commands are supported by the server.

    String strmessage = string. format ("Options % s RTSP/1.0/R/ncseq: % d/R/nuser-AGENT: % S/R/n/R/N", m_strrtspaddress, iseqcount ++, "RTSP test player "); 

    (2) The server returns response information that includes support commands.

    RTSP/1.0 200 OK <br/> CSeq: 0 <br/> date: Thu, Sep 16 2010 15:34:56 GMT <br/> Public: Options, describe, setup, teardown, play, pause, get_parameter, set_parameter 

    (3) the client sends the describe command to the server to obtain the Session Description SDP.

    String strmessage = string. format ("describe % s RTSP/1.0/R/ncseq: % d/R/naccept: Application/SDP/R/nuser-AGENT: % S/R/n/R/N ", m_strrtspaddress, iseqcount ++," RTSP test player "); 

    (4) The server returns response information including SDP Information

    RTSP/1.0 200 OK <br/> CSeq: 1 <br/> date: Thu, Sep 16 2010 15:34:56 GMT <br/> content-base: rtsp: // 192.168.3.145: 1113/stream2/<br/> Content-Type: Application/SDP <br/> Content-Length: 513 </P> <p> V = 0 <br/> O =-1284650808045835 1 in ip4 192.168.3.145 <br/> S = session streamed by RTSP <br/> I = stream2 <br/> T = 0 0 <br/> A = tool: live555 streaming media v2009.04.20 <br/> A = type: Broadcast <br/> A = range: Treaty = 0-<br/> A = x-QT-text-nam: session streamed by RTSP <br/> A = x-QT-text-inf: stream2 <br/> M = video 0 RTP/AVP 96 <br/> C = in ip4 0.0.0.0 <br/> A = rtpmap: 96 h264/8000 <br/> A = fmtp: 96 packetization-mode = 1; Profile-level-id = 42001e; sprop-parameter-sets = z0iahukcg/I =, am44ga = <br/> A = control: track1 <br/> M = audio 0 RTP/AVP 97 <br/> C = in ip4 0.0.0.0 <br/> A = rtpmap: 97 l8/8000 <br/> A = control: track2 

    (5) the client sends the setup command to the server to determine the data type and transmission mode of transmission.

    String strmessage = string. format ("setup % S/track1 RTSP/1.0/R/ntransport: RTP/AVP/tcp; unicast; interleaved = 0-1/R/ncseq: % d/R/nuser-AGENT: % S/R/n/R/N ", m_strrtspaddress, iseqcount ++," RTSP test player "); 

    (6) The server responds to the setup information.

    RTSP/1.0 200 OK <br/> CSeq: 2 <br/> date: Thu, Sep 16 2010 15:34:56 GMT <br/> transport: RTP/AVP/tcp; unicast; destination = 192.168.3.141; Source = 192.168.3.145; interleaved = 0-1 <br/> session: 4 

    (7) the client sends a play command to the server to request data transmission.

    String strmessage = string. format ("play % S/track1 RTSP/1.0/R/nsession: % S/R/ncseq: % d/R/nuser-AGENT: % S/R/n/R/N ", m_strrtspaddress, strsession, iseqcount ++," RTSP test player "); 

    (8) The server responds to the play message.

    RTSP/1.0 200 OK <br/> CSeq: 3 <br/> date: Thu, Sep 16 2010 15:34:57 GMT <br/> session: 4 <br/> RTP-Info: url = rtsp: // 192.168.3.145: 1113/stream2/track1/track1; seq = 28261; rtptime = 3184617004

    The above is probably a negotiation process for establishing an RTSP connection. It is not difficult to see that the command format of the RTSP protocol is somewhat similar to that of HTTP. After the above negotiation process is completed, the following is a process of receiving and parsing RTP packet data. Here we will not detail the specific parsing process. Readers can refer to the rfc3984 documentation.
    For video decoding and display, refer to my other article "video monitoring on ophone".
    Shows the final implementation effect of the software:

    Summary:

    Both of the above methods can enable RTSP stream playing on ophone, but the effort is completely different. The first method is simple, and the system player is called. The software runs very efficiently. However, if the RTSP service on the server side is not standard, negotiation may fail. The second method is to reproduce the entire process with code. You need to complete the control of the interface from protocol decoding, video decoding and display. However, if we can completely solve these problems, we believe that readers will have a better understanding of the ophone platform.

     

    From ophone SDN

     

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.