gst_plugins_base/gst-libs/gst/rtp/gstrtcpbuffer.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
    34  * of 'application/x-rtcp' #GstCaps.
    34  * of 'application/x-rtcp' #GstCaps.
    35  * </para>
    35  * </para>
    36  * <para>
    36  * <para>
    37  * An RTCP buffer consists of 1 or more #GstRTCPPacket structures that you can
    37  * An RTCP buffer consists of 1 or more #GstRTCPPacket structures that you can
    38  * retrieve with gst_rtcp_buffer_get_first_packet(). #GstRTCPPacket acts as a pointer
    38  * retrieve with gst_rtcp_buffer_get_first_packet(). #GstRTCPPacket acts as a pointer
    39  * into the RTCP buffer;
    39  * into the RTCP buffer; you can move to the next packet with
    40 #ifdef __SYMBIAN32__
       
    41 EXPORT_C
       
    42 #endif
       
    43  you can move to the next packet with
       
    44  * gst_rtcp_packet_move_to_next().
    40  * gst_rtcp_packet_move_to_next().
    45  * </para>
    41  * </para>
    46  * </refsect2>
    42  * </refsect2>
    47  *
    43  *
       
    44  * Since: 0.10.13
       
    45  *
    48  * Last reviewed on 2007-03-26 (0.10.13)
    46  * Last reviewed on 2007-03-26 (0.10.13)
    49  *
       
    50  * Since: 0.10.13
       
    51  */
    47  */
    52 
    48 
    53 #include <string.h>
    49 #include <string.h>
    54 
    50 
    55 #include "gstrtcpbuffer.h"
    51 #include "gstrtcpbuffer.h"
   407  * Returns: TRUE if @packet is pointing to a valid packet after calling this
   403  * Returns: TRUE if @packet is pointing to a valid packet after calling this
   408  * function.
   404  * function.
   409  */
   405  */
   410 #ifdef __SYMBIAN32__
   406 #ifdef __SYMBIAN32__
   411 EXPORT_C
   407 EXPORT_C
   412 #endif
   408 #endif 
   413 
       
   414 gboolean
   409 gboolean
   415 gst_rtcp_packet_move_to_next (GstRTCPPacket * packet)
   410 gst_rtcp_packet_move_to_next (GstRTCPPacket * packet)
   416 {
   411 {
   417   g_return_val_if_fail (packet != NULL, FALSE);
   412   g_return_val_if_fail (packet != NULL, FALSE);
   418   g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID, FALSE);
   413   g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID, FALSE);
   491       len = 4;
   486       len = 4;
   492       break;
   487       break;
   493     case GST_RTCP_TYPE_APP:
   488     case GST_RTCP_TYPE_APP:
   494       len = 12;
   489       len = 12;
   495       break;
   490       break;
   496     case GST_RTCP_TYPE_RTPFB:
       
   497       len = 12;
       
   498       break;
       
   499     case GST_RTCP_TYPE_PSFB:
       
   500       len = 12;
       
   501     default:
   491     default:
   502       goto unknown_type;
   492       goto unknown_type;
   503   }
   493   }
   504   if (packet->offset + len >= size)
   494   if (packet->offset + len >= size)
   505     goto no_space;
   495     goto no_space;
   533 
   523 
   534 /**
   524 /**
   535  * gst_rtcp_packet_remove:
   525  * gst_rtcp_packet_remove:
   536  * @packet: a #GstRTCPPacket
   526  * @packet: a #GstRTCPPacket
   537  *
   527  *
   538  * Removes the packet pointed to by @packet and moves pointer to the next one
   528  * Removes the packet pointed to by @packet.
   539  *
   529  *
   540  * Returns: TRUE if @packet is pointing to a valid packet after calling this
   530  * Note: Not implemented.
   541  * function.
   531  */
       
   532 #ifdef __SYMBIAN32__
       
   533 EXPORT_C
       
   534 #endif
       
   535 
       
   536 void
       
   537 gst_rtcp_packet_remove (GstRTCPPacket * packet)
       
   538 {
       
   539   g_return_if_fail (packet != NULL);
       
   540   g_return_if_fail (packet->type != GST_RTCP_TYPE_INVALID);
       
   541 
       
   542   g_warning ("not implemented");
       
   543 }
       
   544 
       
   545 /**
       
   546  * gst_rtcp_packet_get_padding:
       
   547  * @packet: a valid #GstRTCPPacket
       
   548  *
       
   549  * Get the packet padding of the packet pointed to by @packet.
       
   550  *
       
   551  * Returns: If the packet has the padding bit set.
   542  */
   552  */
   543 #ifdef __SYMBIAN32__
   553 #ifdef __SYMBIAN32__
   544 EXPORT_C
   554 EXPORT_C
   545 #endif
   555 #endif
   546 
   556 
   547 gboolean
   557 gboolean
   548 gst_rtcp_packet_remove (GstRTCPPacket * packet)
   558 gst_rtcp_packet_get_padding (GstRTCPPacket * packet)
   549 {
   559 {
   550   gboolean ret = FALSE;
       
   551   guint offset = 0;
       
   552 
       
   553   g_return_val_if_fail (packet != NULL, FALSE);
   560   g_return_val_if_fail (packet != NULL, FALSE);
   554   g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID, FALSE);
   561   g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID, FALSE);
   555 
   562 
   556   /* The next packet starts at offset + length + 4 (the header) */
       
   557   offset = packet->offset + (packet->length << 2) + 4;
       
   558 
       
   559   /* Overwrite this packet with the rest of the data */
       
   560   memmove (GST_BUFFER_DATA (packet->buffer) + packet->offset,
       
   561       GST_BUFFER_DATA (packet->buffer) + offset,
       
   562       GST_BUFFER_SIZE (packet->buffer) - offset);
       
   563 
       
   564   /* try to read next header */
       
   565   ret = read_packet_header (packet);
       
   566   if (!ret)
       
   567     packet->type = GST_RTCP_TYPE_INVALID;
       
   568 
       
   569   return ret;
       
   570 }
       
   571 
       
   572 /**
       
   573  * gst_rtcp_packet_get_padding:
       
   574  * @packet: a valid #GstRTCPPacket
       
   575  *
       
   576  * Get the packet padding of the packet pointed to by @packet.
       
   577  *
       
   578  * Returns: If the packet has the padding bit set.
       
   579  */
       
   580 #ifdef __SYMBIAN32__
       
   581 EXPORT_C
       
   582 #endif
       
   583 
       
   584 gboolean
       
   585 gst_rtcp_packet_get_padding (GstRTCPPacket * packet)
       
   586 {
       
   587   g_return_val_if_fail (packet != NULL, FALSE);
       
   588   g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID, FALSE);
       
   589 
       
   590   return packet->padding;
   563   return packet->padding;
   591 }
   564 }
   592 
   565 
   593 /**
   566 /**
   594  * gst_rtcp_packet_get_type:
   567  * gst_rtcp_packet_get_type:
   595  * @packet: a valid #GstRTCPPacket
   568  * @packet: a valid #GstRTCPPacket
   596  *
   569  *
   597  * Get the packet type of the packet pointed to by @packet.
   570  * Get the packet type of the packet pointed to by @packet.
   598  *
   571  *
   599  * Returns: The packet type or GST_RTCP_TYPE_INVALID when @packet is not
   572  * Returns: The packet type.
   600  * pointing to a valid packet.
       
   601  */
   573  */
   602 #ifdef __SYMBIAN32__
   574 #ifdef __SYMBIAN32__
   603 EXPORT_C
   575 EXPORT_C
   604 #endif
   576 #endif
   605 
   577 
   606 GstRTCPType
   578 GstRTCPType
   607 gst_rtcp_packet_get_type (GstRTCPPacket * packet)
   579 gst_rtcp_packet_get_type (GstRTCPPacket * packet)
   608 {
   580 {
   609   g_return_val_if_fail (packet != NULL, GST_RTCP_TYPE_INVALID);
   581   g_return_val_if_fail (packet != NULL, GST_RTCP_TYPE_INVALID);
       
   582   g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID,
       
   583       GST_RTCP_TYPE_INVALID);
   610 
   584 
   611   return packet->type;
   585   return packet->type;
   612 }
   586 }
   613 
   587 
   614 /**
   588 /**
  1803     return FALSE;
  1777     return FALSE;
  1804   }
  1778   }
  1805 }
  1779 }
  1806 
  1780 
  1807 /**
  1781 /**
  1808  * gst_rtcp_packet_fb_get_sender_ssrc:
       
  1809  * @packet: a valid RTPFB or PSFB #GstRTCPPacket
       
  1810  *
       
  1811  * Get the sender SSRC field of the RTPFB or PSFB @packet.
       
  1812  *
       
  1813  * Returns: the sender SSRC.
       
  1814  *
       
  1815  * Since: 0.10.23
       
  1816  */
       
  1817 #ifdef __SYMBIAN32__
       
  1818 EXPORT_C
       
  1819 #endif
       
  1820 
       
  1821 guint32
       
  1822 gst_rtcp_packet_fb_get_sender_ssrc (GstRTCPPacket * packet)
       
  1823 {
       
  1824   guint8 *data;
       
  1825   guint32 ssrc;
       
  1826 
       
  1827   g_return_val_if_fail (packet != NULL, 0);
       
  1828   g_return_val_if_fail ((packet->type == GST_RTCP_TYPE_RTPFB ||
       
  1829           packet->type == GST_RTCP_TYPE_PSFB), 0);
       
  1830   g_return_val_if_fail (GST_IS_BUFFER (packet->buffer), 0);
       
  1831 
       
  1832   data = GST_BUFFER_DATA (packet->buffer);
       
  1833 
       
  1834   /* skip header */
       
  1835   data += packet->offset + 4;
       
  1836   ssrc = GST_READ_UINT32_BE (data);
       
  1837 
       
  1838   return ssrc;
       
  1839 }
       
  1840 
       
  1841 /**
       
  1842  * gst_rtcp_packet_fb_set_sender_ssrc:
       
  1843  * @packet: a valid RTPFB or PSFB #GstRTCPPacket
       
  1844  * @ssrc: a sender SSRC
       
  1845  *
       
  1846  * Set the sender SSRC field of the RTPFB or PSFB @packet.
       
  1847  *
       
  1848  * Since: 0.10.23
       
  1849  */
       
  1850 #ifdef __SYMBIAN32__
       
  1851 EXPORT_C
       
  1852 #endif
       
  1853 
       
  1854 void
       
  1855 gst_rtcp_packet_fb_set_sender_ssrc (GstRTCPPacket * packet, guint32 ssrc)
       
  1856 {
       
  1857   guint8 *data;
       
  1858 
       
  1859   g_return_if_fail (packet != NULL);
       
  1860   g_return_if_fail (packet->type == GST_RTCP_TYPE_RTPFB ||
       
  1861       packet->type == GST_RTCP_TYPE_PSFB);
       
  1862   g_return_if_fail (GST_IS_BUFFER (packet->buffer));
       
  1863 
       
  1864   data = GST_BUFFER_DATA (packet->buffer);
       
  1865 
       
  1866   /* skip header */
       
  1867   data += packet->offset + 4;
       
  1868   GST_WRITE_UINT32_BE (data, ssrc);
       
  1869 }
       
  1870 
       
  1871 /**
       
  1872  * gst_rtcp_packet_fb_get_media_ssrc:
       
  1873  * @packet: a valid RTPFB or PSFB #GstRTCPPacket
       
  1874  *
       
  1875  * Get the media SSRC field of the RTPFB or PSFB @packet.
       
  1876  *
       
  1877  * Returns: the media SSRC.
       
  1878  *
       
  1879  * Since: 0.10.23
       
  1880  */
       
  1881 #ifdef __SYMBIAN32__
       
  1882 EXPORT_C
       
  1883 #endif
       
  1884 
       
  1885 guint32
       
  1886 gst_rtcp_packet_fb_get_media_ssrc (GstRTCPPacket * packet)
       
  1887 {
       
  1888   guint8 *data;
       
  1889   guint32 ssrc;
       
  1890 
       
  1891   g_return_val_if_fail (packet != NULL, 0);
       
  1892   g_return_val_if_fail ((packet->type == GST_RTCP_TYPE_RTPFB ||
       
  1893           packet->type == GST_RTCP_TYPE_PSFB), 0);
       
  1894   g_return_val_if_fail (GST_IS_BUFFER (packet->buffer), 0);
       
  1895 
       
  1896   data = GST_BUFFER_DATA (packet->buffer);
       
  1897 
       
  1898   /* skip header and sender ssrc */
       
  1899   data += packet->offset + 8;
       
  1900   ssrc = GST_READ_UINT32_BE (data);
       
  1901 
       
  1902   return ssrc;
       
  1903 }
       
  1904 
       
  1905 /**
       
  1906  * gst_rtcp_packet_fb_set_media_ssrc:
       
  1907  * @packet: a valid RTPFB or PSFB #GstRTCPPacket
       
  1908  * @ssrc: a media SSRC
       
  1909  *
       
  1910  * Set the media SSRC field of the RTPFB or PSFB @packet.
       
  1911  *
       
  1912  * Since: 0.10.23
       
  1913  */
       
  1914 #ifdef __SYMBIAN32__
       
  1915 EXPORT_C
       
  1916 #endif
       
  1917 
       
  1918 void
       
  1919 gst_rtcp_packet_fb_set_media_ssrc (GstRTCPPacket * packet, guint32 ssrc)
       
  1920 {
       
  1921   guint8 *data;
       
  1922 
       
  1923   g_return_if_fail (packet != NULL);
       
  1924   g_return_if_fail (packet->type == GST_RTCP_TYPE_RTPFB ||
       
  1925       packet->type == GST_RTCP_TYPE_PSFB);
       
  1926   g_return_if_fail (GST_IS_BUFFER (packet->buffer));
       
  1927 
       
  1928   data = GST_BUFFER_DATA (packet->buffer);
       
  1929 
       
  1930   /* skip header and sender ssrc */
       
  1931   data += packet->offset + 8;
       
  1932   GST_WRITE_UINT32_BE (data, ssrc);
       
  1933 }
       
  1934 
       
  1935 /**
       
  1936  * gst_rtcp_packet_fb_get_type:
       
  1937  * @packet: a valid RTPFB or PSFB #GstRTCPPacket
       
  1938  *
       
  1939  * Get the feedback message type of the FB @packet.
       
  1940  *
       
  1941  * Returns: The feedback message type.
       
  1942  *
       
  1943  * Since: 0.10.23
       
  1944  */
       
  1945 #ifdef __SYMBIAN32__
       
  1946 EXPORT_C
       
  1947 #endif
       
  1948 
       
  1949 GstRTCPFBType
       
  1950 gst_rtcp_packet_fb_get_type (GstRTCPPacket * packet)
       
  1951 {
       
  1952   g_return_val_if_fail (packet != NULL, GST_RTCP_FB_TYPE_INVALID);
       
  1953   g_return_val_if_fail (packet->type == GST_RTCP_TYPE_RTPFB ||
       
  1954       packet->type == GST_RTCP_TYPE_PSFB, GST_RTCP_FB_TYPE_INVALID);
       
  1955 
       
  1956   return packet->count;
       
  1957 }
       
  1958 
       
  1959 /**
       
  1960  * gst_rtcp_packet_fb_set_type:
       
  1961  * @packet: a valid RTPFB or PSFB #GstRTCPPacket
       
  1962  * @type: the #GstRTCPFBType to set
       
  1963  *
       
  1964  * Set the feedback message type of the FB @packet.
       
  1965  *
       
  1966  * Since: 0.10.23
       
  1967  */
       
  1968 #ifdef __SYMBIAN32__
       
  1969 EXPORT_C
       
  1970 #endif
       
  1971 
       
  1972 void
       
  1973 gst_rtcp_packet_fb_set_type (GstRTCPPacket * packet, GstRTCPFBType type)
       
  1974 {
       
  1975   guint8 *data;
       
  1976 
       
  1977   g_return_if_fail (packet != NULL);
       
  1978   g_return_if_fail (packet->type == GST_RTCP_TYPE_RTPFB ||
       
  1979       packet->type == GST_RTCP_TYPE_PSFB);
       
  1980   g_return_if_fail (GST_IS_BUFFER (packet->buffer));
       
  1981 
       
  1982   data = GST_BUFFER_DATA (packet->buffer);
       
  1983 
       
  1984   data[packet->offset] = (data[packet->offset] & 0xe0) | type;
       
  1985   packet->count = type;
       
  1986 }
       
  1987 
       
  1988 /**
       
  1989  * gst_rtcp_ntp_to_unix:
  1782  * gst_rtcp_ntp_to_unix:
  1990  * @ntptime: an NTP timestamp
  1783  * @ntptime: an NTP timestamp
  1991  *
  1784  *
  1992  * Converts an NTP time to UNIX nanoseconds. @ntptime can typically be
  1785  * Converts an NTP time to UNIX nanoseconds. @ntptime can typically be
  1993  * the NTP time of an SR RTCP message and contains, in the upper 32 bits, the
  1786  * the NTP time of an SR RTCP message and contains, in the upper 32 bits, the
  2024  * pass a value with nanoseconds since 1970. The NTP time will, in the upper
  1817  * pass a value with nanoseconds since 1970. The NTP time will, in the upper
  2025  * 32 bits, contain the number of seconds since 1900 and, in the lower 32
  1818  * 32 bits, contain the number of seconds since 1900 and, in the lower 32
  2026  * bits, the fractional seconds. The resulting value can be used as an ntptime
  1819  * bits, the fractional seconds. The resulting value can be used as an ntptime
  2027  * for constructing SR RTCP packets.
  1820  * for constructing SR RTCP packets.
  2028  *
  1821  *
  2029  * Returns: the NTP time for @unixtime.
  1822  * Returns: the NTP time for @gsttime.
  2030  */
  1823  */
  2031 #ifdef __SYMBIAN32__
  1824 #ifdef __SYMBIAN32__
  2032 EXPORT_C
  1825 EXPORT_C
  2033 #endif
  1826 #endif
  2034 
  1827