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