00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "libavutil/bswap.h"
00028 #include "parser.h"
00029
00030 typedef struct BMPParseContext {
00031 ParseContext pc;
00032 uint32_t fsize;
00033 uint32_t remaining_size;
00034 } BMPParseContext;
00035
00036 static int bmp_parse(AVCodecParserContext *s, AVCodecContext *avctx,
00037 const uint8_t **poutbuf, int *poutbuf_size,
00038 const uint8_t *buf, int buf_size)
00039 {
00040 BMPParseContext *bpc = s->priv_data;
00041 uint64_t state = bpc->pc.state64;
00042 int next = END_NOT_FOUND;
00043 int i = 0;
00044
00045 s->pict_type = AV_PICTURE_TYPE_NONE;
00046
00047 *poutbuf_size = 0;
00048 if (buf_size == 0)
00049 return 0;
00050
00051 if (!bpc->pc.frame_start_found) {
00052 for (; i < buf_size; i++) {
00053 state = (state << 8) | buf[i];
00054 if ((state >> 48) == (('B' << 8) | 'M')) {
00055 bpc->fsize = av_bswap32(state >> 16);
00056 bpc->pc.frame_start_found = 1;
00057 if (bpc->fsize > buf_size - i + 7)
00058 bpc->remaining_size = bpc->fsize - buf_size + i - 7;
00059 else
00060 next = bpc->fsize + i - 7;
00061 break;
00062 }
00063 }
00064 bpc->pc.state64 = state;
00065 } else {
00066 if (bpc->remaining_size) {
00067 i = FFMIN(bpc->remaining_size, buf_size);
00068 bpc->remaining_size -= i;
00069 if (bpc->remaining_size)
00070 goto flush;
00071 next = i;
00072 }
00073 }
00074
00075 flush:
00076 if (ff_combine_frame(&bpc->pc, next, &buf, &buf_size) < 0)
00077 return buf_size;
00078
00079 bpc->pc.frame_start_found = 0;
00080
00081 *poutbuf = buf;
00082 *poutbuf_size = buf_size;
00083 return next;
00084 }
00085
00086 AVCodecParser ff_bmp_parser = {
00087 .codec_ids = { AV_CODEC_ID_BMP },
00088 .priv_data_size = sizeof(BMPParseContext),
00089 .parser_parse = bmp_parse,
00090 .parser_close = ff_parse_close,
00091 };