1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "mpeg2_bitstream_parser.h"
31 vlVdpMPEG2NextStartCode(struct vdpMPEG2BitstreamParser
*parser
)
34 uint32_t bytes_to_end
;
36 /* Move cursor to the start of a byte */
37 while(parser
->cursor
% 8)
40 bytes_to_end
= parser
->cur_bitstream_length
- parser
->cursor
/8 - 1;
42 /* Read byte after byte, until startcode is found */
43 while(integer
!= 0x00000100)
47 parser
->state
= MPEG2_HEADER_DONE
;
52 integer
= integer
& (unsigned char)(parser
->ptr_bitstream
+ parser
->cursor
/8)[0];
59 /* start_code found. rewind cursor a byte */
66 vlVdpMPEG2BitstreamToMacroblock (
67 struct pipe_screen
*screen
,
68 VdpBitstreamBuffer
const *bitstream_buffers
,
69 uint32_t bitstream_buffer_count
,
70 unsigned int *num_macroblocks
,
71 struct pipe_mpeg12_macroblock
**pipe_macroblocks
)
73 bool b_header_done
= false;
74 struct vdpMPEG2BitstreamParser parser
;
76 debug_printf("[VDPAU] Starting decoding MPEG2 stream");
78 num_macroblocks
[0] = 0;
80 memset(&parser
,0,sizeof(parser
));
81 parser
.state
= MPEG2_HEADER_START_CODE
;
82 parser
.cur_bitstream_length
= bitstream_buffers
[0].bitstream_bytes
;
83 parser
.ptr_bitstream
= (unsigned char *)bitstream_buffers
[0].bitstream
;
85 /* Main header parser loop */
90 case MPEG2_HEADER_START_CODE
:
91 if (vlVdpMPEG2NextStartCode(&parser
))
94 /* Start_code found */
95 switch ((parser
.ptr_bitstream
+ parser
.cursor
/8)[0])
97 /* sequence_header_code */
99 debug_printf("[VDPAU][Bitstream parser] Sequence header code found at cursor pos: %d\n", parser
.cursor
);
105 case MPEG2_HEADER_DONE
:
106 debug_printf("[VDPAU][Bitstream parser] Done parsing current header\n");