comparison vc1.c @ 4900:36051a4c182a libavcodec

Move VC1 parser to its own file.
author diego
date Fri, 04 May 2007 00:09:33 +0000
parents 6a1e340119df
children 1296fd337cdf
comparison
equal deleted inserted replaced
4899:e153b9ff47d3 4900:36051a4c182a
30 #include "dsputil.h" 30 #include "dsputil.h"
31 #include "avcodec.h" 31 #include "avcodec.h"
32 #include "mpegvideo.h" 32 #include "mpegvideo.h"
33 #include "vc1data.h" 33 #include "vc1data.h"
34 #include "vc1acdata.h" 34 #include "vc1acdata.h"
35 #include "vc1.h"
35 36
36 #undef NDEBUG 37 #undef NDEBUG
37 #include <assert.h> 38 #include <assert.h>
38 39
39 extern const uint32_t ff_table0_dc_lum[120][2], ff_table1_dc_lum[120][2]; 40 extern const uint32_t ff_table0_dc_lum[120][2], ff_table1_dc_lum[120][2];
43 extern VLC ff_msmp4_mb_i_vlc; 44 extern VLC ff_msmp4_mb_i_vlc;
44 extern const uint16_t ff_msmp4_mb_i_table[64][2]; 45 extern const uint16_t ff_msmp4_mb_i_table[64][2];
45 #define DC_VLC_BITS 9 46 #define DC_VLC_BITS 9
46 #define AC_VLC_BITS 9 47 #define AC_VLC_BITS 9
47 static const uint16_t table_mb_intra[64][2]; 48 static const uint16_t table_mb_intra[64][2];
48
49 /** Markers used if VC-1 AP frame data */
50 //@{
51 enum VC1Code{
52 VC1_CODE_RES0 = 0x00000100,
53 VC1_CODE_ENDOFSEQ = 0x0000010A,
54 VC1_CODE_SLICE,
55 VC1_CODE_FIELD,
56 VC1_CODE_FRAME,
57 VC1_CODE_ENTRYPOINT,
58 VC1_CODE_SEQHDR,
59 };
60 //@}
61 49
62 /** Available Profiles */ 50 /** Available Profiles */
63 //@{ 51 //@{
64 enum Profile { 52 enum Profile {
65 PROFILE_SIMPLE, 53 PROFILE_SIMPLE,
4171 vc1_decode_b_blocks(v); 4159 vc1_decode_b_blocks(v);
4172 break; 4160 break;
4173 } 4161 }
4174 } 4162 }
4175 4163
4176 #define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
4177
4178 /** Find VC-1 marker in buffer 4164 /** Find VC-1 marker in buffer
4179 * @return position where next marker starts or end of buffer if no marker found 4165 * @return position where next marker starts or end of buffer if no marker found
4180 */ 4166 */
4181 static av_always_inline uint8_t* find_next_marker(uint8_t *src, uint8_t *end) 4167 static av_always_inline uint8_t* find_next_marker(uint8_t *src, uint8_t *end)
4182 { 4168 {
4539 vc1_decode_end, 4525 vc1_decode_end,
4540 vc1_decode_frame, 4526 vc1_decode_frame,
4541 CODEC_CAP_DELAY, 4527 CODEC_CAP_DELAY,
4542 NULL 4528 NULL
4543 }; 4529 };
4544
4545 #ifdef CONFIG_VC1_PARSER
4546 /**
4547 * finds the end of the current frame in the bitstream.
4548 * @return the position of the first byte of the next frame, or -1
4549 */
4550 static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf,
4551 int buf_size) {
4552 int pic_found, i;
4553 uint32_t state;
4554
4555 pic_found= pc->frame_start_found;
4556 state= pc->state;
4557
4558 i=0;
4559 if(!pic_found){
4560 for(i=0; i<buf_size; i++){
4561 state= (state<<8) | buf[i];
4562 if(state == VC1_CODE_FRAME || state == VC1_CODE_FIELD){
4563 i++;
4564 pic_found=1;
4565 break;
4566 }
4567 }
4568 }
4569
4570 if(pic_found){
4571 /* EOF considered as end of frame */
4572 if (buf_size == 0)
4573 return 0;
4574 for(; i<buf_size; i++){
4575 state= (state<<8) | buf[i];
4576 if(IS_MARKER(state) && state != VC1_CODE_FIELD && state != VC1_CODE_SLICE){
4577 pc->frame_start_found=0;
4578 pc->state=-1;
4579 return i-3;
4580 }
4581 }
4582 }
4583 pc->frame_start_found= pic_found;
4584 pc->state= state;
4585 return END_NOT_FOUND;
4586 }
4587
4588 static int vc1_parse(AVCodecParserContext *s,
4589 AVCodecContext *avctx,
4590 uint8_t **poutbuf, int *poutbuf_size,
4591 const uint8_t *buf, int buf_size)
4592 {
4593 ParseContext *pc = s->priv_data;
4594 int next;
4595
4596 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
4597 next= buf_size;
4598 }else{
4599 next= vc1_find_frame_end(pc, buf, buf_size);
4600
4601 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
4602 *poutbuf = NULL;
4603 *poutbuf_size = 0;
4604 return buf_size;
4605 }
4606 }
4607 *poutbuf = (uint8_t *)buf;
4608 *poutbuf_size = buf_size;
4609 return next;
4610 }
4611
4612 static int vc1_split(AVCodecContext *avctx,
4613 const uint8_t *buf, int buf_size)
4614 {
4615 int i;
4616 uint32_t state= -1;
4617
4618 for(i=0; i<buf_size; i++){
4619 state= (state<<8) | buf[i];
4620 if(IS_MARKER(state) && state != VC1_CODE_SEQHDR && state != VC1_CODE_ENTRYPOINT)
4621 return i-3;
4622 }
4623 return 0;
4624 }
4625
4626 AVCodecParser vc1_parser = {
4627 { CODEC_ID_VC1 },
4628 sizeof(ParseContext1),
4629 NULL,
4630 vc1_parse,
4631 ff_parse1_close,
4632 vc1_split,
4633 };
4634 #endif /* CONFIG_VC1_PARSER */