2 * copyright (c) 2008 Paul Kendall <paul@kcbbs.gen.nz>
4 * This file is part of FFmpeg.
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.
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.
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
29 #define LATM_HEADER 0x56e000 // 0x2b7 (11 bits)
30 #define LATM_MASK 0xFFE000 // top 11 bits
31 #define LATM_SIZE_MASK 0x001FFF // bottom 13 bits
33 typedef struct LATMParseContext{
39 * finds the end of the current frame in the bitstream.
40 * @return the position of the first byte of the next frame, or -1
42 static int latm_find_frame_end(AVCodecParserContext *s1, const uint8_t *buf,
45 LATMParseContext *s = s1->priv_data;
46 ParseContext *pc = &s->pc;
50 pic_found = pc->frame_start_found;
55 for (i = 0; i < buf_size; i++) {
56 state = (state<<8) | buf[i];
57 if ((state & LATM_MASK) == LATM_HEADER) {
67 /* EOF considered as end of frame */
70 if ((state & LATM_SIZE_MASK) - s->count <= buf_size) {
71 pc->frame_start_found = 0;
73 return (state & LATM_SIZE_MASK) - s->count;
78 pc->frame_start_found = pic_found;
84 static int latm_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
85 const uint8_t **poutbuf, int *poutbuf_size,
86 const uint8_t *buf, int buf_size)
88 LATMParseContext *s = s1->priv_data;
89 ParseContext *pc = &s->pc;
92 if (s1->flags & PARSER_FLAG_COMPLETE_FRAMES) {
95 next = latm_find_frame_end(s1, buf, buf_size);
97 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
104 *poutbuf_size = buf_size;
108 AVCodecParser ff_aac_latm_parser = {
109 { CODEC_ID_AAC_LATM },
110 sizeof(LATMParseContext),