FFmpeg
ahx_parser.c
Go to the documentation of this file.
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 
29 typedef struct AHXParseContext {
31  uint32_t header;
32  int size;
34 
36  AVCodecContext *avctx,
37  const uint8_t **poutbuf, int *poutbuf_size,
38  const uint8_t *buf, int buf_size)
39 {
41  ParseContext *pc = &s->pc;
42  uint32_t state = pc->state;
43  int next = END_NOT_FOUND;
44 
45  for (int i = 0; i < buf_size; i++) {
46  state = (state << 8) | buf[i];
47  s->size++;
48  if (s->size == 4 && !s->header)
49  s->header = state;
50  if (s->size > 4 && state == s->header) {
51  next = i - 3;
52  s->size = 0;
53  break;
54  }
55  }
56  pc->state = state;
57 
58  if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
59  *poutbuf = NULL;
60  *poutbuf_size = 0;
61  return buf_size;
62  }
63 
64  s1->duration = 1152;
65  s1->key_frame = 1;
66 
67  *poutbuf = buf;
68  *poutbuf_size = buf_size;
69 
70  return next;
71 }
72 
75  .priv_data_size = sizeof(AHXParseContext),
76  .parser_parse = ahx_parse,
77  .parser_close = ff_parse_close,
78 };
ff_parse_close
av_cold void ff_parse_close(AVCodecParserContext *s)
Definition: parser.c:291
AVCodecParserContext::duration
int duration
Duration of the current frame.
Definition: avcodec.h:2689
AHXParseContext::header
uint32_t header
Definition: ahx_parser.c:31
state
static struct @527 state
ParseContext::state
uint32_t state
contains the last few bytes in MSB order
Definition: parser.h:33
AVCodecParserContext::key_frame
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
Definition: avcodec.h:2624
ParseContext
Definition: parser.h:28
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
NULL
#define NULL
Definition: coverity.c:32
AHXParseContext::size
int size
Definition: ahx_parser.c:32
ff_ahx_parser
const AVCodecParser ff_ahx_parser
Definition: ahx_parser.c:73
AVCodecParser::codec_ids
int codec_ids[7]
Definition: avcodec.h:2735
ff_combine_frame
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
Definition: parser.c:204
AHXParseContext::pc
ParseContext pc
Definition: ahx_parser.c:30
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ahx_parse
static int ahx_parse(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: ahx_parser.c:35
AV_CODEC_ID_AHX
@ AV_CODEC_ID_AHX
Definition: codec_id.h:567
parser.h
AVCodecParserContext
Definition: avcodec.h:2575
AVCodecContext
main external API structure.
Definition: avcodec.h:431
AHXParseContext
Definition: ahx_parser.c:29
END_NOT_FOUND
#define END_NOT_FOUND
Definition: parser.h:40
AVCodecParser
Definition: avcodec.h:2734
AVCodecParserContext::priv_data
void * priv_data
Definition: avcodec.h:2576