Mercurial > libavcodec.hg
annotate amr.h @ 12494:94eaea836bf4 libavcodec
Check avctx width/height more thoroughly (e.g. all values 0 except width would
have been accepted before).
Also do not fail if they are invalid but instead override them to 0.
This allows decoding e.g. MPEG video when only the container values are corrupted.
For encoding a value of 0,0 of course makes no sense, but was allowed
through before and will be caught by an extra check in the encode function.
author | reimar |
---|---|
date | Wed, 15 Sep 2010 04:46:55 +0000 |
parents | b42e02e9bf2b |
children |
rev | line source |
---|---|
12485
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
1 /* |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
2 * Shared functions between AMR codecs |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
3 * |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
4 * Copyright (c) 2010 Marcelo Galvao Povoa |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
5 * |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
6 * This file is part of FFmpeg. |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
7 * |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
10 * License as published by the Free Software Foundation; either |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
12 * |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
17 * |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
21 */ |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
22 |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
23 #ifndef AVCODEC_AMR_H |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
24 #define AVCODEC_AMR_H |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
25 |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
26 #ifdef AMR_USE_16BIT_TABLES |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
27 #define R_TABLE_TYPE uint16_t |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
28 #else |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
29 #define R_TABLE_TYPE uint8_t |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
30 #endif |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
31 |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
32 /** |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
33 * Fill the frame structure variables from bitstream by parsing the |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
34 * given reordering table that uses the following format: |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
35 * |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
36 * Each field (16 bits) in the AMR Frame is stored as: |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
37 * - one byte for the number of bits in the field |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
38 * - one byte for the field index |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
39 * - then, one byte for each bit of the field (from most-significant to least) |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
40 * of the position of that bit in the AMR frame. |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
41 * |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
42 * @param out pointer to the frame struct |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
43 * @param size the size in bytes of the frame struct |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
44 * @param data input bitstream after the frame header |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
45 * @param ord_table the reordering table as above |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
46 */ |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
47 static inline void ff_amr_bit_reorder(uint16_t *out, int size, |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
48 const uint8_t *data, |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
49 const R_TABLE_TYPE *ord_table) |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
50 { |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
51 int field_size; |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
52 |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
53 memset(out, 0, size); |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
54 while ((field_size = *ord_table++)) { |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
55 int field = 0; |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
56 int field_offset = *ord_table++; |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
57 while (field_size--) { |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
58 int bit = *ord_table++; |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
59 field <<= 1; |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
60 field |= data[bit >> 3] >> (bit & 7) & 1; |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
61 } |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
62 out[field_offset] = field; |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
63 } |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
64 } |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
65 |
b42e02e9bf2b
Move AMR-NB frame unpacking code to a common file so it can be reused in
vitor
parents:
diff
changeset
|
66 #endif /* AVCODEC_AMR_H */ |