/src/ffmpeg/libavformat/rmsipr.c
Line | Count | Source |
1 | | /* |
2 | | * tables and functions for demuxing SIPR audio muxed RealMedia style |
3 | | * |
4 | | * This file is part of FFmpeg. |
5 | | * |
6 | | * FFmpeg is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU Lesser General Public |
8 | | * License as published by the Free Software Foundation; either |
9 | | * version 2.1 of the License, or (at your option) any later version. |
10 | | * |
11 | | * FFmpeg is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | | * Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public |
17 | | * License along with FFmpeg; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #include <stdint.h> |
22 | | |
23 | | #include "rmsipr.h" |
24 | | |
25 | | const unsigned char ff_sipr_subpk_size[4] = { 29, 19, 37, 20 }; |
26 | | |
27 | | static const unsigned char sipr_swaps[38][2] = { |
28 | | { 0, 63 }, { 1, 22 }, { 2, 44 }, { 3, 90 }, |
29 | | { 5, 81 }, { 7, 31 }, { 8, 86 }, { 9, 58 }, |
30 | | { 10, 36 }, { 12, 68 }, { 13, 39 }, { 14, 73 }, |
31 | | { 15, 53 }, { 16, 69 }, { 17, 57 }, { 19, 88 }, |
32 | | { 20, 34 }, { 21, 71 }, { 24, 46 }, { 25, 94 }, |
33 | | { 26, 54 }, { 28, 75 }, { 29, 50 }, { 32, 70 }, |
34 | | { 33, 92 }, { 35, 74 }, { 38, 85 }, { 40, 56 }, |
35 | | { 42, 87 }, { 43, 65 }, { 45, 59 }, { 48, 79 }, |
36 | | { 49, 93 }, { 51, 89 }, { 55, 95 }, { 61, 76 }, |
37 | | { 67, 83 }, { 77, 80 } |
38 | | }; |
39 | | |
40 | | /* This can be optimized, e.g. use memcpy() if data blocks are aligned. */ |
41 | | void ff_rm_reorder_sipr_data(uint8_t *buf, int sub_packet_h, int framesize) |
42 | 4.37k | { |
43 | 4.37k | int n, bs = sub_packet_h * framesize * 2 / 96; // nibbles per subpacket |
44 | | |
45 | 170k | for (n = 0; n < 38; n++) { |
46 | 166k | int j; |
47 | 166k | int i = bs * sipr_swaps[n][0]; |
48 | 166k | int o = bs * sipr_swaps[n][1]; |
49 | | |
50 | | /* swap 4bit-nibbles of block 'i' with 'o' */ |
51 | 5.71M | for (j = 0; j < bs; j++, i++, o++) { |
52 | 5.54M | int x = (buf[i >> 1] >> (4 * (i & 1))) & 0xF, |
53 | 5.54M | y = (buf[o >> 1] >> (4 * (o & 1))) & 0xF; |
54 | | |
55 | 5.54M | buf[o >> 1] = (x << (4 * (o & 1))) | |
56 | 5.54M | (buf[o >> 1] & (0xF << (4 * !(o & 1)))); |
57 | 5.54M | buf[i >> 1] = (y << (4 * (i & 1))) | |
58 | 5.54M | (buf[i >> 1] & (0xF << (4 * !(i & 1)))); |
59 | 5.54M | } |
60 | 166k | } |
61 | 4.37k | } |