Jrtp Study Notes

Source: Internet
Author: User
Tags rfc

Rtpsession
For most RTP applications, the rtpsession class may be the only class used by jrtplib. It can fully process RTCP data packets, so users can focus on real data transmission and receiving.
It is important to know that the rtpsession class is not safe under multiple threads. Therefore, you must use some lock synchronization mechanisms to ensure that the same rtpsession instance is not called in different threads.
The rtpsession class has the following interfaces.

• Rtpsession (rtptransmitter: transmissionprotocol proto = rtptransmitter: ipv4udpproto)
Use the proto transport layer to create a prtsession instance. If proto uses the User-Defined transport layer, the corresponding newuserdefinedtransmitter () function must be implemented. PS: The default value is enough. The default value is IPv4 network.

• Int create (const rtpsessionparams & sessparams, const rtptransmissionparams * transparams = 0)
Use the rtpsession parameters sessparams and rtptransmission parameters transparams to create a RTP session. If transparams is null, the default parameter is used. PS: rtpsessionparams we may need to set more. The rtptransmissionparams parameter only needs to be set as long as the port in the parameter is set. The port must be set to a pair. Otherwise, during multicast, this process will not receive data. For the setting method, see example. cpp.

• Void destroy ()
Leave a session but do not send bye packets to other group members. PS: I do not recommend using this function unless it is an error. We should use byedestroy () to exit normally ().

• Void byedestroy (const rtptime & maxwaittime, const void * Reason, size T reasonlength)
Send a bye packet and leave the session. Wait for maxwaittime before sending the bye packet. If it times out, it will not send the bye packet to exit directly. The bye packet will contain your reason for leaving reason. The corresponding reasonlength indicates the reason length. PS: Because the bye package is an RTCP package, RTCP is not sent as soon as it is sent. Its sending time is calculated to balance the bandwidth, it is very likely that the maxwaittime is exceeded by the sending time, and the author may think it is meaningless to keep this session for so long. Of course, I often set maxwaittime to a large value.

• Bool isactive ()
Check whether the rtpsession instance has established a real session through create.

• Uint32 t getlocalssrc ()
Returns our SSRC. PS: For what is SSRC, check out rfc3550. I have said that jrtplib is only a packaging of the RTP protocol and does not do any application.

• Int adddestination (const rtpaddress & ADDR)
Add a sending target. PS: of course, if we use multicast, we only use one call here to write our multicast address. In this way, all the people in this group can receive your package. However, it is annoying to configure multicast over the Internet. It is also annoying to use multicast tests (Multicast must bind a port. If you want to run two software instances on the same machine, you will find the same port bind twice. Of course, the next one will fail, that is, the test will fail? Find two machines or use virtual machines). If the multicast fails, we need to change the multicast to unicast, in this case, we need to use this function to add the IP addresses of other group members. For more information, see example3.cpp.

• Int deletedestination (const rtpaddress & ADDR)
Delete an address from the Sending address list.

• Void cleardestinations ()
Clear the list of Sending addresses.

• Bool supportsmulticasting ()
Returns whether jrtplib supports multicast. PS: jrtplib itself is not your real network. It may be specified when compiling the jrtplib library.
.
• Int joinmulticastgroup (const rtpaddress & ADDR)
Add a multicast group ADDR.

• Int leavemulticastgroup (const rtpaddress & ADDR)
Leave a multicast group ADDR.

• Void leaveallmulticastgroups ()
Leave all multicast groups. PS: We can join multiple multicast groups at the same time ..

• Int sendpacket (const void * data, size T Len)
• Int sendpacket (const void * data, size T Len, uint8 t Pt, bool mark, uint32 t timestampinc)
• Int sendpacketex (const void * data, size T Len, uint16 t hdrextid, const void * hdrextdata, size T numhdrextwords)
• Int sendpacketex (const void * data, size T Len, uint8 t Pt, boolmark, uint32 t timestampinc, uint16 t hdrextid, const void * hdrextdata, size T numhdrextwords)
The above four functions send data packets. I think if you do not read the RTP protocol, you will also be dizzy when I say it. If you read the RTP protocol, and then read the rtpsession. h note, you will understand.

• Int setdefapaypayloadtype (uint8 t Pt)
Set the default RTP payloadtype to PT. PS: matches the first and third sending functions above. As for what number should be set up, if you read the messy articles on Baidu, of course, it is possible to make a mess. In fact, it should be set based on rfc3551 and the media type you want to transmit.

