00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #include "libavutil/intreadwrite.h"
00029 #include "parser.h"
00030 #include "adx.h"
00031
00032 typedef struct ADXParseContext {
00033 ParseContext pc;
00034 int header_size;
00035 int block_size;
00036 int remaining;
00037 } ADXParseContext;
00038
00039 static int adx_parse(AVCodecParserContext *s1,
00040 AVCodecContext *avctx,
00041 const uint8_t **poutbuf, int *poutbuf_size,
00042 const uint8_t *buf, int buf_size)
00043 {
00044 ADXParseContext *s = s1->priv_data;
00045 ParseContext *pc = &s->pc;
00046 int next = END_NOT_FOUND;
00047 int i;
00048 uint64_t state = pc->state64;
00049
00050 if (!s->header_size) {
00051 for (i = 0; i < buf_size; i++) {
00052 state = (state << 8) | buf[i];
00053
00054 if ((state & 0xFFFF0000FFFFFF00) == 0x8000000003120400ULL) {
00055 int channels = state & 0xFF;
00056 int header_size = ((state >> 32) & 0xFFFF) + 4;
00057 if (channels > 0 && header_size >= 8) {
00058 s->header_size = header_size;
00059 s->block_size = BLOCK_SIZE * channels;
00060 s->remaining = i - 7 + s->header_size + s->block_size;
00061 break;
00062 }
00063 }
00064 }
00065 pc->state64 = state;
00066 }
00067
00068 if (s->header_size) {
00069 if (!s->remaining)
00070 s->remaining = s->block_size;
00071 if (s->remaining <= buf_size) {
00072 next = s->remaining;
00073 s->remaining = 0;
00074 } else
00075 s->remaining -= buf_size;
00076 }
00077
00078 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
00079 *poutbuf = NULL;
00080 *poutbuf_size = 0;
00081 return buf_size;
00082 }
00083
00084 s1->duration = BLOCK_SAMPLES;
00085
00086 *poutbuf = buf;
00087 *poutbuf_size = buf_size;
00088 return next;
00089 }
00090
00091 AVCodecParser ff_adx_parser = {
00092 .codec_ids = { CODEC_ID_ADPCM_ADX },
00093 .priv_data_size = sizeof(ADXParseContext),
00094 .parser_parse = adx_parse,
00095 .parser_close = ff_parse_close,
00096 };