yading@10
|
1 /*
|
yading@10
|
2 * Copyright (c) 2012 Justin Ruggles
|
yading@10
|
3 *
|
yading@10
|
4 * This file is part of Libav.
|
yading@10
|
5 *
|
yading@10
|
6 * Libav is free software; you can redistribute it and/or
|
yading@10
|
7 * modify it under the terms of the GNU Lesser General Public
|
yading@10
|
8 * License as published by the Free Software Foundation; either
|
yading@10
|
9 * version 2.1 of the License, or (at your option) any later version.
|
yading@10
|
10 *
|
yading@10
|
11 * Libav is distributed in the hope that it will be useful,
|
yading@10
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@10
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@10
|
14 * Lesser General Public License for more details.
|
yading@10
|
15 *
|
yading@10
|
16 * You should have received a copy of the GNU Lesser General Public
|
yading@10
|
17 * License along with Libav; if not, write to the Free Software
|
yading@10
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@10
|
19 */
|
yading@10
|
20
|
yading@10
|
21 /**
|
yading@10
|
22 * @file
|
yading@10
|
23 * GSM audio parser
|
yading@10
|
24 *
|
yading@10
|
25 * Splits packets into individual blocks.
|
yading@10
|
26 */
|
yading@10
|
27
|
yading@10
|
28 #include "parser.h"
|
yading@10
|
29 #include "gsm.h"
|
yading@10
|
30
|
yading@10
|
31 typedef struct GSMParseContext {
|
yading@10
|
32 ParseContext pc;
|
yading@10
|
33 int block_size;
|
yading@10
|
34 int duration;
|
yading@10
|
35 int remaining;
|
yading@10
|
36 } GSMParseContext;
|
yading@10
|
37
|
yading@10
|
38 static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
|
yading@10
|
39 const uint8_t **poutbuf, int *poutbuf_size,
|
yading@10
|
40 const uint8_t *buf, int buf_size)
|
yading@10
|
41 {
|
yading@10
|
42 GSMParseContext *s = s1->priv_data;
|
yading@10
|
43 ParseContext *pc = &s->pc;
|
yading@10
|
44 int next;
|
yading@10
|
45
|
yading@10
|
46 if (!s->block_size) {
|
yading@10
|
47 switch (avctx->codec_id) {
|
yading@10
|
48 case AV_CODEC_ID_GSM:
|
yading@10
|
49 s->block_size = GSM_BLOCK_SIZE;
|
yading@10
|
50 s->duration = GSM_FRAME_SIZE;
|
yading@10
|
51 break;
|
yading@10
|
52 case AV_CODEC_ID_GSM_MS:
|
yading@10
|
53 s->block_size = GSM_MS_BLOCK_SIZE;
|
yading@10
|
54 s->duration = GSM_FRAME_SIZE * 2;
|
yading@10
|
55 break;
|
yading@10
|
56 default:
|
yading@10
|
57 *poutbuf = buf;
|
yading@10
|
58 *poutbuf_size = buf_size;
|
yading@10
|
59 av_log(avctx, AV_LOG_ERROR, "Invalid codec_id\n");
|
yading@10
|
60 return buf_size;
|
yading@10
|
61 }
|
yading@10
|
62 }
|
yading@10
|
63
|
yading@10
|
64 if (!s->remaining)
|
yading@10
|
65 s->remaining = s->block_size;
|
yading@10
|
66 if (s->remaining <= buf_size) {
|
yading@10
|
67 next = s->remaining;
|
yading@10
|
68 s->remaining = 0;
|
yading@10
|
69 } else {
|
yading@10
|
70 next = END_NOT_FOUND;
|
yading@10
|
71 s->remaining -= buf_size;
|
yading@10
|
72 }
|
yading@10
|
73
|
yading@10
|
74 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
|
yading@10
|
75 *poutbuf = NULL;
|
yading@10
|
76 *poutbuf_size = 0;
|
yading@10
|
77 return buf_size;
|
yading@10
|
78 }
|
yading@10
|
79
|
yading@10
|
80 s1->duration = s->duration;
|
yading@10
|
81
|
yading@10
|
82 *poutbuf = buf;
|
yading@10
|
83 *poutbuf_size = buf_size;
|
yading@10
|
84 return next;
|
yading@10
|
85 }
|
yading@10
|
86
|
yading@10
|
87 AVCodecParser ff_gsm_parser = {
|
yading@10
|
88 .codec_ids = { AV_CODEC_ID_GSM, AV_CODEC_ID_GSM_MS },
|
yading@10
|
89 .priv_data_size = sizeof(GSMParseContext),
|
yading@10
|
90 .parser_parse = gsm_parse,
|
yading@10
|
91 .parser_close = ff_parse_close,
|
yading@10
|
92 };
|