• Int setdefamark mark (bool m)
This sets the mark of the RTP data packet. PS: Why is the value good? Well, you cannot even determine rfc3550. Depending on the specific RTP payload specifications, the MPEG and h263 are different.
MPEG2 www.ietf.org/rfc/rfc2250.txt

MPEG4 www.rfc-editor.org/rfc/rfc3016.txt

H263 www.ietf.org/rfc/rfc2190.txt

• Int setdefatimetimestampincrement (uint32 t timestampinc)
Set the increment of the default timestamp. PS: it is also compatible with the First and Third functions. Each time a RTP packet is sent, timestamp is automatically added.

• Int incrementtimestamp (uint32 t Inc)
This function is used to manually add timestamp. Sometimes I use this very well. For example, a RTP packet does not send because it only contains mute data, this is because we should manually add timestamp so that the timestamp of the next RTP packet is correct.

• Int incrementtimestampdefault ()
This function is used to add the value set by setdefaulttimestampincrement. Sometimes this is useful. For example, an RTP packet does not send because it only contains mute data. In this case, this function is called to set timestamp so that the timestamp of the next RTP package is correct.

• Int setpretransmissiondelay (const rtptime & delay)
This function allows you to inform the Library about the delay
Sampling the first sample of a packet and sending the packet. This delay is
Taken into account when calculating the relation between RTP Timestamp
And Wallclock time, used for inter-media synchronization.

• Rtptransmissioninfo * gettransmissioninfo ()
This function returns an instance of a subclass of rtptransmissioninfo
Which will give some additional information about the transmitter (a list
Of local IP addresses for example). The user has to delete the returned
Instance when it is no longer needed.

• Int poll ()
If you're not using the poll thread, this function must be called regularly
To process incoming data and to send RTCP data when necessary.
61

• Int waitforincomingdata (const rtptime & delay, bool * dataavailable = 0)
Waits at most a time delay until incoming data has been detected. Only
Works when you're not using the poll thread. If dataavailable is not null,
It shoshould be set to true if data was actually read and to false otherwise.

• Int abortwait ()
If the previous function has been called, this one aborts the waiting. Only
Works when you're not using the poll thread.

• Rtptime getrtcpdelay ()
Returns the time interval after which an RTCP compound packet may have
To be sent. only works when you're not using the poll thread.

• Int begindataaccess ()
The following functions (until enddataaccess) must be called between begindataaccess and enddataaccess. begindataaccess ensures that the polling (poll) thread does not access source table during this period. After the enddataaccess call is complete, the polling (poll) thread will get the lock and continue the access. PS: First, each source in your source table represents each independent media stream of each participant participating in the meeting. We will use them below, but at the same time, the poll thread will also poll them to correctly process content related to RTCP.

• Bool gotofirstsource ()
Start recursion of the first stream of the participant. If the first stream is found, the tree is returned. Otherwise, false is returned. PS: we use this function and the following gotonextsource to traverse every source in the source table.

• Bool gotonextsource ()
Set the current source to the next source in the source table. If the end is reached, false is returned.

• Bool gotopreviussource ()
Set the current source to the source table. If the header is reached, false is returned.

• Bool gotofirstsourcewithdata ()
Start recursion of the first stream with RTP data in the participant. If the stream is found, the tree is returned; otherwise, false is returned. PS: we often use this set of functions to receive data, because it is useless if there is no data.

• Bool gotonextsourcewithdata ()
Set the current source to the next Source with RTP data in the source table. If the end is reached, false is returned.

• Bool gotopreviussourcewithdata ()
Set the current source to the previous source with RTP data in the source table. If the header is reached, false is returned.

• Rtpsourcedata * getcurrentsourceinfo ()
Returns the real rtpsourcedata column of the current source of the current participant. PS: The returned rtpsourcedata is the information collected from the RTCP data packets of its participants in the current process. It is useful for us, but the author's routine is useless, the domestic network is not mentioned either. In rfc3550, everything about RTCP is here. Anyone who has read rfc3550 knows that the most talked about it is RTCP. We will talk about this class later.


• Rtpsourcedata * getsourceinfo (uint32 t SSRC)
The rtpsourcedata specified by SSRC is returned, or both are null (when this entry does not exist ). PS: this function is also useful. Because getcurrentsourceinfo can only be used in context such as gotofirstsource. If we are a member function in the rtpsource subclass, we can only use this function without this context.

