3 * Copyright (c) 2006-2007 Konstantin Shishkov
4 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * VC-1 and WMV3 parser
29 #define VC1_PARSER_ONLY
33 * finds the end of the current frame in the bitstream.
34 * @return the position of the first byte of the next frame, or -1
36 static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf,
41 pic_found= pc->frame_start_found;
46 for(i=0; i<buf_size; i++){
47 state= (state<<8) | buf[i];
48 if(state == VC1_CODE_FRAME || state == VC1_CODE_FIELD){
57 /* EOF considered as end of frame */
60 for(; i<buf_size; i++){
61 state= (state<<8) | buf[i];
62 if(IS_MARKER(state) && state != VC1_CODE_FIELD && state != VC1_CODE_SLICE){
63 pc->frame_start_found=0;
69 pc->frame_start_found= pic_found;
74 static int vc1_parse(AVCodecParserContext *s,
75 AVCodecContext *avctx,
76 uint8_t **poutbuf, int *poutbuf_size,
77 const uint8_t *buf, int buf_size)
79 ParseContext *pc = s->priv_data;
82 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
85 next= vc1_find_frame_end(pc, buf, buf_size);
87 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
93 *poutbuf = (uint8_t *)buf;
94 *poutbuf_size = buf_size;
98 static int vc1_split(AVCodecContext *avctx,
99 const uint8_t *buf, int buf_size)
104 for(i=0; i<buf_size; i++){
105 state= (state<<8) | buf[i];
106 if(IS_MARKER(state) && state != VC1_CODE_SEQHDR && state != VC1_CODE_ENTRYPOINT)
112 AVCodecParser vc1_parser = {
114 sizeof(ParseContext1),