comparison vc1_parser.c @ 9732:c25359a56edf libavcodec

set pict_type in VC-1 parser, fix some timestamps problems
author bcoudurier
date Sat, 30 May 2009 00:09:00 +0000
parents 9a642761d734
children 7dd2a45249a9
comparison
equal deleted inserted replaced
9731:5b1b3c4a1f17 9732:c25359a56edf
25 * VC-1 and WMV3 parser 25 * VC-1 and WMV3 parser
26 */ 26 */
27 27
28 #include "parser.h" 28 #include "parser.h"
29 #include "vc1.h" 29 #include "vc1.h"
30 #include "get_bits.h"
31
32 typedef struct {
33 ParseContext pc;
34 VC1Context v;
35 } VC1ParseContext;
36
37 static void vc1_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx,
38 const uint8_t *buf, int buf_size)
39 {
40 VC1ParseContext *vpc = s->priv_data;
41 GetBitContext gb;
42 const uint8_t *start, *end, *next;
43 uint8_t *buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
44
45 vpc->v.s.avctx = avctx;
46 vpc->v.parse_only = 1;
47 next = buf;
48
49 for(start = buf, end = buf + buf_size; next < end; start = next){
50 int buf2_size, size;
51
52 next = find_next_marker(start + 4, end);
53 size = next - start - 4;
54 buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
55 init_get_bits(&gb, buf2, buf2_size * 8);
56 if(size <= 0) continue;
57 switch(AV_RB32(start)){
58 case VC1_CODE_SEQHDR:
59 vc1_decode_sequence_header(avctx, &vpc->v, &gb);
60 break;
61 case VC1_CODE_ENTRYPOINT:
62 vc1_decode_entry_point(avctx, &vpc->v, &gb);
63 break;
64 case VC1_CODE_FRAME:
65 if(vpc->v.profile < PROFILE_ADVANCED)
66 vc1_parse_frame_header (&vpc->v, &gb);
67 else
68 vc1_parse_frame_header_adv(&vpc->v, &gb);
69
70 /* keep FF_BI_TYPE internal to VC1 */
71 if (vpc->v.s.pict_type == FF_BI_TYPE)
72 s->pict_type = FF_B_TYPE;
73 else
74 s->pict_type = vpc->v.s.pict_type;
75
76 break;
77 }
78 }
79
80 av_free(buf2);
81 }
30 82
31 /** 83 /**
32 * finds the end of the current frame in the bitstream. 84 * finds the end of the current frame in the bitstream.
33 * @return the position of the first byte of the next frame, or -1 85 * @return the position of the first byte of the next frame, or -1
34 */ 86 */
73 static int vc1_parse(AVCodecParserContext *s, 125 static int vc1_parse(AVCodecParserContext *s,
74 AVCodecContext *avctx, 126 AVCodecContext *avctx,
75 const uint8_t **poutbuf, int *poutbuf_size, 127 const uint8_t **poutbuf, int *poutbuf_size,
76 const uint8_t *buf, int buf_size) 128 const uint8_t *buf, int buf_size)
77 { 129 {
78 ParseContext *pc = s->priv_data; 130 VC1ParseContext *vpc = s->priv_data;
79 int next; 131 int next;
80 132
81 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ 133 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
82 next= buf_size; 134 next= buf_size;
83 }else{ 135 }else{
84 next= vc1_find_frame_end(pc, buf, buf_size); 136 next= vc1_find_frame_end(&vpc->pc, buf, buf_size);
85 137
86 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { 138 if (ff_combine_frame(&vpc->pc, next, &buf, &buf_size) < 0) {
87 *poutbuf = NULL; 139 *poutbuf = NULL;
88 *poutbuf_size = 0; 140 *poutbuf_size = 0;
89 return buf_size; 141 return buf_size;
90 } 142 }
91 } 143 }
144
145 vc1_extract_headers(s, avctx, buf, buf_size);
146
92 *poutbuf = buf; 147 *poutbuf = buf;
93 *poutbuf_size = buf_size; 148 *poutbuf_size = buf_size;
94 return next; 149 return next;
95 } 150 }
96 151
114 return 0; 169 return 0;
115 } 170 }
116 171
117 AVCodecParser vc1_parser = { 172 AVCodecParser vc1_parser = {
118 { CODEC_ID_VC1 }, 173 { CODEC_ID_VC1 },
119 sizeof(ParseContext1), 174 sizeof(VC1ParseContext),
120 NULL, 175 NULL,
121 vc1_parse, 176 vc1_parse,
122 ff_parse1_close, 177 ff_parse1_close,
123 vc1_split, 178 vc1_split,
124 }; 179 };