• Rtppacket * getnextpacket ()
Obtain the next RTP packet of the current media stream of the current participant.

• Int enddataaccess ()
See begindataaccess

• Int setreceivemode (rtptransmitter: receivemode m)
Sets the receive mode to m, which can be one of the following:
-Rtptransmitter: acceptall
All incoming data is accepted, no matter where it originated from.
-Rtptransmitter: acceptsome
Only data coming from specific sources will be accepted.
-Rtptransmitter: ignoresome
All incoming data is accepted, except T for data coming from a specificset of sources.
Note that when the receive mode is changed, the list of addressed to be ignored or accepted will be cleared.

• Int addtoignorelist (const rtpaddress & ADDR)
Adds ADDR to the list of addresses to ignore.

• Int deletefromignorelist (const rtpaddress & ADDR)
Deletes ADDR from the list of addresses to ignore.

• Void clearignorelist ()
Clears the list of addresses to ignore.

• Int addtoacceptlist (const rtpaddress & ADDR)
Adds ADDR to the list of addresses to accept.

• Int deletefromacceptlist (const rtpaddress & ADDR)
Deletes ADDR from the list of addresses to accept.

• Void clearacceptlist ()
Clears the list of addresses to accept.

• Int setmaximumpacketsize (size t s)
Sets the maximum allowed packet size to S.

• Int setsessionbandwidth (double BW)
Sets the session bandwidth to BW, which is specified in bytes per second.

• Int settimestampunit (double U)
Sets our own timestamp unit to u. The timestamp unit is defined as a time
Interval divided by the number of samples in that interval: for 8000Hz
Audio this wocould be 1.0/8000.0.

• Void setnameinterval (INT count)
After processing sourcese in the source table, RTCP packet Builder (we don't need to worry about this internal stuff) checks whether other (non-cname) sdes projects are to be sent. If count is zero or negative, it is not sent. If count is positive, sdes name item will be added to the current RTCP package after sources table processes count times. PS: Actually, each time sources is processed
Table will be accompanied by sdes RTCP packet transmission. In this packet, cname is required, but other projects are not required. This function determines the frequency of name Project sending, if the value is 1, no sdes RTCP packet is carried in the table. If the value is 2, the name Project is sent every two sdes packets, the following are the same principles: setemailinterval, setlocationinterval, setphoneinterval, settoolinterval, and setnoteinterval. For the description of this item, see rfc3550. in earlier versions, jrtplib does not use this function, but uses functions such as enablesendname.

• Void setemailinterval (INT count)
After all possible sources in the source table have been processed, the RTCP
Packet builder will check if other (non-cname) sdes items need to be
Sent. If count is zero or negative, nothing will happen. If count is positive,
An sdes e-mail item will be added after the sources in the source table
Have been processed count times.

• Void setlocationinterval (INT count)
After all possible sources in the source table have been processed, the RTCP
Packet builder will check if other (non-cname) sdes items need to be
Sent. If count is zero or negative, nothing will happen. If count is positive,
An sdes location item will be added after the sources in the source table
Have been processed count times.

• Void setphoneinterval (INT count)
After all possible sources in the source table have been processed, the RTCP
Packet builder will check if other (non-cname) sdes items need to be
Sent. If count is zero or negative, nothing will happen. If count is positive,
An sdes phone item will be added after the sources in the source table
Have been processed count times.

• Void settoolinterval (INT count)
After all possible sources in the source table have been processed, the RTCP
Packet builder will check if other (non-cname) sdes items need to be
Sent. If count is zero or negative, nothing will happen. If count is positive,
An sdes tool item will be added after the sources in the source table have
Been processed count times.

• Void setnoteinterval (INT count)
After all possible sources in the source table have been processed, the RTCP
Packet builder will check if other (non-cname) sdes items need to be
Sent. If count is zero or negative, nothing will happen. If count is positive,
An sdes note item will be added after the sources in the source table have
Been processed count times.

• Int setlocalname (const void * s, size T Len)
Set the name sdes project and view your name by other persons at the meeting. The same below.

• Int setlocalemail (const void * s, size T Len)
Sets the sdes e-mail item for the local particle ant to the value s
Length Len.

• Int setlocallocation (const void * s, size T Len)
Sets the sdes location item for the local particle ant to the value s
Length Len.

• Int setlocalphone (const void * s, size T Len)
Sets the sdes phone item for the local particle ant to the value s
Length Len.

• Int setlocaltool (const void * s, size T Len)
Sets the sdes tool item for the local particle ant to the value s with length
Len.

• Int setlocalnote (const void * s, size T Len)
Sets the sdes note item for the local particle ant to the value s with length
Len.
In case you specified in the constructor that you want to use your own transmission
Component, you shoshould override the following function:
• Rtptransmitter * newuserdefinedtransmitter ()
The rtptransmitter instance returned by this function will then be used to send
And receive RTP and RTCP packets. Note that when the session is destroyed,
This rtptransmitter instance will be destroyed with a delete call.
By inheriting your own class from rtpsession and overriding one or more of
Functions below, certain events can be detected:

• Void onrtppacket (rtppacket * pack, const rtptime & receivetime, const rtpaddress * senderaddress)
If an rtppacket packet comes, this function is called for processing. PS: this function is likely to be reloaded when we inherit the rtpsession class. This is another method to obtain RTP data packets except the method mentioned above. This method is more suitable for asynchronous scenarios. By default, this is an empty function. In addition to this function, the following functions are often reloaded.

• Void onrtcpcompoundpacket (rtcpcompoundpacket * pack, const rtptime & receivetime, const rtpaddress * senderaddress)
Is called when an incoming RTCP packet is about to be processed.

• Void onssrccollision (rtpsourcedata * srcdat, const rtpaddress * senderaddress, bool isrtp)
Is called when an SSRC collision was detected. The instance srcdat is
One present in the table, the address senderaddress is the one that collided
With one of the addresses and isrtp indicates against which address
Of srcdat the check failed.

• Void oncnamecollision (rtpsourcedata * srcdat, const rtpaddress * senderaddress, const uint8 T * cname, size T cnamelength)
Is called when another cname was received than the one already present for source srcdat.

• Void onnewsource (rtpsourcedata * srcdat)
This function is called when a new entry is added to the source table. PS: this is also an important function, because it means there is a possibility that a new participant will join. However, I am very upset that the cname and name fields in rtpsourcedata are still invalid at this time, which is not the responsibility of RTCP, because all the information in this sdes RTCP packet is confirmed by packet capture ). After our function is called, it will take a while to get the cname and name of the source.
And other related information. Of course, if you don't want the software to die, You can't delay it in a blocking way in this function body.

