Mercurial > libavcodec.hg
comparison mpegvideo.c @ 231:840cd25bf259 libavcodec
- Fixes on RTP and GOB headers for H.263.
- RTP callback system implemented for H.263/H.263+.
- Bug fix on DC coefficients of H.263.
- H.263 decoder now returns PTS on picture number.
author | pulento |
---|---|
date | Sat, 09 Feb 2002 16:59:56 +0000 |
parents | ba9cd6fb6f0e |
children | b640ec5948b0 |
comparison
equal
deleted
inserted
replaced
230:ba9cd6fb6f0e | 231:840cd25bf259 |
---|---|
262 s->width = avctx->width; | 262 s->width = avctx->width; |
263 s->height = avctx->height; | 263 s->height = avctx->height; |
264 s->gop_size = avctx->gop_size; | 264 s->gop_size = avctx->gop_size; |
265 s->rtp_mode = avctx->rtp_mode; | 265 s->rtp_mode = avctx->rtp_mode; |
266 s->rtp_payload_size = avctx->rtp_payload_size; | 266 s->rtp_payload_size = avctx->rtp_payload_size; |
267 if (avctx->rtp_callback) | |
268 s->rtp_callback = avctx->rtp_callback; | |
267 s->avctx = avctx; | 269 s->avctx = avctx; |
268 | 270 |
269 if (s->gop_size <= 1) { | 271 if (s->gop_size <= 1) { |
270 s->intra_only = 1; | 272 s->intra_only = 1; |
271 s->gop_size = 12; | 273 s->gop_size = 12; |
866 emms_c(); | 868 emms_c(); |
867 } | 869 } |
868 | 870 |
869 static void encode_picture(MpegEncContext *s, int picture_number) | 871 static void encode_picture(MpegEncContext *s, int picture_number) |
870 { | 872 { |
871 int mb_x, mb_y, wrap, last_gob; | 873 int mb_x, mb_y, wrap, last_gob, pdif = 0; |
872 UINT8 *ptr; | 874 UINT8 *ptr; |
873 int i, motion_x, motion_y; | 875 int i, motion_x, motion_y; |
874 | 876 |
875 s->picture_number = picture_number; | 877 s->picture_number = picture_number; |
876 if (!s->fixed_qscale) | 878 if (!s->fixed_qscale) |
917 s->last_mv[0][0][1] = 0; | 919 s->last_mv[0][0][1] = 0; |
918 s->mv_type = MV_TYPE_16X16; | 920 s->mv_type = MV_TYPE_16X16; |
919 s->mv_dir = MV_DIR_FORWARD; | 921 s->mv_dir = MV_DIR_FORWARD; |
920 | 922 |
921 /* Get the GOB height based on picture height */ | 923 /* Get the GOB height based on picture height */ |
922 if (s->out_format == FMT_H263 && s->h263_plus) { | 924 if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4) { |
923 if (s->height <= 400) | 925 if (s->height <= 400) |
924 s->gob_index = 1; | 926 s->gob_index = 1; |
925 else if (s->height <= 800) | 927 else if (s->height <= 800) |
926 s->gob_index = 2; | 928 s->gob_index = 2; |
927 else | 929 else |
928 s->gob_index = 4; | 930 s->gob_index = 4; |
929 } | 931 } |
930 | 932 |
931 for(mb_y=0; mb_y < s->mb_height; mb_y++) { | 933 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
932 /* Put GOB header based on RTP MTU */ | 934 /* Put GOB header based on RTP MTU */ |
933 if (!mb_y) { | 935 /* TODO: Put all this stuff in a separate generic function */ |
934 s->ptr_lastgob = s->pb.buf_ptr; | 936 if (s->rtp_mode) { |
935 s->ptr_last_mb_line = s->pb.buf_ptr; | 937 if (!mb_y) { |
936 } else if (s->out_format == FMT_H263 && s->h263_plus) { | 938 s->ptr_lastgob = s->pb.buf; |
937 last_gob = h263_encode_gob_header(s, mb_y); | 939 s->ptr_last_mb_line = s->pb.buf; |
938 if (last_gob) { | 940 } else if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4 && !(mb_y % s->gob_index)) { |
939 //fprintf(stderr,"\nLast GOB size: %d", last_gob); | 941 last_gob = h263_encode_gob_header(s, mb_y); |
940 s->first_gob_line = 1; | 942 if (last_gob) { |
941 } else | 943 s->first_gob_line = 1; |
942 s->first_gob_line = 0; | 944 } |
945 } | |
943 } | 946 } |
944 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | 947 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
945 | 948 |
946 s->mb_x = mb_x; | 949 s->mb_x = mb_x; |
947 s->mb_y = mb_y; | 950 s->mb_y = mb_y; |
1044 s->mv[0][0][0] = motion_x; | 1047 s->mv[0][0][0] = motion_x; |
1045 s->mv[0][0][1] = motion_y; | 1048 s->mv[0][0][1] = motion_y; |
1046 | 1049 |
1047 MPV_decode_mb(s, s->block); | 1050 MPV_decode_mb(s, s->block); |
1048 } | 1051 } |
1049 /* Obtain average MB line size for RTP */ | 1052 /* Obtain average GOB size for RTP */ |
1050 if (!mb_y) | 1053 if (s->rtp_mode) { |
1051 s->mb_line_avgsize = s->pb.buf_ptr - s->ptr_last_mb_line; | 1054 if (!mb_y) |
1052 else | 1055 s->mb_line_avgsize = s->pb.buf_ptr - s->ptr_last_mb_line; |
1053 s->mb_line_avgsize = (s->mb_line_avgsize + s->pb.buf_ptr - s->ptr_last_mb_line) >> 1; | 1056 else if (!(mb_y % s->gob_index)) { |
1054 //fprintf(stderr, "\nMB line: %d\tSize: %u\tAvg. Size: %u", s->mb_y, | 1057 s->mb_line_avgsize = (s->mb_line_avgsize + s->pb.buf_ptr - s->ptr_last_mb_line) >> 1; |
1055 // (s->pb.buf_ptr - s->ptr_last_mb_line), s->mb_line_avgsize); | 1058 s->ptr_last_mb_line = s->pb.buf_ptr; |
1056 s->ptr_last_mb_line = s->pb.buf_ptr; | 1059 } |
1060 //fprintf(stderr, "\nMB line: %d\tSize: %u\tAvg. Size: %u", s->mb_y, | |
1061 // (s->pb.buf_ptr - s->ptr_last_mb_line), s->mb_line_avgsize); | |
1062 s->first_gob_line = 0; | |
1063 } | |
1057 } | 1064 } |
1058 | 1065 |
1059 if (s->h263_msmpeg4) | 1066 if (s->h263_msmpeg4) |
1060 msmpeg4_encode_ext_header(s); | 1067 msmpeg4_encode_ext_header(s); |
1061 | 1068 |
1062 //if (s->gob_number) | 1069 //if (s->gob_number) |
1063 // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); | 1070 // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); |
1071 | |
1072 /* Send the last GOB if RTP */ | |
1073 if (s->rtp_mode) { | |
1074 flush_put_bits(&s->pb); | |
1075 pdif = s->pb.buf_ptr - s->ptr_lastgob; | |
1076 /* Call the RTP callback to send the last GOB */ | |
1077 if (s->rtp_callback) | |
1078 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); | |
1079 s->ptr_lastgob = s->pb.buf_ptr; | |
1080 //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif); | |
1081 } | |
1082 | |
1064 } | 1083 } |
1065 | 1084 |
1066 static int dct_quantize_c(MpegEncContext *s, | 1085 static int dct_quantize_c(MpegEncContext *s, |
1067 DCTELEM *block, int n, | 1086 DCTELEM *block, int n, |
1068 int qscale) | 1087 int qscale) |