• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/vc1_parser.c

Go to the documentation of this file.
00001 /*
00002  * VC-1 and WMV3 parser
00003  * Copyright (c) 2006-2007 Konstantin Shishkov
00004  * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00028 #include "parser.h"
00029 #include "vc1.h"
00030 
00035 static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf,
00036                                int buf_size) {
00037     int pic_found, i;
00038     uint32_t state;
00039 
00040     pic_found= pc->frame_start_found;
00041     state= pc->state;
00042 
00043     i=0;
00044     if(!pic_found){
00045         for(i=0; i<buf_size; i++){
00046             state= (state<<8) | buf[i];
00047             if(state == VC1_CODE_FRAME || state == VC1_CODE_FIELD){
00048                 i++;
00049                 pic_found=1;
00050                 break;
00051             }
00052         }
00053     }
00054 
00055     if(pic_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(IS_MARKER(state) && state != VC1_CODE_FIELD && state != VC1_CODE_SLICE){
00062                 pc->frame_start_found=0;
00063                 pc->state=-1;
00064                 return i-3;
00065             }
00066         }
00067     }
00068     pc->frame_start_found= pic_found;
00069     pc->state= state;
00070     return END_NOT_FOUND;
00071 }
00072 
00073 static int vc1_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= vc1_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     *poutbuf = buf;
00093     *poutbuf_size = buf_size;
00094     return next;
00095 }
00096 
00097 static int vc1_split(AVCodecContext *avctx,
00098                            const uint8_t *buf, int buf_size)
00099 {
00100     int i;
00101     uint32_t state= -1;
00102     int charged=0;
00103 
00104     for(i=0; i<buf_size; i++){
00105         state= (state<<8) | buf[i];
00106         if(IS_MARKER(state)){
00107             if(state == VC1_CODE_SEQHDR || state == VC1_CODE_ENTRYPOINT){
00108                 charged=1;
00109             }else if(charged){
00110                 return i-3;
00111             }
00112         }
00113     }
00114     return 0;
00115 }
00116 
00117 AVCodecParser vc1_parser = {
00118     { CODEC_ID_VC1 },
00119     sizeof(ParseContext1),
00120     NULL,
00121     vc1_parse,
00122     ff_parse1_close,
00123     vc1_split,
00124 };

Generated on Sat Feb 16 2013 09:23:14 for ffmpeg by  doxygen 1.7.1