• Void onremovesource (rtpsourcedata * srcdat)
This function is called when an entry is removed from the source table. PS: This usually means that one attendee leaves, which is different from onnewsource. The cname and name are valid at this time. When using this function, you should note that our "meaning two words" because "joining" may not be a new attendee, but a new media stream of an existing attendee. The "exit" function may not be one attendee, but only one of the media streams of one attendee. These two functions can only provide one trigger condition for our updated attendee. When onnewsource is called, we need to check whether the cname is in our attendee list. If not, it is a new attendee. At the same time, if onremovesource is called, we should check whether there are other sources for this cname participant. If there is no other source, This attendee will actually leave. So troublesome ?? That's right. That's what we need to do with h323 and SIP-session management.

• Void ontimeout (rtpsourcedata * srcdat)
Is called when particle ant srcdat is timed out.

• Void onbyetimeout (rtpsourcedata * srcdat)
Is called when particle ant srcdat is timed after having sent a bye packet.

• Void onbyepacket (rtpsourcedata * srcdat)
Is called when a bye packet has been processed for source srcdat.

• Void onapppacket (rtcpapppacket * apppacket, const rtptime & receivetime,
Const rtpaddress * senderaddress)
In called when an RTCP app packet apppacket has been received at time
Receivetime FROM address senderaddress.

• Void onunknownpackettype (rtcppacket * rtcppack, const rtptime & receivetime,
Const rtpaddress * senderaddress)
Is called when an unknown RTCP packet type was detected.

• Void onunknownpacketformat (rtcppacket * rtcppack, const rtptime & receivetime,
Const rtpaddress * senderaddress)
Is called when an unknown packet format for a known packet type was
Detected.

• Void onnotetimeout (rtpsourcedata * srcdat)
Is called when the sdes note item for source srcdat has been timed out.

• Void onsendrtcpcompoundpacket (rtcpcompoundpacket * pack)
Is called when an RTCP compound packet has just been sent. Useful
Inspect outgoing RTCP data.

• Void onpollthreaderror (INT errcode)
Is called when error errcode was detected in the poll thread.

• Void onpollthreadstep ()
Is called each time the poll thread loops. This happens when incoming data
Was detected or when its time to send an RTCP compound packet.

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.