00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #include "parser.h"
00029 #include "gsm.h"
00030
00031 typedef struct GSMParseContext {
00032 ParseContext pc;
00033 int block_size;
00034 int remaining;
00035 } GSMParseContext;
00036
00037 static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
00038 const uint8_t **poutbuf, int *poutbuf_size,
00039 const uint8_t *buf, int buf_size)
00040 {
00041 GSMParseContext *s = s1->priv_data;
00042 ParseContext *pc = &s->pc;
00043 int next;
00044
00045 if (!s->block_size) {
00046 switch (avctx->codec_id) {
00047 case CODEC_ID_GSM: s->block_size = GSM_BLOCK_SIZE; break;
00048 case CODEC_ID_GSM_MS: s->block_size = GSM_MS_BLOCK_SIZE; break;
00049 default:
00050 return AVERROR(EINVAL);
00051 }
00052 }
00053
00054 if (!s->remaining)
00055 s->remaining = s->block_size;
00056 if (s->remaining <= buf_size) {
00057 next = s->remaining;
00058 s->remaining = 0;
00059 } else {
00060 next = END_NOT_FOUND;
00061 s->remaining -= buf_size;
00062 }
00063
00064 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
00065 *poutbuf = NULL;
00066 *poutbuf_size = 0;
00067 return buf_size;
00068 }
00069 *poutbuf = buf;
00070 *poutbuf_size = buf_size;
00071 return next;
00072 }
00073
00074 AVCodecParser ff_gsm_parser = {
00075 .codec_ids = { CODEC_ID_GSM, CODEC_ID_GSM_MS },
00076 .priv_data_size = sizeof(GSMParseContext),
00077 .parser_parse = gsm_parse,
00078 .parser_close = ff_parse_close,
00079 };