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 if((state&0xFFFF0000FFFFFF00) == 0x8000000003120400ULL && (state&0xFF) && ((state>>32)&0xFFFF)>=4){
00054 s->header_size= ((state>>32)&0xFFFF) + 4;
00055 s->block_size = BLOCK_SIZE * (state&0xFF);
00056 s->remaining = i - 7 + s->header_size + s->block_size;
00057 break;
00058 }
00059 }
00060 pc->state64= state;
00061 }
00062
00063 if (s->header_size) {
00064 if (!s->remaining) {
00065 s->remaining = s->block_size;
00066 }
00067 if (s->remaining<=buf_size) {
00068 next= s->remaining;
00069 s->remaining = 0;
00070 } else
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 *poutbuf = buf;
00080 *poutbuf_size = buf_size;
00081 return next;
00082 }
00083
00084 AVCodecParser ff_adx_parser = {
00085 .codec_ids = { CODEC_ID_ADPCM_ADX },
00086 .priv_data_size = sizeof(ADXParseContext),
00087 .parser_parse = adx_parse,
00088 .parser_close = ff_parse_close,
00089 };