FFmpeg
misc4_parser.c
Go to the documentation of this file.
1 /*
2  * Micronas SC-4 parser
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include "parser.h"
22 
23 typedef struct MISC4Context {
25 } MISC4Context;
26 
28  const uint8_t **poutbuf, int *poutbuf_size,
29  const uint8_t *buf, int buf_size)
30 {
31  MISC4Context *ctx = s->priv_data;
32  uint32_t state = ctx->pc.state;
33  int next = END_NOT_FOUND, i = 0;
34 
35  *poutbuf_size = 0;
36  *poutbuf = NULL;
37 
38  if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
39  next = buf_size;
40  } else {
41  uint32_t marker = 0;
42 
43  switch (avctx->sample_rate) {
44  case 8000:
45  case 11025:
46  marker = 0x11b;
47  break;
48  case 16000:
49  case 32000:
50  marker = 0x2b2;
51  break;
52  }
53 
54  for (; i < buf_size; i++) {
55  state = (state << 8) | buf[i];
56  if (state == marker && i > 3) {
57  next = i - 3;
58  break;
59  }
60  }
61 
62  ctx->pc.state = state;
63  if (ff_combine_frame(&ctx->pc, next, &buf, &buf_size) < 0) {
64  *poutbuf = NULL;
65  *poutbuf_size = 0;
66  return buf_size;
67  }
68  }
69 
70  *poutbuf = buf;
71  *poutbuf_size = buf_size;
72 
73  return next;
74 }
75 
78  .priv_data_size = sizeof(MISC4Context),
79  .parser_parse = misc4_parse,
80  .parser_close = ff_parse_close,
81 };
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1050
misc4_parse
static int misc4_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: misc4_parser.c:27
ff_parse_close
void ff_parse_close(AVCodecParserContext *s)
Definition: parser.c:289
AV_CODEC_ID_MISC4
@ AV_CODEC_ID_MISC4
Definition: codec_id.h:538
MISC4Context::pc
ParseContext pc
Definition: misc4_parser.c:24
ParseContext
Definition: parser.h:28
s
#define s(width, name)
Definition: cbs_vp9.c:198
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ff_misc4_parser
const AVCodecParser ff_misc4_parser
Definition: misc4_parser.c:76
NULL
#define NULL
Definition: coverity.c:32
state
static struct @385 state
AVCodecParser::codec_ids
int codec_ids[7]
Definition: avcodec.h:2867
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:203
PARSER_FLAG_COMPLETE_FRAMES
#define PARSER_FLAG_COMPLETE_FRAMES
Definition: avcodec.h:2741
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
parser.h
AVCodecParserContext
Definition: avcodec.h:2707
AVCodecContext
main external API structure.
Definition: avcodec.h:445
MISC4Context
Definition: misc4.c:48
END_NOT_FOUND
#define END_NOT_FOUND
Definition: parser.h:40
AVCodecParser
Definition: avcodec.h:2866