1 #include <VP_Os/vp_os_malloc.h>
3 #include <VLIB/video_controller.h>
4 #include <VLIB/video_packetizer.h>
6 #include "p263_codec.h"
7 #include "p263_layers.h"
8 #include "p263_huffman.h"
10 C_RESULT p263_read_picture_layer( video_controller_t* controller, video_stream_t* stream )
13 p263_codec_t* p263_codec = (p263_codec_t*) controller->video_codec;
14 p263_picture_layer_t* picture_layer = &p263_codec->picture_layer;
16 p263_codec->mb_types = &standard_mb_types[0];
17 p263_codec->cbpys = &cbpy_standard[0];
19 // Read Temporal Reference (TR) (8 bits)
20 picture_layer->tr = 0;
21 video_read_data( stream, &picture_layer->tr, 8 );
23 // Read Type Information (PTYPE) (Variable Length)
24 picture_layer->ptype = 0;
25 picture_layer->plusptype = 0;
26 picture_layer->opptype = 0;
27 video_read_data( stream, &picture_layer->ptype, 8 );
29 switch( PICTURE_FORMAT(picture_layer->ptype) )
31 case P263_PICTURE_FORMAT_FORBIDDEN:
34 case P263_PICTURE_FORMAT_SUBQCIF:
35 video_controller_set_format( controller, 128, 96 );
36 goto P263_PICTURE_FORMAT_NOT_EXTENDED;
38 case P263_PICTURE_FORMAT_QCIF:
39 video_controller_set_format( controller, 176, 144 );
40 goto P263_PICTURE_FORMAT_NOT_EXTENDED;
42 case P263_PICTURE_FORMAT_CIF:
43 video_controller_set_format( controller, 352, 288 );
44 goto P263_PICTURE_FORMAT_NOT_EXTENDED;
46 case P263_PICTURE_FORMAT_4QCIF:
47 video_controller_set_format( controller, 704, 576 );
48 goto P263_PICTURE_FORMAT_NOT_EXTENDED;
50 case P263_PICTURE_FORMAT_16CIF:
51 video_controller_set_format( controller, 1408, 1152 );
53 P263_PICTURE_FORMAT_NOT_EXTENDED:
54 video_read_data( stream, &picture_layer->ptype, 5 );
55 video_controller_set_picture_type( controller, PICTURE_TYPE(picture_layer->ptype) );
58 case P263_PICTURE_FORMAT_RESERVED:
61 case P263_PICTURE_FORMAT_EXTENDED:
62 // Read Plus PTYPE (PLUSPTYPE) (Variable Length) -- Optionnal, see PTYPE
64 video_read_data( stream, &picture_layer->plusptype, 3 );
65 if( picture_layer->plusptype == 1 )
68 video_read_data( stream, &picture_layer->opptype, 18 );
72 video_read_data( stream, &picture_layer->plusptype, 9 );
73 video_controller_set_picture_type( controller, PICTURE_EXTENDED_TYPE(picture_layer->plusptype) );
77 if( picture_layer->plusptype )
79 // Read Continuous Presence Multipoint and Video Multiplex (CPM) (1 bit, see Annex C)
80 video_read_data( stream, &picture_layer->cpm, 1 );
82 if( picture_layer->cpm )
84 // Read Picture Sub-Bitstream Indicator (PSBI) (2 bits)
85 video_read_data( stream, &picture_layer->psbi, 2 );
89 if( picture_layer->opptype ) // eg UFEP == 001b
91 if( HAS_CUSTOM_PICTURE_FORMAT( picture_layer->opptype ) )
93 // Read Custom Picture Format (CPFMT) (23 bits)
94 video_read_data( stream, &picture_layer->cpfmt, 23 );
96 if( (picture_layer->cpfmt >> 19) == 0xF )
98 // Read Extended Pixel Aspect Ratio (EPAR) (16 bits)
99 video_read_data( stream, &picture_layer->epar, 16 );
103 if( HAS_CUSTOM_PCF(picture_layer->opptype) )
105 // Read Custom Picture Clock Frequency Code (CPCFC) (8 bits)
106 video_read_data( stream, &picture_layer->cpcfc, 8 );
108 // Read Extended Temporal Reference (ETR) (2 bits)
109 video_read_data( stream, &picture_layer->etr, 2 );
112 if( HAS_UNRESTRICTED_MOTION_VECTOR(picture_layer->opptype) )
114 // Read Unlimited Unrestricted Motion Vectors Indicator (UUI) (Variable length) -- Optionnal
115 video_read_data( stream, &picture_layer->uui, 1 );
116 if( picture_layer->uui == 0 )
117 video_read_data( stream, &picture_layer->uui, 1 );
120 if( HAS_SLICE_STRUCTURED(picture_layer->sss) )
122 // Read Slice Structured Submode bits (SSS) (2 bits) -- Optionnal
123 video_read_data( stream, &picture_layer->sss, 2 );
127 if( controller->picture_type == VIDEO_PICTURE_EP )
129 // Read Enhancement Layer Number (ELNUM) (4 bits) -- Optionnal
130 video_read_data( stream, &picture_layer->elnum, 4 );
132 if( picture_layer->opptype ) // eg UFEP == 001b
134 // Read Reference Layer Number (RLNUM) (4 bits) -- Optionnal
135 video_read_data( stream, &picture_layer->rlnum, 4 );
139 if( HAS_REFERENCE_PICTURE_SELECTION( picture_layer->opptype ) )
141 // Read Reference Picture Selection Mode Flags (RPSMF) (3 bits) -- Optionnal
142 video_read_data( stream, &picture_layer->rpsmf, 3 );
145 if( picture_layer->rpsmf )
147 // Read Temporal Reference for Prediction Indication (TRPI) (1 bit) -- Optionnal
148 video_read_data( stream, &picture_layer->trpi, 1 );
150 if( picture_layer->trpi )
152 // Read Temporal Reference for Prediction (TRP) (10 bits) -- Optionnal
153 video_read_data( stream, &picture_layer->trp, 10 );
156 // Read Back-Channel message Indication (BCI) (Variable length, 1 or 2 bits) -- Optionnal
157 video_read_data( stream, &picture_layer->bci, 1 );
159 if( picture_layer->bci == 1 )
162 // Read Back-Channel Message (BCM) (Variable length, see N.4.2) -- Optionnal
166 video_read_data( stream, &picture_layer->bci, 1 ); // read '01' end of back channel message
170 if( HAS_REFERENCE_PICTURE_RESAMPLING( picture_layer->plusptype ) )
173 // Read Reference Picture Resampling Parameters (RPRP) (Variable length, see Annex P) -- Optionnal
176 // Read Quantizer Information (PQUANT) (5 bits)
177 video_read_data( stream, &picture_layer->pquant, 5 );
178 controller->Qp = picture_layer->pquant;
180 if( !picture_layer->plusptype )
182 // Read Continuous Presence Multipoint and Video Multiplex (CPM) (1 bit, see Annex C)
183 video_read_data( stream, &picture_layer->cpm, 1 );
185 if( picture_layer->cpm )
187 // Read Picture Sub-Bitstream Indicator (PSBI) (2 bits)
188 video_read_data( stream, &picture_layer->psbi, 2 );
192 if( controller->picture_type == VIDEO_PICTURE_PB )
195 // Read Temporal Reference for B-pictures in PB-frames (TRB) (3/5 bits) -- Optionnal
197 // Read Quantization information for B-pictures in PB-frames (DBQUANT) (2 bits)
200 // Read Extra Insertion Information (PEI) (1 bit)
201 picture_layer->pei = 0;
202 video_read_data( stream, &pei, 1 );
206 // Read Supplemental Enhancement Information (PSUPP) (0/8/16 ... bits) -- Optionnal (See Annex L)
207 video_read_data( stream, &pei, 8 );
209 // picture_layer->psupp[picture_layer->pei++] = pei; TODO: Alloc psupp
211 video_read_data( stream, &pei, 1 );