comparison h263.c @ 1661:4c9fd29f1606 libavcodec

h263 slice structured mode slice cleanup
author michael
date Sun, 07 Dec 2003 01:33:45 +0000
parents 3075fc11a974
children 4ac3573977e6
comparison
equal deleted inserted replaced
1660:806afb8e9085 1661:4c9fd29f1606
200 200
201 align_put_bits(&s->pb); 201 align_put_bits(&s->pb);
202 202
203 /* Update the pointer to last GOB */ 203 /* Update the pointer to last GOB */
204 s->ptr_lastgob = pbBufPtr(&s->pb); 204 s->ptr_lastgob = pbBufPtr(&s->pb);
205 s->gob_number = 0;
206
207 put_bits(&s->pb, 22, 0x20); /* PSC */ 205 put_bits(&s->pb, 22, 0x20); /* PSC */
208 put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->frame_rate_base) / 206 put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->frame_rate_base) /
209 s->avctx->frame_rate) & 0xff); 207 s->avctx->frame_rate) & 0xff);
210 208
211 put_bits(&s->pb, 1, 1); /* marker */ 209 put_bits(&s->pb, 1, 1); /* marker */
237 put_bits(&s->pb,3,6); /* Custom Source Format */ 235 put_bits(&s->pb,3,6); /* Custom Source Format */
238 else 236 else
239 put_bits(&s->pb, 3, format); 237 put_bits(&s->pb, 3, format);
240 238
241 put_bits(&s->pb,1,0); /* Custom PCF: off */ 239 put_bits(&s->pb,1,0); /* Custom PCF: off */
242 put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */ 240 put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */
243 put_bits(&s->pb,1,0); /* SAC: off */ 241 put_bits(&s->pb,1,0); /* SAC: off */
244 put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */ 242 put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */
245 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ 243 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */
246 put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */ 244 put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */
247 put_bits(&s->pb,1,0); /* Slice Structured: off */ 245 put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */
248 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ 246 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */
249 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ 247 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */
250 put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */ 248 put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */
251 put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */ 249 put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */
252 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ 250 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
280 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ 278 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
281 if (s->umvplus) 279 if (s->umvplus)
282 // put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ 280 // put_bits(&s->pb,1,1); /* Limited according tables of Annex D */
283 //FIXME check actual requested range 281 //FIXME check actual requested range
284 put_bits(&s->pb,2,1); /* unlimited */ 282 put_bits(&s->pb,2,1); /* unlimited */
283 if(s->h263_slice_structured)
284 put_bits(&s->pb,2,0); /* no weird submodes */
285 285
286 put_bits(&s->pb, 5, s->qscale); 286 put_bits(&s->pb, 5, s->qscale);
287 } 287 }
288 288
289 put_bits(&s->pb, 1, 0); /* no PEI */ 289 put_bits(&s->pb, 1, 0); /* no PEI */
298 } 298 }
299 299
300 /** 300 /**
301 * Encodes a group of blocks header. 301 * Encodes a group of blocks header.
302 */ 302 */
303 int h263_encode_gob_header(MpegEncContext * s, int mb_line) 303 void h263_encode_gob_header(MpegEncContext * s, int mb_line)
304 { 304 {
305 align_put_bits(&s->pb); 305 put_bits(&s->pb, 17, 1); /* GBSC */
306 flush_put_bits(&s->pb); 306
307 /* Call the RTP callback to send the last GOB */ 307 if(s->h263_slice_structured){
308 if (s->rtp_callback) { 308 put_bits(&s->pb, 1, 1);
309 int pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; 309
310 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); 310 ff_h263_encode_mba(s);
311 } 311
312 put_bits(&s->pb, 17, 1); /* GBSC */ 312 if(s->mb_num > 1583)
313 s->gob_number = mb_line / s->gob_index; 313 put_bits(&s->pb, 1, 1);
314 put_bits(&s->pb, 5, s->gob_number); /* GN */ 314 put_bits(&s->pb, 5, s->qscale); /* GQUANT */
315 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */ 315 put_bits(&s->pb, 1, 1);
316 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ 316 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */
317 //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif); 317 }else{
318 return 0; 318 int gob_number= mb_line / s->gob_index;
319
320 put_bits(&s->pb, 5, gob_number); /* GN */
321 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */
322 put_bits(&s->pb, 5, s->qscale); /* GQUANT */
323 }
319 } 324 }
320 325
321 static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int block_last_index, uint8_t scantable[64]){ 326 static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int block_last_index, uint8_t scantable[64]){
322 int last=0; 327 int last=0;
323 int j; 328 int j;
2782 return 2; 2787 return 2;
2783 else 2788 else
2784 return 4; 2789 return 4;
2785 } 2790 }
2786 2791
2792 int ff_h263_decode_mba(MpegEncContext *s)
2793 {
2794 int i, mb_pos;
2795
2796 for(i=0; i<6; i++){
2797 if(s->mb_num < ff_mba_max[i]) break;
2798 }
2799 mb_pos= get_bits(&s->gb, ff_mba_length[i]);
2800 s->mb_x= mb_pos % s->mb_width;
2801 s->mb_y= mb_pos / s->mb_width;
2802
2803 return mb_pos;
2804 }
2805
2806 void ff_h263_encode_mba(MpegEncContext *s)
2807 {
2808 int i, mb_pos;
2809
2810 for(i=0; i<6; i++){
2811 if(s->mb_num < ff_mba_max[i]) break;
2812 }
2813 mb_pos= s->mb_x + s->mb_width*s->mb_y;
2814 put_bits(&s->pb, ff_mba_length[i], mb_pos);
2815 }
2816
2787 /** 2817 /**
2788 * decodes the group of blocks header. 2818 * decodes the group of blocks header or slice header.
2789 * @return <0 if an error occured 2819 * @return <0 if an error occured
2790 */ 2820 */
2791 static int h263_decode_gob_header(MpegEncContext *s) 2821 static int h263_decode_gob_header(MpegEncContext *s)
2792 { 2822 {
2793 unsigned int val, gfid; 2823 unsigned int val, gfid, gob_number;
2794 int left; 2824 int left;
2795 2825
2796 /* Check for GOB Start Code */ 2826 /* Check for GOB Start Code */
2797 val = show_bits(&s->gb, 16); 2827 val = show_bits(&s->gb, 16);
2798 if(val) 2828 if(val)
2806 if(get_bits1(&s->gb)) break; /* Seek the '1' bit */ 2836 if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
2807 } 2837 }
2808 if(left<=13) 2838 if(left<=13)
2809 return -1; 2839 return -1;
2810 2840
2811 #ifdef DEBUG 2841 if(s->h263_slice_structured){
2812 fprintf(stderr,"\nGOB Start Code at MB %d\n", (s->mb_y * s->mb_width) + s->mb_x); 2842 if(get_bits1(&s->gb)==0)
2813 #endif 2843 return -1;
2814 s->gob_number = get_bits(&s->gb, 5); /* GN */ 2844
2815 gfid = get_bits(&s->gb, 2); /* GFID */ 2845 ff_h263_decode_mba(s);
2816 s->qscale = get_bits(&s->gb, 5); /* GQUANT */ 2846
2847 if(s->mb_num > 1583)
2848 if(get_bits1(&s->gb)==0)
2849 return -1;
2850
2851 s->qscale = get_bits(&s->gb, 5); /* SQUANT */
2852 if(get_bits1(&s->gb)==0)
2853 return -1;
2854 gfid = get_bits(&s->gb, 2); /* GFID */
2855 }else{
2856 gob_number = get_bits(&s->gb, 5); /* GN */
2857 s->mb_x= 0;
2858 s->mb_y= s->gob_index* gob_number;
2859 gfid = get_bits(&s->gb, 2); /* GFID */
2860 s->qscale = get_bits(&s->gb, 5); /* GQUANT */
2861 }
2862
2863 if(s->mb_y >= s->mb_height)
2864 return -1;
2865
2817 if(s->qscale==0) 2866 if(s->qscale==0)
2818 return -1; 2867 return -1;
2819 2868
2820 s->mb_x= 0;
2821 s->mb_y= s->gob_index* s->gob_number;
2822 if(s->mb_y >= s->mb_height)
2823 return -1;
2824 #ifdef DEBUG
2825 fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", s->gob_number, gfid, s->qscale);
2826 #endif
2827 return 0; 2869 return 0;
2828 } 2870 }
2829 2871
2830 static inline void memsetw(short *tab, int val, int n) 2872 static inline void memsetw(short *tab, int val, int n)
2831 { 2873 {
2887 2929
2888 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s) 2930 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
2889 { 2931 {
2890 int mb_num_bits= av_log2(s->mb_num - 1) + 1; 2932 int mb_num_bits= av_log2(s->mb_num - 1) + 1;
2891 2933
2892 ff_mpeg4_stuffing(&s->pb);
2893 put_bits(&s->pb, ff_mpeg4_get_video_packet_prefix_length(s), 0); 2934 put_bits(&s->pb, ff_mpeg4_get_video_packet_prefix_length(s), 0);
2894 put_bits(&s->pb, 1, 1); 2935 put_bits(&s->pb, 1, 1);
2895 2936
2896 put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y*s->mb_width); 2937 put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y*s->mb_width);
2897 put_bits(&s->pb, s->quant_precision, s->qscale); 2938 put_bits(&s->pb, s->quant_precision, s->qscale);
4757 } 4798 }
4758 skip_bits1(&s->gb); /* split screen off */ 4799 skip_bits1(&s->gb); /* split screen off */
4759 skip_bits1(&s->gb); /* camera off */ 4800 skip_bits1(&s->gb); /* camera off */
4760 skip_bits1(&s->gb); /* freeze picture release off */ 4801 skip_bits1(&s->gb); /* freeze picture release off */
4761 4802
4762 /* Reset GOB number */
4763 s->gob_number = 0;
4764
4765 format = get_bits(&s->gb, 3); 4803 format = get_bits(&s->gb, 3);
4766 /* 4804 /*
4767 0 forbidden 4805 0 forbidden
4768 1 sub-QCIF 4806 1 sub-QCIF
4769 10 QCIF 4807 10 QCIF
4818 s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ 4856 s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
4819 s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */ 4857 s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */
4820 s->loop_filter= get_bits1(&s->gb); 4858 s->loop_filter= get_bits1(&s->gb);
4821 s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter; 4859 s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter;
4822 4860
4823 if (get_bits1(&s->gb) != 0) { 4861 s->h263_slice_structured= get_bits1(&s->gb);
4824 av_log(s->avctx, AV_LOG_ERROR, "Slice Structured not supported\n");
4825 }
4826 if (get_bits1(&s->gb) != 0) { 4862 if (get_bits1(&s->gb) != 0) {
4827 av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); 4863 av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
4828 } 4864 }
4829 if (get_bits1(&s->gb) != 0) { 4865 if (get_bits1(&s->gb) != 0) {
4830 av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); 4866 av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
4892 s->height = height; 4928 s->height = height;
4893 if (s->umvplus) { 4929 if (s->umvplus) {
4894 if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ 4930 if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
4895 skip_bits1(&s->gb); 4931 skip_bits1(&s->gb);
4896 } 4932 }
4933 if(s->h263_slice_structured){
4934 if (get_bits1(&s->gb) != 0) {
4935 av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
4936 }
4937 if (get_bits1(&s->gb) != 0) {
4938 av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");
4939 }
4940 }
4897 } 4941 }
4898 4942
4899 s->qscale = get_bits(&s->gb, 5); 4943 s->qscale = get_bits(&s->gb, 5);
4900 } 4944 }
4901 /* PEI */ 4945 /* PEI */
4911 s->y_dc_scale_table= 4955 s->y_dc_scale_table=
4912 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; 4956 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
4913 } 4957 }
4914 4958
4915 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ 4959 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
4916 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s\n", 4960 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s\n",
4917 s->qscale, av_get_pict_type_char(s->pict_type), 4961 s->qscale, av_get_pict_type_char(s->pict_type),
4918 s->gb.size_in_bits, 1-s->no_rounding, 4962 s->gb.size_in_bits, 1-s->no_rounding,
4919 s->obmc ? " AP" : "", 4963 s->obmc ? " AP" : "",
4920 s->umvplus ? " UMV" : "", 4964 s->umvplus ? " UMV" : "",
4921 s->h263_long_vectors ? " LONG" : "", 4965 s->h263_long_vectors ? " LONG" : "",
4922 s->h263_plus ? " +" : "", 4966 s->h263_plus ? " +" : "",
4923 s->h263_aic ? " AIC" : "", 4967 s->h263_aic ? " AIC" : "",
4924 s->alt_inter_vlc ? " AIV" : "", 4968 s->alt_inter_vlc ? " AIV" : "",
4925 s->modified_quant ? " MQ" : "", 4969 s->modified_quant ? " MQ" : "",
4926 s->loop_filter ? " LOOP" : "" 4970 s->loop_filter ? " LOOP" : "",
4971 s->h263_slice_structured ? " SS" : ""
4927 ); 4972 );
4928 } 4973 }
4929 #if 1 4974 #if 1
4930 if (s->pict_type == I_TYPE && s->avctx->codec_tag == ff_get_fourcc("ZYGO")){ 4975 if (s->pict_type == I_TYPE && s->avctx->codec_tag == ff_get_fourcc("ZYGO")){
4931 int i,j; 4976 int i,j;