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 #include "parser_internal.h"
29 
30 typedef struct AHXParseContext {
32  uint32_t header;
33  int size;
35 
37  AVCodecContext *avctx,
38  const uint8_t **poutbuf, int *poutbuf_size,
39  const uint8_t *buf, int buf_size)
40 {
42  ParseContext *pc = &s->pc;
43  uint32_t state = pc->state;
44  int next = END_NOT_FOUND;
45 
46  for (int i = 0; i < buf_size; i++) {
47  state = (state << 8) | buf[i];
48  s->size++;
49  if (s->size == 4 && !s->header)
50  s->header = state;
51  if (s->size > 4 && state == s->header) {
52  next = i - 3;
53  s->size = 0;
54  break;
55  }
56  }
57  pc->state = state;
58 
59  if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
60  *poutbuf = NULL;
61  *poutbuf_size = 0;
62  return buf_size;
63  }
64 
65  s1->duration = 1152;
66  s1->key_frame = 1;
67 
68  *poutbuf = buf;
69  *poutbuf_size = buf_size;
70 
71  return next;
72 }
73 
76  .priv_data_size = sizeof(AHXParseContext),
77  .parse = ahx_parse,
79 };
ff_ahx_parser
const FFCodecParser ff_ahx_parser
Definition: ahx_parser.c:74
ff_parse_close
av_cold void ff_parse_close(AVCodecParserContext *s)
Definition: parser.c:298
AVCodecParserContext::duration
int duration
Duration of the current frame.
Definition: avcodec.h:2689
parser_internal.h
AHXParseContext::header
uint32_t header
Definition: ahx_parser.c:32
ParseContext::state
uint32_t state
contains the last few bytes in MSB order
Definition: parser.h:33
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:136
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:33
state
static struct @541 state
parse
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: apv_parser.c:46
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:211
FFCodecParser
Definition: parser_internal.h:29
AHXParseContext::pc
ParseContext pc
Definition: ahx_parser.c:31
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:36
AV_CODEC_ID_AHX
@ AV_CODEC_ID_AHX
Definition: codec_id.h:567
parser.h
PARSER_CODEC_LIST
#define PARSER_CODEC_LIST(...)
Definition: parser_internal.h:76
AVCodecParserContext
Definition: avcodec.h:2575
AVCodecContext
main external API structure.
Definition: avcodec.h:431
AHXParseContext
Definition: ahx_parser.c:30
END_NOT_FOUND
#define END_NOT_FOUND
Definition: parser.h:40
AVCodecParserContext::priv_data
void * priv_data
Definition: avcodec.h:2576