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 duration;
00035 int remaining;
00036 } GSMParseContext;
00037
00038 static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
00039 const uint8_t **poutbuf, int *poutbuf_size,
00040 const uint8_t *buf, int buf_size)
00041 {
00042 GSMParseContext *s = s1->priv_data;
00043 ParseContext *pc = &s->pc;
00044 int next;
00045
00046 if (!s->block_size) {
00047 switch (avctx->codec_id) {
00048 case CODEC_ID_GSM:
00049 s->block_size = GSM_BLOCK_SIZE;
00050 s->duration = GSM_FRAME_SIZE;
00051 break;
00052 case CODEC_ID_GSM_MS:
00053 s->block_size = GSM_MS_BLOCK_SIZE;
00054 s->duration = GSM_FRAME_SIZE * 2;
00055 break;
00056 default:
00057 return AVERROR(EINVAL);
00058 }
00059 }
00060
00061 if (!s->remaining)
00062 s->remaining = s->block_size;
00063 if (s->remaining <= buf_size) {
00064 next = s->remaining;
00065 s->remaining = 0;
00066 } else {
00067 next = END_NOT_FOUND;
00068 s->remaining -= buf_size;
00069 }
00070
00071 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
00072 *poutbuf = NULL;
00073 *poutbuf_size = 0;
00074 return buf_size;
00075 }
00076
00077 s1->duration = s->duration;
00078
00079 *poutbuf = buf;
00080 *poutbuf_size = buf_size;
00081 return next;
00082 }
00083
00084 AVCodecParser ff_gsm_parser = {
00085 .codec_ids = { CODEC_ID_GSM, CODEC_ID_GSM_MS },
00086 .priv_data_size = sizeof(GSMParseContext),
00087 .parser_parse = gsm_parse,
00088 .parser_close = ff_parse_close,
00089 };