1. 概述
查看https://www.rfc-editor.org/rfc/rfc3267.txt,可了解到该协议在第4章节定义了RTP上AMR和AMR-WB的两种数据格式Bandwidth-Efficient Mode和Octet-aligned Mode,第5章节定义了文件存储AMR和AMR-WB的数据格式。
1. Introduction.................................................... 3
2. Conventions and Acronyms........................................ 3
3. Background on AMR/AMR-WB and Design Principles.................. 4
3.1. The Adaptive Multi-Rate (AMR) Speech Codec.................. 4
3.2. The Adaptive Multi-Rate Wideband (AMR-WB) Speech Codec...... 5
3.3. Multi-rate Encoding and Mode Adaptation..................... 5
3.4. Voice Activity Detection and Discontinuous Transmission..... 6
3.5. Support for Multi-Channel Session........................... 6
3.6. Unequal Bit-error Detection and Protection.................. 7
3.6.1. Applying UEP and UED in an IP Network................... 7
3.7. Robustness against Packet Loss.............................. 9
3.7.1. Use of Forward Error Correction (FEC)................... 9
3.7.2. Use of Frame Interleaving...............................11
3.8. Bandwidth Efficient or Octet-aligned Mode...................11
3.9. AMR or AMR-WB Speech over IP scenarios......................12
4. AMR and AMR-WB RTP Payload Formats..............................14
4.1. RTP Header Usage............................................14
4.2. Payload Structure...........................................16
4.3. Bandwidth-Efficient Mode....................................16
4.3.1. The Payload Header......................................16
4.3.2. The Payload Table of Contents...........................17
4.3.3. Speech Data.............................................19
4.3.4. Algorithm for Forming the Payload.......................20
4.3.5 Payload Examples.........................................21
4.3.5.1. Single Channel Payload Carrying a Single Frame...21
4.3.5.2. Single Channel Payload Carrying Multiple Frames..22
4.3.5.3. Multi-Channel Payload Carrying Multiple Frames...23
4.4. Octet-aligned Mode..........................................25
4.4.1. The Payload Header......................................25
4.4.2. The Payload Table of Contents and Frame CRCs............26
4.4.2.1. Use of Frame CRC for UED over IP....................28
4.4.3. Speech Data.............................................30
4.4.4. Methods for Forming the Payload.........................30
4.4.5. Payload Examples........................................32
4.4.5.1. Basic Single Channel Payload Carrying
Multiple Frames..................................32
4.4.5.2. Two Channel Payload with CRC, Interleaving,
and Robust-sorting...............................32
4.5. Implementation Considerations...............................33
5. AMR and AMR-WB Storage Format...................................34
5.1. Single Channel Header.......................................34
5.2. Multi-channel Header........................................35
5.3. Speech Frames...............................................36
6. Congestion Control..............................................37
7. Security Considerations.........................................37
7.1. Confidentiality.............................................37
7.2. Authentication..............................................38
7.3. Decoding Validation.........................................38
8. Payload Format Parameters.......................................38
8.1. AMR MIME Registration.......................................39
8.2. AMR-WB MIME Registration....................................41
8.3. Mapping MIME Parameters into SDP............................44
9. IANA Considerations.............................................45
10. Acknowledgements...............................................45
11. References.....................................................45
11.1 Informative References......................................46
12. Authors' Addresses.............................................48
13. Full Copyright Statement.......................................49
2. AMR文件解析
2.1. 选择文件
选择文件如下:
/frameworks/base/media/tests/contents/media_api/music/test_amr_ietf.amr
2.2. 分析文件
23 21 41 4D 52 0A -> #!AMR\n RFC3267 5.1. Single channel Header
3C 91 17 16 BE 66 79 E1 E0 01 E7 AF F0 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
3C 48 77 24 96 66 79 E1 E0 01 E7 BA F0 00 00 00 C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
3C 55 00 88 B6 66 79 E1 E0 01 E7 CF F0 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
3C 48 F9 1F 96 66 79 E1 E0 01 E7 8A F0 00 00 00 C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
3C 54 FD 1F B6 66 79 E1 E0 01 E7 CF F0 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
3C -> FT = b0111 = 7(12.2kbit/s) 3GPP26.101 4.1 AMR Header and AMR Auxiliary Information
0 1 2 3 4 5 6 7 -> Q = 1(Good frame) 3GPP26.101 4.1 AMR Header and AMR Auxiliary Information
+-+-+-+-+-+-+-+-+
|P| FT |Q|P|P|
+-+-+-+-+-+-+-+-+
0 0 1 1 1 1 0 0
-> mode = b0111 = 7 size = packed_size[7] + 1 = 32
https://github.com/marcelogp/AMR-WB/blob/master/libavformat/amr.c
static const uint8_t packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
3GPP26.101 4.2.2 AMR Core Frame with speech bits: Class division
Class A 81 bits
Class B 103 bits
Class C 60 bits
3. AMR-WB文件解析
3.1 文件解析
23 21 41 4D 52 2D 57 42 0A -> #!AMR-WB\n RFC3267 5.1. Single channel Header
44 54 06 22 40 CB 82 8C 42 69 20 09 1D 83 CC CE E6 E7 FE 14 D8 43 E7 E0 C1 47 A4 E0 4D 20 50 DB 42 E2 1D 86 80 D1 00 36 B3 3E 53 1A B0 45 71 FB 0D 8C E9 E9 1E 26 EB 9A A7 75 11 86 F0
44 40 2A 66 96 F9 A4 DC C6 1F A9 E0 81 CF 4A 14 81 BF FC 86 A8 BB 72 D8 45 8E 3E 2B 1D B6 F1 F9 AD 4C 45 20 A7 A8 CA 14 62 1A 4F 35 D2 7C 16 A9 6A B3 77 B9 0E 16 DC 87 11 F9 D5 C2 E8
44 -> FT = b1000 = 8(AMR-WB 23.85 kbit/s) 3GPP26.201 4.1 AMR-WB Header and AMR-WB Auxiliary Information
0 1 2 3 4 5 6 7 -> Q = 1(Good frame) 3GPP26.201 4.1 AMR-WB Header and AMR-WB Auxiliary Information
+-+-+-+-+-+-+-+-+
|P| FT |Q|P|P|
+-+-+-+-+-+-+-+-+
0 1 0 0 0 1 0 0
-> mode = b1000 = 8 size = packed_size[8] + 1 = 62
https://github.com/marcelogp/AMR-WB/blob/master/libavformat/amr.c
static uint8_t packed_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
3.2 数据流解析
从wireshark查看一个Bandwidth-Efficient Mode的AMR-WB数据流进行解析。
f470431cbbc3dcfcc92d21de35f03d375a7bf5b970b67f0ccfb2c08dc27889c40d5bc7343700f74bb08903a03bf49f4763bf2ced87457faf1b43580e0c
参考RFC3267 4.3. Bandwidth-Efficient Mode,分析前两个字节:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| CMR |F| FT |Q| d(0)~d(n)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1 1 1 1 0 1 0 0 0 1 1 1 0 0 0 0
CMR = 15
FT = 8
4. 参考资料
RTP Payload Format and File Storage Format for the AMR and AMR-WB Audio Codecs
https://www.rfc-editor.org/rfc/rfc3267.txt
AMR和AMR-WB帧结构
3GPP TS 26.101 Mandatory speech codec speech processing functions; AMR speech codec frame structure
3GPP TS 26.201 Speech codec speech processing functions; AMR-WB speech codec; Frame structure
AMR-WB数据生成方法
3GPP TS 26.190 Speech codec speech processing functions; AMR-WB speech codec; Transcoding functions
AMR在IP域中的编码(rfc3267,4867)
https://blog.csdn.net/runningya/article/details/6227384
Display Filter Reference: Adaptive Multi-Rate
https://www.wireshark.org/docs/dfref/a/amr.html
[Reserved != 0, wrongly encoded or not octet aligned. Decoding as bandwidth-efficient mode]
Audio File Formats - AMR
https://docs.fileformat.com/audio/amr/
RIFF和WAVE音频文件格式
https://www.cnblogs.com/wangguchangqing/p/5957531.htm
8 Best Hex Editors You Can Try
https://tech4fresher.com/best-hex-editors/
HEXED.IT - THE CLIENT-SIDE JAVASCRIPT BASED HEX EDITOR
https://hexed.it/
HXD Hex Editor
https://mh-nexus.de/en/downloads.php?product=HxD20
MediaInfo
https://mediaarea.net/en/MediaInfo
电脑提示调用DllRegisterServer失败解决方法【详细步骤】
https://product.pconline.com.cn/itbk/software/dnyw/1492/14920906.html
音频转换工具
https://www.freeconvert.com/audio-converter
https://convertio.co/zh/audio-converter/