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