/src/ffmpeg/libavcodec/ahx_parser.c
Line | Count | Source |
1 | | /* |
2 | | * This file is part of FFmpeg. |
3 | | * |
4 | | * FFmpeg is free software; you can redistribute it and/or |
5 | | * modify it under the terms of the GNU Lesser General Public |
6 | | * License as published by the Free Software Foundation; either |
7 | | * version 2.1 of the License, or (at your option) any later version. |
8 | | * |
9 | | * FFmpeg is distributed in the hope that it will be useful, |
10 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | | * Lesser General Public License for more details. |
13 | | * |
14 | | * You should have received a copy of the GNU Lesser General Public |
15 | | * License along with FFmpeg; if not, write to the Free Software |
16 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | | */ |
18 | | |
19 | | /** |
20 | | * @file |
21 | | * AHX audio parser |
22 | | * |
23 | | * Splits packets into individual blocks. |
24 | | */ |
25 | | |
26 | | #include "libavutil/intreadwrite.h" |
27 | | #include "parser.h" |
28 | | #include "parser_internal.h" |
29 | | |
30 | | typedef struct AHXParseContext { |
31 | | ParseContext pc; |
32 | | uint32_t header; |
33 | | int size; |
34 | | } AHXParseContext; |
35 | | |
36 | | static int ahx_parse(AVCodecParserContext *s1, |
37 | | AVCodecContext *avctx, |
38 | | const uint8_t **poutbuf, int *poutbuf_size, |
39 | | const uint8_t *buf, int buf_size) |
40 | 1.33M | { |
41 | 1.33M | AHXParseContext *s = s1->priv_data; |
42 | 1.33M | ParseContext *pc = &s->pc; |
43 | 1.33M | uint32_t state = pc->state; |
44 | 1.33M | int next = END_NOT_FOUND; |
45 | | |
46 | 33.3M | for (int i = 0; i < buf_size; i++) { |
47 | 33.2M | state = (state << 8) | buf[i]; |
48 | 33.2M | s->size++; |
49 | 33.2M | if (s->size == 4 && !s->header) |
50 | 463k | s->header = state; |
51 | 33.2M | if (s->size > 4 && state == s->header) { |
52 | 1.23M | next = i - 3; |
53 | 1.23M | s->size = 0; |
54 | 1.23M | break; |
55 | 1.23M | } |
56 | 33.2M | } |
57 | 1.33M | pc->state = state; |
58 | | |
59 | 1.33M | if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { |
60 | 102k | *poutbuf = NULL; |
61 | 102k | *poutbuf_size = 0; |
62 | 102k | return buf_size; |
63 | 102k | } |
64 | | |
65 | 1.23M | s1->duration = 1152; |
66 | 1.23M | s1->key_frame = 1; |
67 | | |
68 | 1.23M | *poutbuf = buf; |
69 | 1.23M | *poutbuf_size = buf_size; |
70 | | |
71 | 1.23M | return next; |
72 | 1.33M | } |
73 | | |
74 | | const FFCodecParser ff_ahx_parser = { |
75 | | PARSER_CODEC_LIST(AV_CODEC_ID_AHX), |
76 | | .priv_data_size = sizeof(AHXParseContext), |
77 | | .parse = ahx_parse, |
78 | | .close = ff_parse_close, |
79 | | }; |