annotate ffmpeg/libavcodec/bmp_parser.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * BMP parser
yading@10 3 * Copyright (c) 2012 Paul B Mahol
yading@10 4 *
yading@10 5 * This file is part of FFmpeg.
yading@10 6 *
yading@10 7 * FFmpeg is free software; you can redistribute it and/or
yading@10 8 * modify it under the terms of the GNU Lesser General Public
yading@10 9 * License as published by the Free Software Foundation; either
yading@10 10 * version 2.1 of the License, or (at your option) any later version.
yading@10 11 *
yading@10 12 * FFmpeg is distributed in the hope that it will be useful,
yading@10 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 15 * Lesser General Public License for more details.
yading@10 16 *
yading@10 17 * You should have received a copy of the GNU Lesser General Public
yading@10 18 * License along with FFmpeg; if not, write to the Free Software
yading@10 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 20 */
yading@10 21
yading@10 22 /**
yading@10 23 * @file
yading@10 24 * BMP parser
yading@10 25 */
yading@10 26
yading@10 27 #include "libavutil/bswap.h"
yading@10 28 #include "parser.h"
yading@10 29
yading@10 30 typedef struct BMPParseContext {
yading@10 31 ParseContext pc;
yading@10 32 uint32_t fsize;
yading@10 33 uint32_t remaining_size;
yading@10 34 } BMPParseContext;
yading@10 35
yading@10 36 static int bmp_parse(AVCodecParserContext *s, AVCodecContext *avctx,
yading@10 37 const uint8_t **poutbuf, int *poutbuf_size,
yading@10 38 const uint8_t *buf, int buf_size)
yading@10 39 {
yading@10 40 BMPParseContext *bpc = s->priv_data;
yading@10 41 uint64_t state = bpc->pc.state64;
yading@10 42 int next = END_NOT_FOUND;
yading@10 43 int i = 0;
yading@10 44
yading@10 45 s->pict_type = AV_PICTURE_TYPE_NONE;
yading@10 46
yading@10 47 *poutbuf_size = 0;
yading@10 48 if (buf_size == 0)
yading@10 49 return 0;
yading@10 50
yading@10 51 if (!bpc->pc.frame_start_found) {
yading@10 52 for (; i < buf_size; i++) {
yading@10 53 state = (state << 8) | buf[i];
yading@10 54 if ((state >> 48) == (('B' << 8) | 'M')) {
yading@10 55 bpc->fsize = av_bswap32(state >> 16);
yading@10 56 bpc->pc.frame_start_found = 1;
yading@10 57 if (bpc->fsize > buf_size - i + 7)
yading@10 58 bpc->remaining_size = bpc->fsize - buf_size + i - 7;
yading@10 59 else
yading@10 60 next = bpc->fsize + i - 7;
yading@10 61 break;
yading@10 62 }
yading@10 63 }
yading@10 64 bpc->pc.state64 = state;
yading@10 65 } else {
yading@10 66 if (bpc->remaining_size) {
yading@10 67 i = FFMIN(bpc->remaining_size, buf_size);
yading@10 68 bpc->remaining_size -= i;
yading@10 69 if (bpc->remaining_size)
yading@10 70 goto flush;
yading@10 71 next = i;
yading@10 72 }
yading@10 73 }
yading@10 74
yading@10 75 flush:
yading@10 76 if (ff_combine_frame(&bpc->pc, next, &buf, &buf_size) < 0)
yading@10 77 return buf_size;
yading@10 78
yading@10 79 bpc->pc.frame_start_found = 0;
yading@10 80
yading@10 81 *poutbuf = buf;
yading@10 82 *poutbuf_size = buf_size;
yading@10 83 return next;
yading@10 84 }
yading@10 85
yading@10 86 AVCodecParser ff_bmp_parser = {
yading@10 87 .codec_ids = { AV_CODEC_ID_BMP },
yading@10 88 .priv_data_size = sizeof(BMPParseContext),
yading@10 89 .parser_parse = bmp_parse,
yading@10 90 .parser_close = ff_parse_close,
yading@10 91 };