正在显示
2 个修改的文件
包含
327 行增加
和
4 行删除
@@ -1823,6 +1823,85 @@ char srs_utils_flv_video_frame_type(char* data, int size) | @@ -1823,6 +1823,85 @@ char srs_utils_flv_video_frame_type(char* data, int size) | ||
1823 | return frame_type; | 1823 | return frame_type; |
1824 | } | 1824 | } |
1825 | 1825 | ||
1826 | +char srs_utils_flv_audio_sound_format(char* data, int size) | ||
1827 | +{ | ||
1828 | + if (size < 1) { | ||
1829 | + return -1; | ||
1830 | + } | ||
1831 | + | ||
1832 | + u_int8_t sound_format = data[0]; | ||
1833 | + sound_format = (sound_format >> 4) & 0x0f; | ||
1834 | + if (sound_format > 15 || sound_format == 12 || sound_format == 13) { | ||
1835 | + return -1; | ||
1836 | + } | ||
1837 | + | ||
1838 | + return sound_format; | ||
1839 | +} | ||
1840 | + | ||
1841 | +char srs_utils_flv_audio_sound_rate(char* data, int size) | ||
1842 | +{ | ||
1843 | + if (size < 1) { | ||
1844 | + return -1; | ||
1845 | + } | ||
1846 | + | ||
1847 | + u_int8_t sound_rate = data[0]; | ||
1848 | + sound_rate = (sound_rate >> 2) & 0x03; | ||
1849 | + if (sound_rate > 3) { | ||
1850 | + return -1; | ||
1851 | + } | ||
1852 | + | ||
1853 | + return sound_rate; | ||
1854 | +} | ||
1855 | + | ||
1856 | +char srs_utils_flv_audio_sound_size(char* data, int size) | ||
1857 | +{ | ||
1858 | + if (size < 1) { | ||
1859 | + return -1; | ||
1860 | + } | ||
1861 | + | ||
1862 | + u_int8_t sound_size = data[0]; | ||
1863 | + sound_size = (sound_size >> 1) & 0x01; | ||
1864 | + if (sound_size > 1) { | ||
1865 | + return -1; | ||
1866 | + } | ||
1867 | + | ||
1868 | + return sound_size; | ||
1869 | +} | ||
1870 | + | ||
1871 | +char srs_utils_flv_audio_sound_type(char* data, int size) | ||
1872 | +{ | ||
1873 | + if (size < 1) { | ||
1874 | + return -1; | ||
1875 | + } | ||
1876 | + | ||
1877 | + u_int8_t sound_type = data[0]; | ||
1878 | + sound_type = sound_type & 0x01; | ||
1879 | + if (sound_type > 1) { | ||
1880 | + return -1; | ||
1881 | + } | ||
1882 | + | ||
1883 | + return sound_type; | ||
1884 | +} | ||
1885 | + | ||
1886 | +char srs_utils_flv_audio_aac_packet_type(char* data, int size) | ||
1887 | +{ | ||
1888 | + if (size < 2) { | ||
1889 | + return -1; | ||
1890 | + } | ||
1891 | + | ||
1892 | + if (srs_utils_flv_audio_sound_format(data, size) != 10) { | ||
1893 | + return -1; | ||
1894 | + } | ||
1895 | + | ||
1896 | + u_int8_t aac_packet_type = data[1]; | ||
1897 | + aac_packet_type = aac_packet_type; | ||
1898 | + if (aac_packet_type > 1) { | ||
1899 | + return -1; | ||
1900 | + } | ||
1901 | + | ||
1902 | + return aac_packet_type; | ||
1903 | +} | ||
1904 | + | ||
1826 | char* srs_human_amf0_print(srs_amf0_t amf0, char** pdata, int* psize) | 1905 | char* srs_human_amf0_print(srs_amf0_t amf0, char** pdata, int* psize) |
1827 | { | 1906 | { |
1828 | if (!amf0) { | 1907 | if (!amf0) { |
@@ -1876,7 +1955,7 @@ const char* srs_human_flv_video_codec_id2string(char codec_id) | @@ -1876,7 +1955,7 @@ const char* srs_human_flv_video_codec_id2string(char codec_id) | ||
1876 | 1955 | ||
1877 | const char* srs_human_flv_video_avc_packet_type2string(char avc_packet_type) | 1956 | const char* srs_human_flv_video_avc_packet_type2string(char avc_packet_type) |
1878 | { | 1957 | { |
1879 | - static const char* sps_pps = "SpsPps"; | 1958 | + static const char* sps_pps = "SH"; |
1880 | static const char* nalu = "Nalu"; | 1959 | static const char* nalu = "Nalu"; |
1881 | static const char* sps_pps_end = "SpsPpsEnd"; | 1960 | static const char* sps_pps_end = "SpsPpsEnd"; |
1882 | static const char* unknown = "Unknown"; | 1961 | static const char* unknown = "Unknown"; |
@@ -1912,6 +1991,109 @@ const char* srs_human_flv_video_frame_type2string(char frame_type) | @@ -1912,6 +1991,109 @@ const char* srs_human_flv_video_frame_type2string(char frame_type) | ||
1912 | return unknown; | 1991 | return unknown; |
1913 | } | 1992 | } |
1914 | 1993 | ||
1994 | +const char* srs_human_flv_audio_sound_format2string(char sound_format) | ||
1995 | +{ | ||
1996 | + static const char* linear_pcm = "LinearPCM"; | ||
1997 | + static const char* ad_pcm = "ADPCM"; | ||
1998 | + static const char* mp3 = "MP3"; | ||
1999 | + static const char* linear_pcm_le = "LinearPCMLe"; | ||
2000 | + static const char* nellymoser_16khz = "NellymoserKHz16"; | ||
2001 | + static const char* nellymoser_8khz = "NellymoserKHz8"; | ||
2002 | + static const char* nellymoser = "Nellymoser"; | ||
2003 | + static const char* g711_a_pcm = "G711APCM"; | ||
2004 | + static const char* g711_mu_pcm = "G711MuPCM"; | ||
2005 | + static const char* reserved = "Reserved"; | ||
2006 | + static const char* aac = "AAC"; | ||
2007 | + static const char* speex = "Speex"; | ||
2008 | + static const char* mp3_8khz = "MP3KHz8"; | ||
2009 | + static const char* device_specific = "DeviceSpecific"; | ||
2010 | + static const char* unknown = "Unknown"; | ||
2011 | + | ||
2012 | + switch (sound_format) { | ||
2013 | + case 0: return linear_pcm; | ||
2014 | + case 1: return ad_pcm; | ||
2015 | + case 2: return mp3; | ||
2016 | + case 3: return linear_pcm_le; | ||
2017 | + case 4: return nellymoser_16khz; | ||
2018 | + case 5: return nellymoser_8khz; | ||
2019 | + case 6: return nellymoser; | ||
2020 | + case 7: return g711_a_pcm; | ||
2021 | + case 8: return g711_mu_pcm; | ||
2022 | + case 9: return reserved; | ||
2023 | + case 10: return aac; | ||
2024 | + case 11: return speex; | ||
2025 | + case 14: return mp3_8khz; | ||
2026 | + case 15: return device_specific; | ||
2027 | + default: return unknown; | ||
2028 | + } | ||
2029 | + | ||
2030 | + return unknown; | ||
2031 | +} | ||
2032 | + | ||
2033 | +const char* srs_human_flv_audio_sound_rate2string(char sound_rate) | ||
2034 | +{ | ||
2035 | + static const char* khz_5_5 = "5.5KHz"; | ||
2036 | + static const char* khz_11 = "11KHz"; | ||
2037 | + static const char* khz_22 = "22KHz"; | ||
2038 | + static const char* khz_44 = "44KHz"; | ||
2039 | + static const char* unknown = "Unknown"; | ||
2040 | + | ||
2041 | + switch (sound_rate) { | ||
2042 | + case 0: return khz_5_5; | ||
2043 | + case 1: return khz_11; | ||
2044 | + case 2: return khz_22; | ||
2045 | + case 3: return khz_44; | ||
2046 | + default: return unknown; | ||
2047 | + } | ||
2048 | + | ||
2049 | + return unknown; | ||
2050 | +} | ||
2051 | + | ||
2052 | +const char* srs_human_flv_audio_sound_size2string(char sound_size) | ||
2053 | +{ | ||
2054 | + static const char* bit_8 = "8bit"; | ||
2055 | + static const char* bit_16 = "16bit"; | ||
2056 | + static const char* unknown = "Unknown"; | ||
2057 | + | ||
2058 | + switch (sound_size) { | ||
2059 | + case 0: return bit_8; | ||
2060 | + case 1: return bit_16; | ||
2061 | + default: return unknown; | ||
2062 | + } | ||
2063 | + | ||
2064 | + return unknown; | ||
2065 | +} | ||
2066 | + | ||
2067 | +const char* srs_human_flv_audio_sound_type2string(char sound_type) | ||
2068 | +{ | ||
2069 | + static const char* mono = "Mono"; | ||
2070 | + static const char* stereo = "Stereo"; | ||
2071 | + static const char* unknown = "Unknown"; | ||
2072 | + | ||
2073 | + switch (sound_type) { | ||
2074 | + case 0: return mono; | ||
2075 | + case 1: return stereo; | ||
2076 | + default: return unknown; | ||
2077 | + } | ||
2078 | + | ||
2079 | + return unknown; | ||
2080 | +} | ||
2081 | + | ||
2082 | +const char* srs_human_flv_audio_aac_packet_type2string(char aac_packet_type) | ||
2083 | +{ | ||
2084 | + static const char* sps_pps = "SH"; | ||
2085 | + static const char* raw = "Raw"; | ||
2086 | + static const char* unknown = "Unknown"; | ||
2087 | + | ||
2088 | + switch (aac_packet_type) { | ||
2089 | + case 0: return sps_pps; | ||
2090 | + case 1: return raw; | ||
2091 | + default: return unknown; | ||
2092 | + } | ||
2093 | + | ||
2094 | + return unknown; | ||
2095 | +} | ||
2096 | + | ||
1915 | int srs_human_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int size) | 2097 | int srs_human_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int size) |
1916 | { | 2098 | { |
1917 | int ret = ERROR_SUCCESS; | 2099 | int ret = ERROR_SUCCESS; |
@@ -1929,8 +2111,14 @@ int srs_human_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int | @@ -1929,8 +2111,14 @@ int srs_human_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int | ||
1929 | srs_human_flv_video_frame_type2string(srs_utils_flv_video_frame_type(data, size)) | 2111 | srs_human_flv_video_frame_type2string(srs_utils_flv_video_frame_type(data, size)) |
1930 | ); | 2112 | ); |
1931 | } else if (type == SRS_RTMP_TYPE_AUDIO) { | 2113 | } else if (type == SRS_RTMP_TYPE_AUDIO) { |
1932 | - srs_human_trace("Audio packet type=%s, dts=%d, pts=%d, size=%d", | ||
1933 | - srs_human_flv_tag_type2string(type), timestamp, pts, size); | 2114 | + srs_human_trace("Audio packet type=%s, dts=%d, pts=%d, size=%d, %s(%s,%s,%s,%s)", |
2115 | + srs_human_flv_tag_type2string(type), timestamp, pts, size, | ||
2116 | + srs_human_flv_audio_sound_format2string(srs_utils_flv_audio_sound_format(data, size)), | ||
2117 | + srs_human_flv_audio_sound_rate2string(srs_utils_flv_audio_sound_rate(data, size)), | ||
2118 | + srs_human_flv_audio_sound_size2string(srs_utils_flv_audio_sound_size(data, size)), | ||
2119 | + srs_human_flv_audio_sound_type2string(srs_utils_flv_audio_sound_type(data, size)), | ||
2120 | + srs_human_flv_audio_aac_packet_type2string(srs_utils_flv_audio_aac_packet_type(data, size)) | ||
2121 | + ); | ||
1934 | } else if (type == SRS_RTMP_TYPE_SCRIPT) { | 2122 | } else if (type == SRS_RTMP_TYPE_SCRIPT) { |
1935 | srs_human_verbose("Data packet type=%s, time=%d, size=%d", | 2123 | srs_human_verbose("Data packet type=%s, time=%d, size=%d", |
1936 | srs_human_flv_tag_type2string(type), timestamp, size); | 2124 | srs_human_flv_tag_type2string(type), timestamp, size); |
@@ -660,6 +660,70 @@ extern char srs_utils_flv_video_avc_packet_type(char* data, int size); | @@ -660,6 +660,70 @@ extern char srs_utils_flv_video_avc_packet_type(char* data, int size); | ||
660 | */ | 660 | */ |
661 | extern char srs_utils_flv_video_frame_type(char* data, int size); | 661 | extern char srs_utils_flv_video_frame_type(char* data, int size); |
662 | 662 | ||
663 | +/** | ||
664 | +* get the SoundFormat of audio tag. | ||
665 | +* Format of SoundData. The following values are defined: | ||
666 | +* 0 = Linear PCM, platform endian | ||
667 | +* 1 = ADPCM | ||
668 | +* 2 = MP3 | ||
669 | +* 3 = Linear PCM, little endian | ||
670 | +* 4 = Nellymoser 16 kHz mono | ||
671 | +* 5 = Nellymoser 8 kHz mono | ||
672 | +* 6 = Nellymoser | ||
673 | +* 7 = G.711 A-law logarithmic PCM | ||
674 | +* 8 = G.711 mu-law logarithmic PCM | ||
675 | +* 9 = reserved | ||
676 | +* 10 = AAC | ||
677 | +* 11 = Speex | ||
678 | +* 14 = MP3 8 kHz | ||
679 | +* 15 = Device-specific sound | ||
680 | +* Formats 7, 8, 14, and 15 are reserved. | ||
681 | +* AAC is supported in Flash Player 9,0,115,0 and higher. | ||
682 | +* Speex is supported in Flash Player 10 and higher. | ||
683 | +* @return the sound format. -1(0xff) for error. | ||
684 | +*/ | ||
685 | +extern char srs_utils_flv_audio_sound_format(char* data, int size); | ||
686 | + | ||
687 | +/** | ||
688 | +* get the SoundRate of audio tag. | ||
689 | +* Sampling rate. The following values are defined: | ||
690 | +* 0 = 5.5 kHz | ||
691 | +* 1 = 11 kHz | ||
692 | +* 2 = 22 kHz | ||
693 | +* 3 = 44 kHz | ||
694 | +* @return the sound rate. -1(0xff) for error. | ||
695 | +*/ | ||
696 | +extern char srs_utils_flv_audio_sound_rate(char* data, int size); | ||
697 | + | ||
698 | +/** | ||
699 | +* get the SoundSize of audio tag. | ||
700 | +* Size of each audio sample. This parameter only pertains to | ||
701 | +* uncompressed formats. Compressed formats always decode | ||
702 | +* to 16 bits internally. | ||
703 | +* 0 = 8-bit samples | ||
704 | +* 1 = 16-bit samples | ||
705 | +* @return the sound size. -1(0xff) for error. | ||
706 | +*/ | ||
707 | +extern char srs_utils_flv_audio_sound_size(char* data, int size); | ||
708 | + | ||
709 | +/** | ||
710 | +* get the SoundType of audio tag. | ||
711 | +* Mono or stereo sound | ||
712 | +* 0 = Mono sound | ||
713 | +* 1 = Stereo sound | ||
714 | +* @return the sound type. -1(0xff) for error. | ||
715 | +*/ | ||
716 | +extern char srs_utils_flv_audio_sound_type(char* data, int size); | ||
717 | + | ||
718 | +/** | ||
719 | +* get the AACPacketType of audio tag. | ||
720 | +* The following values are defined: | ||
721 | +* 0 = AAC sequence header | ||
722 | +* 1 = AAC raw | ||
723 | +* @return the aac packet type. -1(0xff) for error. | ||
724 | +*/ | ||
725 | +extern char srs_utils_flv_audio_aac_packet_type(char* data, int size); | ||
726 | + | ||
663 | /************************************************************* | 727 | /************************************************************* |
664 | ************************************************************** | 728 | ************************************************************** |
665 | * human readable print. | 729 | * human readable print. |
@@ -699,7 +763,7 @@ extern const char* srs_human_flv_video_codec_id2string(char codec_id); | @@ -699,7 +763,7 @@ extern const char* srs_human_flv_video_codec_id2string(char codec_id); | ||
699 | 763 | ||
700 | /** | 764 | /** |
701 | * get the avc packet type string. | 765 | * get the avc packet type string. |
702 | -* SpsPps = AVC sequence header | 766 | +* SH = AVC sequence header |
703 | * Nalu = AVC NALU | 767 | * Nalu = AVC NALU |
704 | * SpsPpsEnd = AVC end of sequence | 768 | * SpsPpsEnd = AVC end of sequence |
705 | * otherwise, "Unknown" | 769 | * otherwise, "Unknown" |
@@ -722,6 +786,77 @@ extern const char* srs_human_flv_video_avc_packet_type2string(char avc_packet_ty | @@ -722,6 +786,77 @@ extern const char* srs_human_flv_video_avc_packet_type2string(char avc_packet_ty | ||
722 | extern const char* srs_human_flv_video_frame_type2string(char frame_type); | 786 | extern const char* srs_human_flv_video_frame_type2string(char frame_type); |
723 | 787 | ||
724 | /** | 788 | /** |
789 | +* get the SoundFormat string. | ||
790 | +* Format of SoundData. The following values are defined: | ||
791 | +* LinearPCM = Linear PCM, platform endian | ||
792 | +* ADPCM = ADPCM | ||
793 | +* MP3 = MP3 | ||
794 | +* LinearPCMLe = Linear PCM, little endian | ||
795 | +* NellymoserKHz16 = Nellymoser 16 kHz mono | ||
796 | +* NellymoserKHz8 = Nellymoser 8 kHz mono | ||
797 | +* Nellymoser = Nellymoser | ||
798 | +* G711APCM = G.711 A-law logarithmic PCM | ||
799 | +* G711MuPCM = G.711 mu-law logarithmic PCM | ||
800 | +* Reserved = reserved | ||
801 | +* AAC = AAC | ||
802 | +* Speex = Speex | ||
803 | +* MP3KHz8 = MP3 8 kHz | ||
804 | +* DeviceSpecific = Device-specific sound | ||
805 | +* otherwise, "Unknown" | ||
806 | +* @remark user never free the return char*, | ||
807 | +* it's static shared const string. | ||
808 | +*/ | ||
809 | +extern const char* srs_human_flv_audio_sound_format2string(char sound_format); | ||
810 | + | ||
811 | +/** | ||
812 | +* get the SoundRate of audio tag. | ||
813 | +* Sampling rate. The following values are defined: | ||
814 | +* 5.5KHz = 5.5 kHz | ||
815 | +* 11KHz = 11 kHz | ||
816 | +* 22KHz = 22 kHz | ||
817 | +* 44KHz = 44 kHz | ||
818 | +* otherwise, "Unknown" | ||
819 | +* @remark user never free the return char*, | ||
820 | +* it's static shared const string. | ||
821 | +*/ | ||
822 | +extern const char* srs_human_flv_audio_sound_rate2string(char sound_rate); | ||
823 | + | ||
824 | +/** | ||
825 | +* get the SoundSize of audio tag. | ||
826 | +* Size of each audio sample. This parameter only pertains to | ||
827 | +* uncompressed formats. Compressed formats always decode | ||
828 | +* to 16 bits internally. | ||
829 | +* 8bit = 8-bit samples | ||
830 | +* 16bit = 16-bit samples | ||
831 | +* otherwise, "Unknown" | ||
832 | +* @remark user never free the return char*, | ||
833 | +* it's static shared const string. | ||
834 | +*/ | ||
835 | +extern const char* srs_human_flv_audio_sound_size2string(char sound_size); | ||
836 | + | ||
837 | +/** | ||
838 | +* get the SoundType of audio tag. | ||
839 | +* Mono or stereo sound | ||
840 | +* Mono = Mono sound | ||
841 | +* Stereo = Stereo sound | ||
842 | +* otherwise, "Unknown" | ||
843 | +* @remark user never free the return char*, | ||
844 | +* it's static shared const string. | ||
845 | +*/ | ||
846 | +extern const char* srs_human_flv_audio_sound_type2string(char sound_type); | ||
847 | + | ||
848 | +/** | ||
849 | +* get the AACPacketType of audio tag. | ||
850 | +* The following values are defined: | ||
851 | +* SH = AAC sequence header | ||
852 | +* Raw = AAC raw | ||
853 | +* otherwise, "Unknown" | ||
854 | +* @remark user never free the return char*, | ||
855 | +* it's static shared const string. | ||
856 | +*/ | ||
857 | +extern const char* srs_human_flv_audio_aac_packet_type2string(char aac_packet_type); | ||
858 | + | ||
859 | +/** | ||
725 | * print the rtmp packet, use srs_human_trace/srs_human_verbose for packet, | 860 | * print the rtmp packet, use srs_human_trace/srs_human_verbose for packet, |
726 | * and use srs_human_raw for script data body. | 861 | * and use srs_human_raw for script data body. |
727 | * @return an error code for parse the timetstamp to dts and pts. | 862 | * @return an error code for parse the timetstamp to dts and pts. |
-
请 注册 或 登录 后发表评论