gst_plugins_base/gst-libs/gst/rtp/gstrtcpbuffer.c
changeset 16 8e837d1bf446
parent 0 0e761a78d257
child 30 7e817e7e631c
equal deleted inserted replaced
15:4b0c6ed43234 16:8e837d1bf446
    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; you can move to the next packet with
    39  * into the RTCP buffer;
       
    40 #ifdef __SYMBIAN32__
       
    41 EXPORT_C
       
    42 #endif
       
    43  you can move to the next packet with
    40  * gst_rtcp_packet_move_to_next().
    44  * gst_rtcp_packet_move_to_next().
    41  * </para>
    45  * </para>
    42  * </refsect2>
    46  * </refsect2>
    43  *
    47  *
       
    48  * Last reviewed on 2007-03-26 (0.10.13)
       
    49  *
    44  * Since: 0.10.13
    50  * Since: 0.10.13
    45  *
       
    46  * Last reviewed on 2007-03-26 (0.10.13)
       
    47  */
    51  */
    48 
    52 
    49 #include <string.h>
    53 #include <string.h>
    50 
    54 
    51 #include "gstrtcpbuffer.h"
    55 #include "gstrtcpbuffer.h"
   403  * Returns: TRUE if @packet is pointing to a valid packet after calling this
   407  * Returns: TRUE if @packet is pointing to a valid packet after calling this
   404  * function.
   408  * function.
   405  */
   409  */
   406 #ifdef __SYMBIAN32__
   410 #ifdef __SYMBIAN32__
   407 EXPORT_C
   411 EXPORT_C
   408 #endif 
   412 #endif
       
   413 
   409 gboolean
   414 gboolean
   410 gst_rtcp_packet_move_to_next (GstRTCPPacket * packet)
   415 gst_rtcp_packet_move_to_next (GstRTCPPacket * packet)
   411 {
   416 {
   412   g_return_val_if_fail (packet != NULL, FALSE);
   417   g_return_val_if_fail (packet != NULL, FALSE);
   413   g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID, FALSE);
   418   g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID, FALSE);
   486       len = 4;
   491       len = 4;
   487       break;
   492       break;
   488     case GST_RTCP_TYPE_APP:
   493     case GST_RTCP_TYPE_APP:
   489       len = 12;
   494       len = 12;
   490       break;
   495       break;
       
   496     case GST_RTCP_TYPE_RTPFB:
       
   497       len = 12;
       
   498       break;
       
   499     case GST_RTCP_TYPE_PSFB:
       
   500       len = 12;
   491     default:
   501     default:
   492       goto unknown_type;
   502       goto unknown_type;
   493   }
   503   }
   494   if (packet->offset + len >= size)
   504   if (packet->offset + len >= size)
   495     goto no_space;
   505     goto no_space;
   523 
   533 
   524 /**
   534 /**
   525  * gst_rtcp_packet_remove:
   535  * gst_rtcp_packet_remove:
   526  * @packet: a #GstRTCPPacket
   536  * @packet: a #GstRTCPPacket
   527  *
   537  *
   528  * Removes the packet pointed to by @packet.
   538  * Removes the packet pointed to by @packet and moves pointer to the next one
   529  *
   539  *
   530  * Note: Not implemented.
   540  * Returns: TRUE if @packet is pointing to a valid packet after calling this
   531  */
   541  * function.
   532 #ifdef __SYMBIAN32__
   542  */
   533 EXPORT_C
   543 #ifdef __SYMBIAN32__
   534 #endif
   544 EXPORT_C
   535 
   545 #endif
   536 void
   546 
       
   547 gboolean
   537 gst_rtcp_packet_remove (GstRTCPPacket * packet)
   548 gst_rtcp_packet_remove (GstRTCPPacket * packet)
   538 {
   549 {
   539   g_return_if_fail (packet != NULL);
   550   gboolean ret = FALSE;
   540   g_return_if_fail (packet->type != GST_RTCP_TYPE_INVALID);
   551   guint offset = 0;
   541 
   552 
   542   g_warning ("not implemented");
   553   g_return_val_if_fail (packet != NULL, FALSE);
       
   554   g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID, FALSE);
       
   555 
       
   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;
   543 }
   570 }
   544 
   571 
   545 /**
   572 /**
   546  * gst_rtcp_packet_get_padding:
   573  * gst_rtcp_packet_get_padding:
   547  * @packet: a valid #GstRTCPPacket
   574  * @packet: a valid #GstRTCPPacket
   567  * gst_rtcp_packet_get_type:
   594  * gst_rtcp_packet_get_type:
   568  * @packet: a valid #GstRTCPPacket
   595  * @packet: a valid #GstRTCPPacket
   569  *
   596  *
   570  * Get the packet type of the packet pointed to by @packet.
   597  * Get the packet type of the packet pointed to by @packet.
   571  *
   598  *
   572  * Returns: The packet type.
   599  * Returns: The packet type or GST_RTCP_TYPE_INVALID when @packet is not
       
   600  * pointing to a valid packet.
   573  */
   601  */
   574 #ifdef __SYMBIAN32__
   602 #ifdef __SYMBIAN32__
   575 EXPORT_C
   603 EXPORT_C
   576 #endif
   604 #endif
   577 
   605 
   578 GstRTCPType
   606 GstRTCPType
   579 gst_rtcp_packet_get_type (GstRTCPPacket * packet)
   607 gst_rtcp_packet_get_type (GstRTCPPacket * packet)
   580 {
   608 {
   581   g_return_val_if_fail (packet != NULL, GST_RTCP_TYPE_INVALID);
   609   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);
       
   584 
   610 
   585   return packet->type;
   611   return packet->type;
   586 }
   612 }
   587 
   613 
   588 /**
   614 /**
  1777     return FALSE;
  1803     return FALSE;
  1778   }
  1804   }
  1779 }
  1805 }
  1780 
  1806 
  1781 /**
  1807 /**
       
  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 /**
  1782  * gst_rtcp_ntp_to_unix:
  1989  * gst_rtcp_ntp_to_unix:
  1783  * @ntptime: an NTP timestamp
  1990  * @ntptime: an NTP timestamp
  1784  *
  1991  *
  1785  * Converts an NTP time to UNIX nanoseconds. @ntptime can typically be
  1992  * Converts an NTP time to UNIX nanoseconds. @ntptime can typically be
  1786  * the NTP time of an SR RTCP message and contains, in the upper 32 bits, the
  1993  * the NTP time of an SR RTCP message and contains, in the upper 32 bits, the
  1817  * pass a value with nanoseconds since 1970. The NTP time will, in the upper
  2024  * pass a value with nanoseconds since 1970. The NTP time will, in the upper
  1818  * 32 bits, contain the number of seconds since 1900 and, in the lower 32
  2025  * 32 bits, contain the number of seconds since 1900 and, in the lower 32
  1819  * bits, the fractional seconds. The resulting value can be used as an ntptime
  2026  * bits, the fractional seconds. The resulting value can be used as an ntptime
  1820  * for constructing SR RTCP packets.
  2027  * for constructing SR RTCP packets.
  1821  *
  2028  *
  1822  * Returns: the NTP time for @gsttime.
  2029  * Returns: the NTP time for @unixtime.
  1823  */
  2030  */
  1824 #ifdef __SYMBIAN32__
  2031 #ifdef __SYMBIAN32__
  1825 EXPORT_C
  2032 EXPORT_C
  1826 #endif
  2033 #endif
  1827 
  2034