2007-05-09 03:03:17 +03:00
|
|
|
/*
|
|
|
|
* Chinese AVS video (AVS1-P2, JiZhun profile) parser.
|
|
|
|
* Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
|
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* This file is part of Libav.
|
2007-05-09 03:03:17 +03:00
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2007-05-09 03:03:17 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2007-05-09 03:03:17 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 19:35:10 +02:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2007-07-05 13:40:25 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-05-09 03:03:17 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2007-05-09 03:03:17 +03:00
|
|
|
* Chinese AVS video (AVS1-P2, JiZhun profile) parser
|
|
|
|
* @author Stefan Gehrer <stefan.gehrer@gmx.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "parser.h"
|
|
|
|
#include "cavs.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-12-07 15:03:53 +03:00
|
|
|
* Find the end of the current frame in the bitstream.
|
2007-05-09 03:03:17 +03:00
|
|
|
* @return the position of the first byte of the next frame, or -1
|
|
|
|
*/
|
|
|
|
static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf,
|
|
|
|
int buf_size) {
|
|
|
|
int pic_found, i;
|
|
|
|
uint32_t state;
|
|
|
|
|
|
|
|
pic_found= pc->frame_start_found;
|
|
|
|
state= pc->state;
|
|
|
|
|
|
|
|
i=0;
|
|
|
|
if(!pic_found){
|
|
|
|
for(i=0; i<buf_size; i++){
|
|
|
|
state= (state<<8) | buf[i];
|
|
|
|
if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){
|
|
|
|
i++;
|
|
|
|
pic_found=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pic_found){
|
|
|
|
/* EOF considered as end of frame */
|
|
|
|
if (buf_size == 0)
|
|
|
|
return 0;
|
|
|
|
for(; i<buf_size; i++){
|
|
|
|
state= (state<<8) | buf[i];
|
|
|
|
if((state&0xFFFFFF00) == 0x100){
|
2009-02-10 18:34:45 +02:00
|
|
|
if(state > SLICE_MAX_START_CODE){
|
2007-05-09 03:03:17 +03:00
|
|
|
pc->frame_start_found=0;
|
|
|
|
pc->state=-1;
|
|
|
|
return i-3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pc->frame_start_found= pic_found;
|
|
|
|
pc->state= state;
|
|
|
|
return END_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cavsvideo_parse(AVCodecParserContext *s,
|
|
|
|
AVCodecContext *avctx,
|
|
|
|
const uint8_t **poutbuf, int *poutbuf_size,
|
|
|
|
const uint8_t *buf, int buf_size)
|
|
|
|
{
|
|
|
|
ParseContext *pc = s->priv_data;
|
|
|
|
int next;
|
|
|
|
|
|
|
|
if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
|
|
|
|
next= buf_size;
|
|
|
|
}else{
|
|
|
|
next= cavs_find_frame_end(pc, buf, buf_size);
|
|
|
|
|
|
|
|
if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
|
|
|
|
*poutbuf = NULL;
|
|
|
|
*poutbuf_size = 0;
|
|
|
|
return buf_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*poutbuf = buf;
|
|
|
|
*poutbuf_size = buf_size;
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
2011-01-25 23:40:11 +02:00
|
|
|
AVCodecParser ff_cavsvideo_parser = {
|
2011-11-02 11:34:41 +03:00
|
|
|
.codec_ids = { CODEC_ID_CAVS },
|
2012-02-09 01:46:48 +03:00
|
|
|
.priv_data_size = sizeof(ParseContext),
|
2011-11-02 11:34:41 +03:00
|
|
|
.parser_parse = cavsvideo_parse,
|
2012-02-09 01:46:48 +03:00
|
|
|
.parser_close = ff_parse_close,
|
2011-11-02 11:34:41 +03:00
|
|
|
.split = ff_mpeg4video_split,
|
2007-05-09 03:03:17 +03:00
|
|
|
};
|