yading@10
|
1 /*
|
yading@10
|
2 * Chinese AVS video (AVS1-P2, JiZhun profile) parser.
|
yading@10
|
3 * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
|
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 * Chinese AVS video (AVS1-P2, JiZhun profile) parser
|
yading@10
|
25 * @author Stefan Gehrer <stefan.gehrer@gmx.de>
|
yading@10
|
26 */
|
yading@10
|
27
|
yading@10
|
28 #include "parser.h"
|
yading@10
|
29 #include "cavs.h"
|
yading@10
|
30
|
yading@10
|
31
|
yading@10
|
32 /**
|
yading@10
|
33 * Find the end of the current frame in the bitstream.
|
yading@10
|
34 * @return the position of the first byte of the next frame, or -1
|
yading@10
|
35 */
|
yading@10
|
36 static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf,
|
yading@10
|
37 int buf_size) {
|
yading@10
|
38 int pic_found, i;
|
yading@10
|
39 uint32_t state;
|
yading@10
|
40
|
yading@10
|
41 pic_found= pc->frame_start_found;
|
yading@10
|
42 state= pc->state;
|
yading@10
|
43
|
yading@10
|
44 i=0;
|
yading@10
|
45 if(!pic_found){
|
yading@10
|
46 for(i=0; i<buf_size; i++){
|
yading@10
|
47 state= (state<<8) | buf[i];
|
yading@10
|
48 if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){
|
yading@10
|
49 i++;
|
yading@10
|
50 pic_found=1;
|
yading@10
|
51 break;
|
yading@10
|
52 }
|
yading@10
|
53 }
|
yading@10
|
54 }
|
yading@10
|
55
|
yading@10
|
56 if(pic_found){
|
yading@10
|
57 /* EOF considered as end of frame */
|
yading@10
|
58 if (buf_size == 0)
|
yading@10
|
59 return 0;
|
yading@10
|
60 for(; i<buf_size; i++){
|
yading@10
|
61 state= (state<<8) | buf[i];
|
yading@10
|
62 if((state&0xFFFFFF00) == 0x100){
|
yading@10
|
63 if(state > SLICE_MAX_START_CODE){
|
yading@10
|
64 pc->frame_start_found=0;
|
yading@10
|
65 pc->state=-1;
|
yading@10
|
66 return i-3;
|
yading@10
|
67 }
|
yading@10
|
68 }
|
yading@10
|
69 }
|
yading@10
|
70 }
|
yading@10
|
71 pc->frame_start_found= pic_found;
|
yading@10
|
72 pc->state= state;
|
yading@10
|
73 return END_NOT_FOUND;
|
yading@10
|
74 }
|
yading@10
|
75
|
yading@10
|
76 static int cavsvideo_parse(AVCodecParserContext *s,
|
yading@10
|
77 AVCodecContext *avctx,
|
yading@10
|
78 const uint8_t **poutbuf, int *poutbuf_size,
|
yading@10
|
79 const uint8_t *buf, int buf_size)
|
yading@10
|
80 {
|
yading@10
|
81 ParseContext *pc = s->priv_data;
|
yading@10
|
82 int next;
|
yading@10
|
83
|
yading@10
|
84 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
|
yading@10
|
85 next= buf_size;
|
yading@10
|
86 }else{
|
yading@10
|
87 next= cavs_find_frame_end(pc, buf, buf_size);
|
yading@10
|
88
|
yading@10
|
89 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
|
yading@10
|
90 *poutbuf = NULL;
|
yading@10
|
91 *poutbuf_size = 0;
|
yading@10
|
92 return buf_size;
|
yading@10
|
93 }
|
yading@10
|
94 }
|
yading@10
|
95 *poutbuf = buf;
|
yading@10
|
96 *poutbuf_size = buf_size;
|
yading@10
|
97 return next;
|
yading@10
|
98 }
|
yading@10
|
99
|
yading@10
|
100 AVCodecParser ff_cavsvideo_parser = {
|
yading@10
|
101 .codec_ids = { AV_CODEC_ID_CAVS },
|
yading@10
|
102 .priv_data_size = sizeof(ParseContext),
|
yading@10
|
103 .parser_parse = cavsvideo_parse,
|
yading@10
|
104 .parser_close = ff_parse_close,
|
yading@10
|
105 .split = ff_mpeg4video_split,
|
yading@10
|
106 };
|