summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libvdpau/bits_reader.h36
-rw-r--r--src/libvdpau/vdpau_mpeg12.c226
-rw-r--r--src/libvdpau/vdpau_vc1.c197
3 files changed, 260 insertions, 199 deletions
diff --git a/src/libvdpau/bits_reader.h b/src/libvdpau/bits_reader.h
new file mode 100644
index 000000000..9563c9d3b
--- /dev/null
+++ b/src/libvdpau/bits_reader.h
@@ -0,0 +1,36 @@
+#include <sys/types.h>
+
+
+
+typedef struct {
+ uint8_t *buffer;
+ int offbits;
+} bits_reader_t;
+
+static void bits_reader_set( bits_reader_t *br, uint8_t *buf )
+{
+ br->buffer = buf;
+ br->offbits = 0;
+}
+
+static uint32_t read_bits( bits_reader_t *br, int nbits )
+{
+ int i, nbytes;
+ uint32_t ret = 0;
+ uint8_t *buf;
+
+ buf = br->buffer;
+ nbytes = (br->offbits + nbits)/8;
+ if ( ((br->offbits + nbits) %8 ) > 0 )
+ nbytes++;
+ for ( i=0; i<nbytes; i++ )
+ ret += buf[i]<<((nbytes-i-1)*8);
+ i = (4-nbytes)*8+br->offbits;
+ ret = ((ret<<i)>>i)>>((nbytes*8)-nbits-br->offbits);
+
+ br->offbits += nbits;
+ br->buffer += br->offbits / 8;
+ br->offbits %= 8;
+
+ return ret;
+}
diff --git a/src/libvdpau/vdpau_mpeg12.c b/src/libvdpau/vdpau_mpeg12.c
index be912b22a..4ef1f5c30 100644
--- a/src/libvdpau/vdpau_mpeg12.c
+++ b/src/libvdpau/vdpau_mpeg12.c
@@ -37,6 +37,7 @@
#include "buffer.h"
#include "xineutils.h"
#include "accel_vdpau.h"
+#include "bits_reader.h"
#include <vdpau/vdpau.h>
@@ -67,6 +68,12 @@
#define WANT_EXT 2
#define WANT_SLICE 3
+/*#define MAKE_DAT*/ /*do NOT define this, unless you know what you do */
+#ifdef MAKE_DAT
+static int nframes;
+static FILE *outfile;
+#endif
+
/* default intra quant matrix, in zig-zag order */
@@ -141,6 +148,8 @@ typedef struct {
vdpau_accel_t *accel_vdpau;
+ bits_reader_t br;
+
int vdp_runtime_nr;
} sequence_t;
@@ -236,50 +245,32 @@ static void free_sequence( sequence_t *sequence )
-static uint32_t get_bits( uint8_t *b, int offbits, int nbits )
-{
- int i, nbytes;
- uint32_t ret = 0;
- uint8_t *buf;
-
- buf = b+(offbits/8);
- offbits %=8;
- nbytes = (offbits+nbits)/8;
- if ( ((offbits+nbits)%8)>0 )
- nbytes++;
- for ( i=0; i<nbytes; i++ )
- ret += buf[i]<<((nbytes-i-1)*8);
- i = (4-nbytes)*8+offbits;
- ret = ((ret<<i)>>i)>>((nbytes*8)-nbits-offbits);
-
- return ret;
-}
-
-
-
static void sequence_header( vdpau_mpeg12_decoder_t *this_gen, uint8_t *buf, int len )
{
sequence_t *sequence = (sequence_t*)&this_gen->sequence;
- int i, j, off=0;
+ int i, j;
if ( sequence->cur_pts ) {
sequence->seq_pts = sequence->cur_pts;
}
- sequence->coded_width = get_bits( buf,0,12 );
- lprintf( "coded_width: %d\n", get_bits( buf,0,12 ) );
- sequence->coded_height = get_bits( buf,12,12 );
- lprintf( "coded_height: %d\n", get_bits( buf,12,12 ) );
- switch ( get_bits( buf+3,0,4 ) ) {
+ bits_reader_set( &sequence->br, buf );
+ sequence->coded_width = read_bits( &sequence->br, 12 );
+ lprintf( "coded_width: %d\n", sequence->coded_width );
+ sequence->coded_height = read_bits( &sequence->br, 12 );
+ lprintf( "coded_height: %d\n", sequence->coded_height );
+ int rt = read_bits( &sequence->br, 4 );
+ switch ( rt ) {
case 1: sequence->ratio = 1.0; break;
case 2: sequence->ratio = 4.0/3.0; break;
case 3: sequence->ratio = 16.0/9.0; break;
case 4: sequence->ratio = 2.21; break;
default: sequence->ratio = (double)sequence->coded_width/(double)sequence->coded_height;
}
- lprintf( "ratio: %d\n", get_bits( buf+3,0,4 ) );
- switch ( get_bits( buf+3,4,4 ) ) {
+ lprintf( "ratio: %d\n", rt );
+ int fr = read_bits( &sequence->br, 4 );
+ switch ( fr ) {
case 1: sequence->video_step = 3913; break; /* 23.976.. */
case 2: sequence->video_step = 3750; break; /* 24 */
case 3: sequence->video_step = 3600; break; /* 25 */
@@ -289,18 +280,22 @@ static void sequence_header( vdpau_mpeg12_decoder_t *this_gen, uint8_t *buf, int
case 7: sequence->video_step = 1525; break; /* 59.94.. */
case 8: sequence->video_step = 1509; break; /* 60 */
}
- lprintf( "frame_rate: %d\n", get_bits( buf+3,4,4 ) );
- lprintf( "bit_rate_value: %d\n", get_bits( buf+4,0,18 ) );
- lprintf( "marker_bit: %d\n", get_bits( buf+6,2,1 ) );
- lprintf( "vbv_buffer_size_value: %d\n", get_bits( buf+6,3,10 ) );
- lprintf( "constrained_parameters_flag: %d\n", get_bits( buf+7,5,1 ) );
- i = get_bits( buf+7,6,1 );
+ lprintf( "frame_rate: %d\n", fr );
+ int tmp;
+ tmp = read_bits( &sequence->br, 18 );
+ lprintf( "bit_rate_value: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 1 );
+ lprintf( "marker_bit: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 10 );
+ lprintf( "vbv_buffer_size_value: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 1 );
+ lprintf( "constrained_parameters_flag: %d\n", tmp );
+ i = read_bits( &sequence->br, 1 );
lprintf( "load_intra_quantizer_matrix: %d\n", i );
if ( i ) {
for ( j=0; j<64; ++j ) {
- sequence->picture.vdp_infos2.intra_quantizer_matrix[mpeg2_scan_norm[j]] = sequence->picture.vdp_infos.intra_quantizer_matrix[mpeg2_scan_norm[j]] = get_bits( buf+7+j,7,8 );
+ sequence->picture.vdp_infos2.intra_quantizer_matrix[mpeg2_scan_norm[j]] = sequence->picture.vdp_infos.intra_quantizer_matrix[mpeg2_scan_norm[j]] = read_bits( &sequence->br, 8 );
}
- off = 64;
}
else {
for ( j=0; j<64; ++j ) {
@@ -308,11 +303,11 @@ static void sequence_header( vdpau_mpeg12_decoder_t *this_gen, uint8_t *buf, int
}
}
- i = get_bits( buf+7+off,7,1 );
+ i = read_bits( &sequence->br, 1 );
lprintf( "load_non_intra_quantizer_matrix: %d\n", i );
if ( i ) {
for ( j=0; j<64; ++j ) {
- sequence->picture.vdp_infos2.non_intra_quantizer_matrix[mpeg2_scan_norm[j]] = sequence->picture.vdp_infos.non_intra_quantizer_matrix[mpeg2_scan_norm[j]] = get_bits( buf+8+off+j,0,8 );
+ sequence->picture.vdp_infos2.non_intra_quantizer_matrix[mpeg2_scan_norm[j]] = sequence->picture.vdp_infos.non_intra_quantizer_matrix[mpeg2_scan_norm[j]] = read_bits( &sequence->br, 8 );
}
}
else {
@@ -366,17 +361,20 @@ static void picture_header( sequence_t *sequence, uint8_t *buf, int len )
infos = &sequence->picture.vdp_infos2;
}
- lprintf( "temporal_reference: %d\n", get_bits( buf,0,10 ) );
- infos->picture_coding_type = get_bits( buf,10,3 );
- lprintf( "picture_coding_type: %d\n", get_bits( buf,10,3 ) );
+ bits_reader_set( &sequence->br, buf );
+ int tmp = read_bits( &sequence->br, 10 );
+ lprintf( "temporal_reference: %d\n", tmp );
+ infos->picture_coding_type = read_bits( &sequence->br, 3 );
+ lprintf( "picture_coding_type: %d\n", infos->picture_coding_type );
infos->forward_reference = VDP_INVALID_HANDLE;
infos->backward_reference = VDP_INVALID_HANDLE;
+ read_bits( &sequence->br, 16 );
if ( infos->picture_coding_type > I_FRAME ) {
- infos->full_pel_forward_vector = get_bits( buf+2,13,1 );
- infos->f_code[0][0] = infos->f_code[0][1] = get_bits( buf+2,14,3 );
+ infos->full_pel_forward_vector = read_bits( &sequence->br, 1 );
+ infos->f_code[0][0] = infos->f_code[0][1] = read_bits( &sequence->br, 3 );
if ( infos->picture_coding_type==B_FRAME ) {
- infos->full_pel_backward_vector = get_bits( buf+2,17,1 );
- infos->f_code[1][0] = infos->f_code[1][1] = get_bits( buf+2,18,3 );
+ infos->full_pel_backward_vector = read_bits( &sequence->br, 1 );
+ infos->f_code[1][0] = infos->f_code[1][1] = read_bits( &sequence->br, 3 );
}
}
else {
@@ -393,24 +391,35 @@ static void picture_header( sequence_t *sequence, uint8_t *buf, int len )
static void sequence_extension( sequence_t *sequence, uint8_t *buf, int len )
{
- lprintf( "extension_start_code_identifier: %d\n", get_bits( buf,0,4 ) );
- switch ( get_bits( buf,5,3 ) ) {
+ bits_reader_set( &sequence->br, buf );
+ int tmp = read_bits( &sequence->br, 4 );
+ lprintf( "extension_start_code_identifier: %d\n", tmp );
+ read_bits( &sequence->br, 1 );
+ switch ( read_bits( &sequence->br, 3 ) ) {
case 5: sequence->profile = VDP_DECODER_PROFILE_MPEG2_SIMPLE; break;
default: sequence->profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
}
- lprintf( "profile_and_level_indication: %d\n", get_bits( buf,4,8 ) );
- lprintf( "progressive_sequence: %d\n", get_bits( buf,12,1 ) );
- if ( get_bits( buf,13,2 )==2 )
+ read_bits( &sequence->br, 4 );
+ tmp = read_bits( &sequence->br, 1 );
+ lprintf( "progressive_sequence: %d\n", tmp );
+ if ( read_bits( &sequence->br, 2 ) == 2 )
sequence->chroma = VO_CHROMA_422;
- lprintf( "chroma_format: %d\n", get_bits( buf,13,2 ) );
- lprintf( "horizontal_size_extension: %d\n", get_bits( buf,15,2 ) );
- lprintf( "vertical_size_extension: %d\n", get_bits( buf,17,2 ) );
- lprintf( "bit_rate_extension: %d\n", get_bits( buf,19,12 ) );
- lprintf( "marker_bit: %d\n", get_bits( buf,31,1 ) );
- lprintf( "vbv_buffer_size_extension: %d\n", get_bits( buf+4,0,8 ) );
- lprintf( "low_delay: %d\n", get_bits( buf+5,0,1 ) );
- lprintf( "frame_rate_extension_n: %d\n", get_bits( buf+5,1,2 ) );
- lprintf( "frame_rate_extension_d: %d\n", get_bits( buf+5,3,5 ) );
+ tmp = read_bits( &sequence->br, 2 );
+ lprintf( "horizontal_size_extension: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 2 );
+ lprintf( "vertical_size_extension: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 12 );
+ lprintf( "bit_rate_extension: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 1 );
+ lprintf( "marker_bit: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 8 );
+ lprintf( "vbv_buffer_size_extension: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 1 );
+ lprintf( "low_delay: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 2 );
+ lprintf( "frame_rate_extension_n: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 5 );
+ lprintf( "frame_rate_extension_d: %d\n", tmp );
}
@@ -424,35 +433,39 @@ static void picture_coding_extension( sequence_t *sequence, uint8_t *buf, int le
if ( infos->picture_structure && infos->picture_structure!=PICTURE_FRAME )
infos = &sequence->picture.vdp_infos2;
- infos->f_code[0][0] = get_bits( buf,4,4 );
- infos->f_code[0][1] = get_bits( buf,8,4 );
- infos->f_code[1][0] = get_bits( buf,12,4 );
- infos->f_code[1][1] = get_bits( buf,16,4 );
- lprintf( "extension_start_code_identifier: %d\n", get_bits( buf,0,4 ) );
- lprintf( "f_code_0_0: %d\n", get_bits( buf,4,4 ) );
- lprintf( "f_code_0_1: %d\n", get_bits( buf,8,4 ) );
- lprintf( "f_code_1_0: %d\n", get_bits( buf,12,4 ) );
- lprintf( "f_code_1_1: %d\n", get_bits( buf,16,4 ) );
- infos->intra_dc_precision = get_bits( buf,20,2 );
- lprintf( "intra_dc_precision: %d\n", get_bits( buf,20,2 ) );
- infos->picture_structure = get_bits( buf,22,2 );
- lprintf( "picture_structure: %d\n", get_bits( buf,22,2 ) );
- infos->top_field_first = get_bits( buf,24,1 );
- lprintf( "top_field_first: %d\n", get_bits( buf,24,1 ) );
- infos->frame_pred_frame_dct = get_bits( buf,25,1 );
- lprintf( "frame_pred_frame_dct: %d\n", get_bits( buf,25,1 ) );
- infos->concealment_motion_vectors = get_bits( buf,26,1 );
- lprintf( "concealment_motion_vectors: %d\n", get_bits( buf,26,1 ) );
- infos->q_scale_type = get_bits( buf,27,1 );
- lprintf( "q_scale_type: %d\n", get_bits( buf,27,1 ) );
- infos->intra_vlc_format = get_bits( buf,28,1 );
- lprintf( "intra_vlc_format: %d\n", get_bits( buf,28,1 ) );
- infos->alternate_scan = get_bits( buf,29,1 );
- lprintf( "alternate_scan: %d\n", get_bits( buf,29,1 ) );
- lprintf( "repeat_first_field: %d\n", get_bits( buf,30,1 ) );
- lprintf( "chroma_420_type: %d\n", get_bits( buf,31,1 ) );
- sequence->picture.progressive_frame = get_bits( buf,32,1 );
- lprintf( "progressive_frame: %d\n", get_bits( buf,32,1 ) );
+ bits_reader_set( &sequence->br, buf );
+ int tmp = read_bits( &sequence->br, 4 );
+ lprintf( "extension_start_code_identifier: %d\n", tmp );
+ infos->f_code[0][0] = read_bits( &sequence->br, 4 );
+ infos->f_code[0][1] = read_bits( &sequence->br, 4 );
+ infos->f_code[1][0] = read_bits( &sequence->br, 4 );
+ infos->f_code[1][1] = read_bits( &sequence->br, 4 );
+ lprintf( "f_code_0_0: %d\n", infos->f_code[0][0] );
+ lprintf( "f_code_0_1: %d\n", infos->f_code[0][1] );
+ lprintf( "f_code_1_0: %d\n", infos->f_code[1][0] );
+ lprintf( "f_code_1_1: %d\n", infos->f_code[1][1] );
+ infos->intra_dc_precision = read_bits( &sequence->br, 2 );
+ lprintf( "intra_dc_precision: %d\n", infos->intra_dc_precision );
+ infos->picture_structure = read_bits( &sequence->br, 2 );
+ lprintf( "picture_structure: %d\n", infos->picture_structure );
+ infos->top_field_first = read_bits( &sequence->br, 1 );
+ lprintf( "top_field_first: %d\n", infos->top_field_first );
+ infos->frame_pred_frame_dct = read_bits( &sequence->br, 1 );
+ lprintf( "frame_pred_frame_dct: %d\n", infos->frame_pred_frame_dct );
+ infos->concealment_motion_vectors = read_bits( &sequence->br, 1 );
+ lprintf( "concealment_motion_vectors: %d\n", infos->concealment_motion_vectors );
+ infos->q_scale_type = read_bits( &sequence->br, 1 );
+ lprintf( "q_scale_type: %d\n", infos->q_scale_type );
+ infos->intra_vlc_format = read_bits( &sequence->br, 1 );
+ lprintf( "intra_vlc_format: %d\n", infos->intra_vlc_format );
+ infos->alternate_scan = read_bits( &sequence->br, 1 );
+ lprintf( "alternate_scan: %d\n", infos->alternate_scan );
+ tmp = read_bits( &sequence->br, 1 );
+ lprintf( "repeat_first_field: %d\n", tmp );
+ tmp = read_bits( &sequence->br, 1 );
+ lprintf( "chroma_420_type: %d\n", tmp );
+ sequence->picture.progressive_frame = read_bits( &sequence->br, 1 );
+ lprintf( "progressive_frame: %d\n", sequence->picture.progressive_frame );
sequence->picture.state = WANT_SLICE;
}
@@ -460,15 +473,16 @@ static void picture_coding_extension( sequence_t *sequence, uint8_t *buf, int le
static void quant_matrix_extension( sequence_t *sequence, uint8_t *buf, int len )
{
- int i, j, off=0;
+ int i, j;
- i = get_bits( buf,4,1 );
+ bits_reader_set( &sequence->br, buf );
+ read_bits( &sequence->br, 4 );
+ i = read_bits( &sequence->br, 1 );
lprintf( "load_intra_quantizer_matrix: %d\n", i );
if ( i ) {
for ( j=0; j<64; ++j ) {
- sequence->picture.vdp_infos2.intra_quantizer_matrix[mpeg2_scan_norm[j]] = sequence->picture.vdp_infos.intra_quantizer_matrix[mpeg2_scan_norm[j]] = get_bits( buf+j,5,8 );
+ sequence->picture.vdp_infos2.intra_quantizer_matrix[mpeg2_scan_norm[j]] = sequence->picture.vdp_infos.intra_quantizer_matrix[mpeg2_scan_norm[j]] = read_bits( &sequence->br, 8 );
}
- off = 64;
}
else {
for ( j=0; j<64; ++j ) {
@@ -476,11 +490,11 @@ static void quant_matrix_extension( sequence_t *sequence, uint8_t *buf, int len
}
}
- i = get_bits( buf+off,5,1 );
+ i = read_bits( &sequence->br, 1 );
lprintf( "load_non_intra_quantizer_matrix: %d\n", i );
if ( i ) {
for ( j=0; j<64; ++j ) {
- sequence->picture.vdp_infos2.non_intra_quantizer_matrix[mpeg2_scan_norm[j]] = sequence->picture.vdp_infos.non_intra_quantizer_matrix[mpeg2_scan_norm[j]] = get_bits( buf+off+j,6,8 );
+ sequence->picture.vdp_infos2.non_intra_quantizer_matrix[mpeg2_scan_norm[j]] = sequence->picture.vdp_infos.non_intra_quantizer_matrix[mpeg2_scan_norm[j]] = read_bits( &sequence->br, 8 );
}
}
else {
@@ -537,7 +551,7 @@ static int parse_code( vdpau_mpeg12_decoder_t *this_gen, uint8_t *buf, int len )
sequence_header( this_gen, buf+4, len-4 );
break;
case extension_start_code: {
- switch ( get_bits( buf+4,0,4 ) ) {
+ switch ( buf[4]>>4 ) {
case sequence_ext_sc:
lprintf( " ----------- sequence_extension_start_code\n" );
sequence_extension( sequence, buf+4, len-4 );
@@ -703,6 +717,21 @@ static void decode_picture( vdpau_mpeg12_decoder_t *vd )
decode_render( vd, accel );
+#ifdef MAKE_DAT
+ if ( nframes==0 ) {
+ fwrite( &seq->coded_width, 1, sizeof(seq->coded_width), outfile );
+ fwrite( &seq->coded_height, 1, sizeof(seq->coded_height), outfile );
+ fwrite( &seq->ratio, 1, sizeof(seq->ratio), outfile );
+ fwrite( &seq->profile, 1, sizeof(seq->profile), outfile );
+ }
+
+ if ( nframes++ < 25 ) {
+ fwrite( &pic->vdp_infos, 1, sizeof(pic->vdp_infos), outfile );
+ fwrite( &pic->slices_pos, 1, sizeof(pic->slices_pos), outfile );
+ fwrite( pic->slices, 1, pic->slices_pos, outfile );
+ }
+#endif
+
img->drawn = 0;
img->pts = seq->seq_pts;
seq->seq_pts = 0; /* reset */
@@ -905,6 +934,11 @@ static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stre
(stream->video_out->open)(stream->video_out, stream);
+#ifdef MAKE_DAT
+ outfile = fopen( "/tmp/mpg.dat","w");
+ nframes = 0;
+#endif
+
return &this->video_decoder;
}
diff --git a/src/libvdpau/vdpau_vc1.c b/src/libvdpau/vdpau_vc1.c
index 67a453870..2ccc7e6b9 100644
--- a/src/libvdpau/vdpau_vc1.c
+++ b/src/libvdpau/vdpau_vc1.c
@@ -37,6 +37,7 @@
#include "buffer.h"
#include "xineutils.h"
#include "accel_vdpau.h"
+#include "bits_reader.h"
#include <vdpau/vdpau.h>
@@ -137,6 +138,8 @@ typedef struct {
vdpau_accel_t *accel_vdpau;
+ bits_reader_t br;
+
int vdp_runtime_nr;
} sequence_t;
@@ -212,7 +215,7 @@ static void init_sequence( sequence_t *sequence )
-static uint32_t get_bits( uint8_t *b, int offbits, int nbits )
+/*static uint32_t get_bits( uint8_t *b, int offbits, int nbits )
{
int i, nbytes;
uint32_t ret = 0;
@@ -229,7 +232,7 @@ static uint32_t get_bits( uint8_t *b, int offbits, int nbits )
ret = ((ret<<i)>>i)>>((nbytes*8)-nbits-offbits);
return ret;
-}
+}*/
@@ -269,35 +272,29 @@ static void sequence_header_advanced( vdpau_vc1_decoder_t *this_gen, uint8_t *bu
sequence->profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
lprintf("VDP_DECODER_PROFILE_VC1_ADVANCED\n");
- int off = 15;
- sequence->picture.vdp_infos.postprocflag = get_bits(buf,off++,1);
- sequence->coded_width = (get_bits(buf,off,12)+1)<<1;
- off += 12;
- sequence->coded_height = (get_bits(buf,off,12)+1)<<1;
- off += 12;
- sequence->picture.vdp_infos.pulldown = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.interlace = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.tfcntrflag = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.finterpflag = get_bits(buf,off++,1);
- ++off;
- sequence->picture.vdp_infos.psf = get_bits(buf,off++,1);
+ bits_reader_set( &sequence->br, buf );
+ read_bits( &sequence->br, 15 );
+ sequence->picture.vdp_infos.postprocflag = read_bits( &sequence->br, 1 );
+ sequence->coded_width = read_bits( &sequence->br, 12 )<<1;
+ sequence->coded_height = (read_bits( &sequence->br, 12 )+1)<<1;
+ sequence->picture.vdp_infos.pulldown = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.interlace = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.tfcntrflag = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.finterpflag = read_bits( &sequence->br, 1 );
+ read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.psf = read_bits( &sequence->br, 1 );
sequence->picture.vdp_infos.maxbframes = 7;
- if ( get_bits(buf,off++,1) ) {
+ if ( read_bits( &sequence->br, 1 ) ) {
double w, h;
int ar=0;
- w = get_bits(buf,off,14)+1;
- off += 14;
- h = get_bits(buf,off,14)+1;
- off += 14;
- if ( get_bits(buf,off++,1) ) {
- ar = get_bits(buf,off,4);
- off += 4;
+ w = read_bits( &sequence->br, 14 )+1;
+ h = read_bits( &sequence->br, 14 )+1;
+ if ( read_bits( &sequence->br, 1 ) ) {
+ ar = read_bits( &sequence->br, 4 );
}
if ( ar==15 ) {
- w = get_bits(buf,off,8);
- off += 8;
- h = get_bits(buf,off,8);
- off += 8;
+ w = read_bits( &sequence->br, 8 );
+ h = read_bits( &sequence->br, 8 );
sequence->ratio = w/h;
lprintf("aspect_ratio (w/h) = %f\n", sequence->ratio);
}
@@ -306,14 +303,13 @@ static void sequence_header_advanced( vdpau_vc1_decoder_t *this_gen, uint8_t *bu
lprintf("aspect_ratio = %f\n", sequence->ratio);
}
- if ( get_bits(buf,off++,1) ) {
- if ( get_bits(buf,off++,1) ) {
- int exp = get_bits(buf,off,16);
+ if ( read_bits( &sequence->br, 1 ) ) {
+ if ( read_bits( &sequence->br, 1 ) ) {
+ int exp = read_bits( &sequence->br, 16 );
lprintf("framerate exp = %d\n", exp);
- off += 16;
}
else {
- double nr = get_bits(buf,off,8);
+ double nr = read_bits( &sequence->br, 8 );
switch ((int)nr) {
case 1: nr = 24000; break;
case 2: nr = 25000; break;
@@ -322,25 +318,23 @@ static void sequence_header_advanced( vdpau_vc1_decoder_t *this_gen, uint8_t *bu
case 5: nr = 60000; break;
default: nr = 0;
}
- off += 8;
- double dr = get_bits(buf,off,4);
+ double dr = read_bits( &sequence->br, 4 );
switch ((int)dr) {
case 2: dr = 1001; break;
default: dr = 1000;
}
- off += 4;
sequence->video_step = 90000/(nr/dr);
lprintf("framerate = %f video_step = %d\n", nr/dr, sequence->video_step);
}
}
- if ( get_bits(buf,off++,1) ) {
- lprintf("color_standard = %d\n", get_bits(buf,off,8));
- off += 24;
+ if ( read_bits( &sequence->br, 1 ) ) {
+ lprintf("color_standard = %d\n", read_bits( &sequence->br, 8 ));
+ read_bits( &sequence->br, 16 );
}
}
- sequence->picture.hrd_param_flag = get_bits(buf,off++,1);
+ sequence->picture.hrd_param_flag = read_bits( &sequence->br, 1 );
if ( sequence->picture.hrd_param_flag )
- sequence->picture.hrd_num_leaky_buckets = get_bits(buf,off,5);
+ sequence->picture.hrd_num_leaky_buckets = read_bits( &sequence->br, 5 );
update_metadata( this_gen );
}
@@ -355,26 +349,30 @@ static void sequence_header( vdpau_vc1_decoder_t *this_gen, uint8_t *buf, int le
if ( len < 4 )
return;
- switch ( get_bits(buf,0,2) ) {
+ bits_reader_set( &sequence->br, buf );
+ switch ( read_bits( &sequence->br, 2 ) ) {
case 0: sequence->profile = VDP_DECODER_PROFILE_VC1_SIMPLE; lprintf("VDP_DECODER_PROFILE_VC1_SIMPLE\n"); break;
case 1: sequence->profile = VDP_DECODER_PROFILE_VC1_MAIN; lprintf("VDP_DECODER_PROFILE_VC1_MAIN\n"); break;
case 2: sequence->profile = VDP_DECODER_PROFILE_VC1_MAIN; lprintf("vc1_complex profile not supported by vdpau, trying vc1_main.\n"); break;
case 3: return sequence_header_advanced( this_gen, buf, len ); break;
default: return; /* illegal value, broken header? */
}
-
- sequence->picture.vdp_infos.loopfilter = get_bits(buf,12,1);
- sequence->picture.vdp_infos.multires = get_bits(buf,14,1);
- sequence->picture.vdp_infos.fastuvmc = get_bits(buf,16,1);
- sequence->picture.vdp_infos.extended_mv = get_bits(buf,17,1);
- sequence->picture.vdp_infos.dquant = get_bits(buf,18,2);
- sequence->picture.vdp_infos.vstransform = get_bits(buf,20,1);
- sequence->picture.vdp_infos.overlap = get_bits(buf,22,1);
- sequence->picture.vdp_infos.syncmarker = get_bits(buf,23,1);
- sequence->picture.vdp_infos.rangered = get_bits(buf,24,1);
- sequence->picture.vdp_infos.maxbframes = get_bits(buf,25,3);
- sequence->picture.vdp_infos.quantizer = get_bits(buf,28,2);
- sequence->picture.vdp_infos.finterpflag = get_bits(buf,30,1);
+ read_bits( &sequence->br, 10 );
+ sequence->picture.vdp_infos.loopfilter = read_bits( &sequence->br, 1 );
+ read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.multires = read_bits( &sequence->br, 1 );
+ read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.fastuvmc = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.extended_mv = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.dquant = read_bits( &sequence->br, 2 );
+ sequence->picture.vdp_infos.vstransform = read_bits( &sequence->br, 1 );
+ read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.overlap = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.syncmarker = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.rangered = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.maxbframes = read_bits( &sequence->br, 3 );
+ sequence->picture.vdp_infos.quantizer = read_bits( &sequence->br, 2 );
+ sequence->picture.vdp_infos.finterpflag = read_bits( &sequence->br, 1 );
update_metadata( this_gen );
}
@@ -385,45 +383,40 @@ static void entry_point( vdpau_vc1_decoder_t *this_gen, uint8_t *buf, int len )
{
lprintf( "entry_point\n" );
sequence_t *sequence = (sequence_t*)&this_gen->sequence;
- int off=2;
-
- sequence->picture.vdp_infos.panscan_flag = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.refdist_flag = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.loopfilter = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.fastuvmc = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.extended_mv = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.dquant = get_bits(buf,off,2);
- off += 2;
- sequence->picture.vdp_infos.vstransform = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.overlap = get_bits(buf,off++,1);
- sequence->picture.vdp_infos.quantizer = get_bits(buf,off,2);
- off += 2;
+
+ bits_reader_set( &sequence->br, buf );
+ read_bits( &sequence->br, 2 );
+ sequence->picture.vdp_infos.panscan_flag = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.refdist_flag = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.loopfilter = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.fastuvmc = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.extended_mv = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.dquant = read_bits( &sequence->br, 2 );
+ sequence->picture.vdp_infos.vstransform = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.overlap = read_bits( &sequence->br, 1 );
+ sequence->picture.vdp_infos.quantizer = read_bits( &sequence->br, 2 );
if ( sequence->picture.hrd_param_flag ) {
int i;
for ( i=0; i<sequence->picture.hrd_num_leaky_buckets; ++i )
- off += 8;
+ read_bits( &sequence->br, 8 );
}
- if ( get_bits(buf,off++,1) ) {
- sequence->coded_width = (get_bits(buf,off,12)+1)<<1;
- off += 12;
- sequence->coded_height = (get_bits(buf,off,12)+1)<<1;
- off += 12;
+ if ( read_bits( &sequence->br, 1 ) ) {
+ sequence->coded_width = (read_bits( &sequence->br, 12 )+1)<<1;
+ sequence->coded_height = (read_bits( &sequence->br, 12 )+1)<<1;
}
if ( sequence->picture.vdp_infos.extended_mv )
- sequence->picture.vdp_infos.extended_dmv = get_bits(buf,off++,1);
+ sequence->picture.vdp_infos.extended_dmv = read_bits( &sequence->br, 1 );
- sequence->picture.vdp_infos.range_mapy_flag = get_bits(buf,off++,1);
+ sequence->picture.vdp_infos.range_mapy_flag = read_bits( &sequence->br, 1 );
if ( sequence->picture.vdp_infos.range_mapy_flag ) {
- sequence->picture.vdp_infos.range_mapy = get_bits(buf,off,3);
- off += 3;
+ sequence->picture.vdp_infos.range_mapy = read_bits( &sequence->br, 3 );
}
- sequence->picture.vdp_infos.range_mapuv_flag = get_bits(buf,off++,1);
+ sequence->picture.vdp_infos.range_mapuv_flag = read_bits( &sequence->br, 1 );
if ( sequence->picture.vdp_infos.range_mapuv_flag ) {
- sequence->picture.vdp_infos.range_mapuv = get_bits(buf,off,3);
- off += 3;
+ sequence->picture.vdp_infos.range_mapuv = read_bits( &sequence->br, 3 );
}
}
@@ -438,41 +431,39 @@ static void picture_header( vdpau_vc1_decoder_t *this_gen, uint8_t *buf, int len
lprintf("picture_header\n");
- int off=2;
+ bits_reader_set( &sequence->br, buf );
+ read_bits( &sequence->br, 2 );
if ( info->finterpflag )
- ++off;
+ read_bits( &sequence->br, 1 );
if ( info->rangered ) {
/*info->rangered &= ~2;
info->rangered |= get_bits( buf,off++,1 ) << 1;*/
- info->rangered = (get_bits( buf,off++,1 ) << 1) +1;
+ info->rangered = (read_bits( &sequence->br, 1 ) << 1) +1;
}
if ( !info->maxbframes ) {
- if ( get_bits( buf,off++,1 ) )
+ if ( read_bits( &sequence->br, 1 ) )
info->picture_type = P_FRAME;
else
info->picture_type = I_FRAME;
}
else {
- if ( get_bits( buf,off++,1 ) )
+ if ( read_bits( &sequence->br, 1 ) )
info->picture_type = P_FRAME;
else {
- if ( get_bits( buf,off++,1 ) )
+ if ( read_bits( &sequence->br, 1 ) )
info->picture_type = I_FRAME;
else
info->picture_type = B_FRAME;
}
}
if ( info->picture_type == B_FRAME ) {
- tmp = get_bits(buf,off,3);
+ tmp = read_bits( &sequence->br, 3 );
if ( tmp==7 ) {
- tmp = get_bits(buf,off,7);
- off += 7;
+ tmp = read_bits( &sequence->br, 7 );
if ( tmp==127 )
info->picture_type = BI_FRAME;
}
- else
- off += 3;
}
}
@@ -483,18 +474,19 @@ static void picture_header_advanced( vdpau_vc1_decoder_t *this_gen, uint8_t *buf
sequence_t *sequence = (sequence_t*)&this_gen->sequence;
picture_t *pic = (picture_t*)&sequence->picture;
VdpPictureInfoVC1 *info = &(sequence->picture.vdp_infos);
- int off=0;
lprintf("picture_header_advanced\n");
+ bits_reader_set( &sequence->br, buf );
+
if ( info->interlace ) {
lprintf("frame->interlace=1\n");
- if ( !get_bits(buf,off++,1) ) {
+ if ( !read_bits( &sequence->br, 1 ) ) {
lprintf("progressive frame\n");
info->frame_coding_mode = PICTURE_FRAME;
}
else {
- if ( !get_bits(buf,off++,1) ) {
+ if ( !read_bits( &sequence->br, 1 ) ) {
lprintf("frame interlaced\n");
info->frame_coding_mode = PICTURE_FRAME_INTERLACE;
}
@@ -505,7 +497,7 @@ static void picture_header_advanced( vdpau_vc1_decoder_t *this_gen, uint8_t *buf
}
}
if ( info->interlace && info->frame_coding_mode == PICTURE_FIELD_INTERLACE ) {
- pic->fptype = get_bits(buf,off,3);
+ pic->fptype = read_bits( &sequence->br, 3 );
switch ( pic->fptype ) {
case FIELDS_I_I:
case FIELDS_I_P:
@@ -519,19 +511,18 @@ static void picture_header_advanced( vdpau_vc1_decoder_t *this_gen, uint8_t *buf
default:
info->picture_type = BI_FRAME;
}
- off += 3;
}
else {
- if ( !get_bits(buf,off++,1) )
+ if ( !read_bits( &sequence->br, 1 ) )
info->picture_type = P_FRAME;
else {
- if ( !get_bits(buf,off++,1) )
+ if ( !read_bits( &sequence->br, 1 ) )
info->picture_type = B_FRAME;
else {
- if ( !get_bits(buf,off++,1) )
+ if ( !read_bits( &sequence->br, 1 ) )
info->picture_type = I_FRAME;
else {
- if ( !get_bits(buf,off++,1) )
+ if ( !read_bits( &sequence->br, 1 ) )
info->picture_type = BI_FRAME;
else {
info->picture_type = P_FRAME;
@@ -543,11 +534,11 @@ static void picture_header_advanced( vdpau_vc1_decoder_t *this_gen, uint8_t *buf
}
if ( info->tfcntrflag ) {
lprintf("tfcntrflag=1\n");
- off += 8;
+ read_bits( &sequence->br, 8 );
}
if ( info->pulldown && info->interlace ) {
- pic->top_field_first = get_bits(buf,off++,1);
- pic->repeat_first_field = get_bits(buf,off++,1);
+ pic->top_field_first = read_bits( &sequence->br, 1 );
+ pic->repeat_first_field = read_bits( &sequence->br, 1 );
}
}
@@ -1139,7 +1130,7 @@ static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stre
(stream->video_out->open)(stream->video_out, stream);
#ifdef MAKE_DAT
- outfile = fopen( "/home/cris/qvdpautest/mpg.dat","w");
+ outfile = fopen( "/tmp/vc1.dat","w");
nframes = 0;
#endif