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 AV_CODEC_ID_GSM:
00049 s->block_size = GSM_BLOCK_SIZE;
00050 s->duration = GSM_FRAME_SIZE;
00051 break;
00052 case AV_CODEC_ID_GSM_MS:
00053 s->block_size = GSM_MS_BLOCK_SIZE;
00054 s->duration = GSM_FRAME_SIZE * 2;
00055 break;
00056 default:
00057 *poutbuf = buf;
00058 *poutbuf_size = buf_size;
00059 av_log(avctx, AV_LOG_ERROR, "Invalid codec_id\n");
00060 return buf_size;
00061 }
00062 }
00063
00064 if (!s->remaining)
00065 s->remaining = s->block_size;
00066 if (s->remaining <= buf_size) {
00067 next = s->remaining;
00068 s->remaining = 0;
00069 } else {
00070 next = END_NOT_FOUND;
00071 s->remaining -= buf_size;
00072 }
00073
00074 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
00075 *poutbuf = NULL;
00076 *poutbuf_size = 0;
00077 return buf_size;
00078 }
00079
00080 s1->duration = s->duration;
00081
00082 *poutbuf = buf;
00083 *poutbuf_size = buf_size;
00084 return next;
00085 }
00086
00087 AVCodecParser ff_gsm_parser = {
00088 .codec_ids = { AV_CODEC_ID_GSM, AV_CODEC_ID_GSM_MS },
00089 .priv_data_size = sizeof(GSMParseContext),
00090 .parser_parse = gsm_parse,
00091 .parser_close = ff_parse_close,
00092 };