00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "parser.h"
00030
00031 #define DIRAC_PARSE_INFO_PREFIX 0x42424344
00032
00033
00034
00035
00036
00037 static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
00038 {
00039 uint32_t state = pc->state;
00040 int i;
00041
00042 for (i = 0; i < buf_size; i++) {
00043 state = (state << 8) | buf[i];
00044 if (state == DIRAC_PARSE_INFO_PREFIX) {
00045 pc->frame_start_found ^= 1;
00046 if (!pc->frame_start_found) {
00047 pc->state = -1;
00048 return i - 3;
00049 }
00050 }
00051 }
00052
00053 pc->state = state;
00054
00055 return END_NOT_FOUND;
00056 }
00057
00058 static int dirac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
00059 const uint8_t **poutbuf, int *poutbuf_size,
00060 const uint8_t *buf, int buf_size)
00061 {
00062 ParseContext *pc = s->priv_data;
00063 int next;
00064
00065 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
00066 next = buf_size;
00067 }else{
00068 next = find_frame_end(pc, buf, buf_size);
00069
00070 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
00071 *poutbuf = NULL;
00072 *poutbuf_size = 0;
00073 return buf_size;
00074 }
00075 }
00076
00077 *poutbuf = buf;
00078 *poutbuf_size = buf_size;
00079 return next;
00080 }
00081
00082 AVCodecParser dirac_parser = {
00083 { CODEC_ID_DIRAC },
00084 sizeof(ParseContext),
00085 NULL,
00086 dirac_parse,
00087 ff_parse_close,
00088 };