Libav 0.7.1
|
00001 /* 00002 * MJPEG parser 00003 * Copyright (c) 2000, 2001 Fabrice Bellard 00004 * Copyright (c) 2003 Alex Beregszaszi 00005 * Copyright (c) 2003-2004 Michael Niedermayer 00006 * 00007 * This file is part of Libav. 00008 * 00009 * Libav is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 * Libav is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with Libav; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 */ 00023 00029 #include "parser.h" 00030 00031 00036 static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ 00037 int vop_found, i; 00038 uint16_t state; 00039 00040 vop_found= pc->frame_start_found; 00041 state= pc->state; 00042 00043 i=0; 00044 if(!vop_found){ 00045 for(i=0; i<buf_size; i++){ 00046 state= (state<<8) | buf[i]; 00047 if(state == 0xFFD8){ 00048 i++; 00049 vop_found=1; 00050 break; 00051 } 00052 } 00053 } 00054 00055 if(vop_found){ 00056 /* EOF considered as end of frame */ 00057 if (buf_size == 0) 00058 return 0; 00059 for(; i<buf_size; i++){ 00060 state= (state<<8) | buf[i]; 00061 if(state == 0xFFD8){ 00062 pc->frame_start_found=0; 00063 pc->state=0; 00064 return i-1; 00065 } 00066 } 00067 } 00068 pc->frame_start_found= vop_found; 00069 pc->state= state; 00070 return END_NOT_FOUND; 00071 } 00072 00073 static int jpeg_parse(AVCodecParserContext *s, 00074 AVCodecContext *avctx, 00075 const uint8_t **poutbuf, int *poutbuf_size, 00076 const uint8_t *buf, int buf_size) 00077 { 00078 ParseContext *pc = s->priv_data; 00079 int next; 00080 00081 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ 00082 next= buf_size; 00083 }else{ 00084 next= find_frame_end(pc, buf, buf_size); 00085 00086 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { 00087 *poutbuf = NULL; 00088 *poutbuf_size = 0; 00089 return buf_size; 00090 } 00091 } 00092 00093 *poutbuf = buf; 00094 *poutbuf_size = buf_size; 00095 return next; 00096 } 00097 00098 00099 AVCodecParser ff_mjpeg_parser = { 00100 { CODEC_ID_MJPEG }, 00101 sizeof(ParseContext), 00102 NULL, 00103 jpeg_parse, 00104 ff_parse_close, 00105 };