1 2 #ifndef __SCHRO_DECODER_H__ 3 #define __SCHRO_DECODER_H__ 4 5 #include <schroedinger/schrobuffer.h> 6 #include <schroedinger/schroparams.h> 7 #include <schroedinger/schroframe.h> 8 #include <schroedinger/schromotion.h> 9 #include <schroedinger/schrounpack.h> 10 #include <schroedinger/schrobitstream.h> 11 #include <schroedinger/schroqueue.h> 12 #include <schroedinger/schroasync.h> 13 #include <schroedinger/schroarith.h> 14 #include <schroedinger/schrobufferlist.h> 15 #include <schroedinger/schroparse.h> 16 17 SCHRO_BEGIN_DECLS 18 19 typedef struct _SchroDecoder SchroDecoder; 20 typedef struct _SchroDecoderInstance SchroDecoderInstance; 21 typedef struct _SchroPicture SchroPicture; 22 23 #ifdef SCHRO_ENABLE_UNSTABLE_API 24 25 #ifndef SCHRO_OPENGL_TYPEDEF 26 #define SCHRO_OPENGL_TYPEDEF 27 typedef struct _SchroOpenGL SchroOpenGL; 28 #endif 29 30 struct _SchroDecoder { 31 /*< private >*/ 32 33 SchroMemoryDomain *cpu_domain; 34 SchroMemoryDomain *cuda_domain; 35 SchroMemoryDomain *opengl_domain; 36 37 SchroAsync *async; 38 39 int use_cuda; 40 SchroOpenGL *opengl; 41 int use_opengl; 42 43 double skip_value; 44 double skip_ratio; 45 int earliest_frame; 46 47 /* output pictures in coded order */ 48 int coded_order; 49 50 int error; 51 char *error_message; 52 53 SchroBufferList *input_buflist; 54 SchroParseSyncState *sps; 55 56 /* private data that is supplied with the input bitstream and 57 * is to be associated with the next picture to occur */ 58 SchroTag *next_picture_tag; 59 60 SchroDecoderInstance *instance; 61 }; 62 63 struct _SchroDecoderInstance { 64 /*< private >*/ 65 66 /* the decoder this sequence instance belongs to */ 67 SchroDecoder *decoder; 68 69 /* the next sequence instance to supercede this 70 * - New instances should be created whenever an EOS 71 * is detected at the input to the decoder 72 * - Old instances should be deleted whenever their 73 * state would cause an EOS to be emitted */ 74 SchroDecoderInstance *next; 75 76 /* the list of reference pictures */ 77 SchroQueue *reference_queue; 78 79 /* a list of frames provided by the app that we'll decode into */ 80 /* xxx: maybe this belongs in Decoder and not per instance */ 81 SchroQueue *output_queue; 82 83 /* the last picture number to be emitted by decoder_pull(). 84 * used to determine if a stream jumps backwards */ 85 SchroPictureNumber last_picture_number; 86 int last_picture_number_valid; 87 88 int major_version; 89 int minor_version; 90 int profile; 91 int level; 92 SchroVideoFormat video_format; 93 int compat_quant_offset; 94 95 SchroQueue *reorder_queue; 96 int reorder_queue_size; 97 98 int end_of_stream; 99 int flushing; 100 101 int first_sequence_header; 102 int have_sequence_header; 103 SchroBuffer *sequence_header_buffer; 104 int have_frame_number; 105 106 int has_md5; 107 uint8_t md5_checksum[32]; 108 109 int bit_depth; 110 }; 111 112 struct _SchroPicture { 113 int refcount; 114 115 SchroDecoderInstance *decoder_instance; 116 117 int busy; 118 int skip; 119 int error; 120 121 SchroBuffer *input_buffer; 122 SchroParams params; 123 SchroPictureNumber picture_number; 124 SchroPictureNumber reference1; 125 SchroPictureNumber reference2; 126 SchroPictureNumber retired_picture_number; 127 SchroPicture *ref0; 128 SchroPicture *ref1; 129 SchroFrame *planar_output_frame; 130 SchroFrame *ref_output_frame; 131 132 SchroAsyncStage stages[9]; 133 134 int is_ref; 135 136 int zero_residual; 137 138 SchroFrame *transform_frame; 139 SchroFrame *frame; 140 SchroFrame *mc_tmp_frame; 141 SchroMotion *motion; 142 SchroFrame *output_picture; 143 SchroUpsampledFrame *upsampled_frame; 144 145 int subband_length[3][SCHRO_LIMIT_SUBBANDS]; 146 int subband_quant_index[3][SCHRO_LIMIT_SUBBANDS]; 147 SchroBuffer *subband_buffer[3][SCHRO_LIMIT_SUBBANDS]; 148 SchroFrameData subband_data[3][SCHRO_LIMIT_SUBBANDS]; 149 150 SchroBuffer *motion_buffers[9]; 151 152 SchroBuffer *lowdelay_buffer; 153 154 int has_md5; 155 uint8_t md5_checksum[32]; 156 157 /* private data that is associated with this picture */ 158 SchroTag *tag; 159 }; 160 161 #endif 162 163 enum { 164 SCHRO_DECODER_OK, 165 SCHRO_DECODER_ERROR, 166 SCHRO_DECODER_EOS, 167 SCHRO_DECODER_FIRST_ACCESS_UNIT, 168 SCHRO_DECODER_NEED_BITS, 169 SCHRO_DECODER_NEED_FRAME, 170 SCHRO_DECODER_WAIT, 171 SCHRO_DECODER_STALLED 172 }; 173 174 enum { 175 SCHRO_DECODER_PICTURE_ORDER_PRESENTATION = 0, 176 SCHRO_DECODER_PICTURE_ORDER_CODED 177 }; 178 179 SchroDecoder * schro_decoder_new (void); 180 void schro_decoder_free (SchroDecoder *decoder); 181 void schro_decoder_reset (SchroDecoder *decoder); 182 SchroVideoFormat * schro_decoder_get_video_format (SchroDecoder *decoder); 183 void schro_decoder_add_output_picture (SchroDecoder *decoder, SchroFrame *frame); 184 int schro_decoder_push_ready (SchroDecoder *decoder); 185 int schro_decoder_push (SchroDecoder *decoder, SchroBuffer *buffer); 186 #ifndef SCHRO_DISABLE_DEPRECATED 187 int schro_decoder_set_flushing (SchroDecoder *decoder, int flushing) SCHRO_DEPRECATED; 188 #endif 189 void schro_decoder_set_picture_order (SchroDecoder *decoder, int picture_order); 190 int schro_decoder_push_end_of_stream (SchroDecoder *decoder); 191 SchroFrame *schro_decoder_pull (SchroDecoder *decoder); 192 int schro_decoder_wait (SchroDecoder *decoder); 193 194 void schro_decoder_set_earliest_frame (SchroDecoder *decoder, SchroPictureNumber earliest_frame); 195 void schro_decoder_set_skip_ratio (SchroDecoder *decoder, double ratio); 196 SchroPictureNumber schro_decoder_get_picture_number (SchroDecoder *decoder); 197 int schro_decoder_need_output_frame (SchroDecoder *decoder); 198 199 int schro_decoder_autoparse_wait (SchroDecoder *decoder); 200 int schro_decoder_autoparse_push (SchroDecoder *decoder, SchroBuffer *buffer); 201 int schro_decoder_autoparse_push_end_of_sequence (SchroDecoder *decoder); 202 203 SchroTag* schro_decoder_get_picture_tag (SchroDecoder *decoder); 204 205 #ifdef SCHRO_ENABLE_UNSTABLE_API 206 207 int schro_decoder_begin_sequence (SchroDecoder *decoder); 208 int schro_decoder_end_sequence (SchroDecoder *decoder); 209 210 int schro_decoder_decode_parse_header (SchroUnpack *unpack); 211 void schro_decoder_parse_sequence_header (SchroDecoderInstance *instance, SchroUnpack *unpack); 212 int schro_decoder_compare_sequence_header_buffer (SchroBuffer *a, SchroBuffer *b); 213 214 void schro_decoder_subband_dc_predict (SchroFrameData *fd); 215 void schro_decoder_subband_dc_predict_s32 (SchroFrameData *fd); 216 217 /* SchroPicture */ 218 219 SchroPicture * schro_picture_new (SchroDecoderInstance *instance); 220 SchroPicture * schro_picture_ref (SchroPicture *picture); 221 void schro_picture_unref (SchroPicture *picture); 222 223 int schro_decoder_iterate_picture (SchroDecoderInstance *instance, SchroBuffer *buffer, SchroUnpack *unpack, int parse_code); 224 void schro_decoder_parse_picture (SchroPicture *picture, SchroUnpack *unpack); 225 void schro_decoder_parse_picture_header (SchroPicture *picture, SchroUnpack *unpack); 226 void schro_decoder_parse_picture_prediction_parameters (SchroPicture *picture, SchroUnpack *unpack); 227 void schro_decoder_parse_block_data (SchroPicture *picture, SchroUnpack *unpack); 228 void schro_decoder_parse_transform_parameters (SchroPicture *picture, SchroUnpack *unpack); 229 void schro_decoder_parse_transform_data (SchroPicture *picture, SchroUnpack *unpack); 230 void schro_decoder_parse_lowdelay_transform_data (SchroPicture *picture, SchroUnpack *unpack); 231 void schro_decoder_init_subband_frame_data_interleaved (SchroPicture *picture); 232 void schro_decoder_init_subband_frame_data (SchroPicture *picture); 233 void schro_decoder_decode_block_data (SchroPicture *picture); 234 void schro_decoder_decode_transform_data (SchroPicture *picture); 235 void schro_decoder_decode_lowdelay_transform_data (SchroPicture *picture); 236 void schro_decoder_decode_macroblock(SchroPicture *picture, 237 SchroArith **arith, SchroUnpack *unpack, int i, int j); 238 void schro_decoder_decode_prediction_unit(SchroPicture *picture, 239 SchroArith **arith, SchroUnpack *unpack, SchroMotionVector *motion_vectors, 240 int x, int y); 241 242 243 #endif 244 245 SCHRO_END_DECLS 246 247 #endif 248 249