Mercurial > libavcodec.hg
comparison mpeg12.c @ 1064:b32afefe7d33 libavcodec
* UINTX -> uintx_t INTX -> intx_t
| author | kabi |
|---|---|
| date | Tue, 11 Feb 2003 16:35:48 +0000 |
| parents | e5a9dbf597d4 |
| children | 6da5ae9ee199 |
comparison
equal
deleted
inserted
replaced
| 1063:fdeac9642346 | 1064:b32afefe7d33 |
|---|---|
| 65 DCTELEM *block, | 65 DCTELEM *block, |
| 66 int n); | 66 int n); |
| 67 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); | 67 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); |
| 68 | 68 |
| 69 #ifdef CONFIG_ENCODERS | 69 #ifdef CONFIG_ENCODERS |
| 70 static UINT16 mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; | 70 static uint16_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; |
| 71 static UINT8 fcode_tab[MAX_MV*2+1]; | 71 static uint8_t fcode_tab[MAX_MV*2+1]; |
| 72 | 72 |
| 73 static uint32_t uni_mpeg1_ac_vlc_bits[64*64*2]; | 73 static uint32_t uni_mpeg1_ac_vlc_bits[64*64*2]; |
| 74 static uint8_t uni_mpeg1_ac_vlc_len [64*64*2]; | 74 static uint8_t uni_mpeg1_ac_vlc_len [64*64*2]; |
| 75 #endif | 75 #endif |
| 76 | 76 |
| 180 static void mpeg1_encode_sequence_header(MpegEncContext *s) | 180 static void mpeg1_encode_sequence_header(MpegEncContext *s) |
| 181 { | 181 { |
| 182 unsigned int vbv_buffer_size; | 182 unsigned int vbv_buffer_size; |
| 183 unsigned int fps, v; | 183 unsigned int fps, v; |
| 184 int n, i; | 184 int n, i; |
| 185 UINT64 time_code; | 185 uint64_t time_code; |
| 186 float best_aspect_error= 1E10; | 186 float best_aspect_error= 1E10; |
| 187 float aspect_ratio= s->avctx->aspect_ratio; | 187 float aspect_ratio= s->avctx->aspect_ratio; |
| 188 | 188 |
| 189 if(aspect_ratio==0.0) aspect_ratio= s->width / (float)s->height; //pixel aspect 1:1 (VGA) | 189 if(aspect_ratio==0.0) aspect_ratio= s->width / (float)s->height; //pixel aspect 1:1 (VGA) |
| 190 | 190 |
| 240 put_header(s, GOP_START_CODE); | 240 put_header(s, GOP_START_CODE); |
| 241 put_bits(&s->pb, 1, 0); /* do drop frame */ | 241 put_bits(&s->pb, 1, 0); /* do drop frame */ |
| 242 /* time code : we must convert from the real frame rate to a | 242 /* time code : we must convert from the real frame rate to a |
| 243 fake mpeg frame rate in case of low frame rate */ | 243 fake mpeg frame rate in case of low frame rate */ |
| 244 fps = frame_rate_tab[s->frame_rate_index]; | 244 fps = frame_rate_tab[s->frame_rate_index]; |
| 245 time_code = (INT64)s->fake_picture_number * FRAME_RATE_BASE; | 245 time_code = (int64_t)s->fake_picture_number * FRAME_RATE_BASE; |
| 246 s->gop_picture_number = s->fake_picture_number; | 246 s->gop_picture_number = s->fake_picture_number; |
| 247 put_bits(&s->pb, 5, (UINT32)((time_code / (fps * 3600)) % 24)); | 247 put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); |
| 248 put_bits(&s->pb, 6, (UINT32)((time_code / (fps * 60)) % 60)); | 248 put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); |
| 249 put_bits(&s->pb, 1, 1); | 249 put_bits(&s->pb, 1, 1); |
| 250 put_bits(&s->pb, 6, (UINT32)((time_code / fps) % 60)); | 250 put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60)); |
| 251 put_bits(&s->pb, 6, (UINT32)((time_code % fps) / FRAME_RATE_BASE)); | 251 put_bits(&s->pb, 6, (uint32_t)((time_code % fps) / FRAME_RATE_BASE)); |
| 252 put_bits(&s->pb, 1, 1); /* closed gop */ | 252 put_bits(&s->pb, 1, 1); /* closed gop */ |
| 253 put_bits(&s->pb, 1, 0); /* broken link */ | 253 put_bits(&s->pb, 1, 0); /* broken link */ |
| 254 } | 254 } |
| 255 | 255 |
| 256 if (s->frame_rate < (24 * FRAME_RATE_BASE) && s->picture_number > 0) { | 256 if (s->frame_rate < (24 * FRAME_RATE_BASE) && s->picture_number > 0) { |
| 257 /* insert empty P pictures to slow down to the desired | 257 /* insert empty P pictures to slow down to the desired |
| 258 frame rate. Each fake pictures takes about 20 bytes */ | 258 frame rate. Each fake pictures takes about 20 bytes */ |
| 259 fps = frame_rate_tab[s->frame_rate_index]; | 259 fps = frame_rate_tab[s->frame_rate_index]; |
| 260 n = (((INT64)s->picture_number * fps) / s->frame_rate) - 1; | 260 n = (((int64_t)s->picture_number * fps) / s->frame_rate) - 1; |
| 261 while (s->fake_picture_number < n) { | 261 while (s->fake_picture_number < n) { |
| 262 mpeg1_skip_picture(s, s->fake_picture_number - | 262 mpeg1_skip_picture(s, s->fake_picture_number - |
| 263 s->gop_picture_number); | 263 s->gop_picture_number); |
| 264 s->fake_picture_number++; | 264 s->fake_picture_number++; |
| 265 } | 265 } |
| 735 } else { | 735 } else { |
| 736 /* encode the first coefficient : needs to be done here because | 736 /* encode the first coefficient : needs to be done here because |
| 737 it is handled slightly differently */ | 737 it is handled slightly differently */ |
| 738 level = block[0]; | 738 level = block[0]; |
| 739 if (abs(level) == 1) { | 739 if (abs(level) == 1) { |
| 740 code = ((UINT32)level >> 31); /* the sign bit */ | 740 code = ((uint32_t)level >> 31); /* the sign bit */ |
| 741 put_bits(&s->pb, 2, code | 0x02); | 741 put_bits(&s->pb, 2, code | 0x02); |
| 742 i = 1; | 742 i = 1; |
| 743 } else { | 743 } else { |
| 744 i = 0; | 744 i = 0; |
| 745 last_non_zero = -1; | 745 last_non_zero = -1; |
| 1206 int n) | 1206 int n) |
| 1207 { | 1207 { |
| 1208 int level, dc, diff, i, j, run; | 1208 int level, dc, diff, i, j, run; |
| 1209 int component; | 1209 int component; |
| 1210 RLTable *rl = &rl_mpeg1; | 1210 RLTable *rl = &rl_mpeg1; |
| 1211 UINT8 * const scantable= s->intra_scantable.permutated; | 1211 uint8_t * const scantable= s->intra_scantable.permutated; |
| 1212 const UINT16 *quant_matrix= s->intra_matrix; | 1212 const uint16_t *quant_matrix= s->intra_matrix; |
| 1213 const int qscale= s->qscale; | 1213 const int qscale= s->qscale; |
| 1214 | 1214 |
| 1215 /* DC coef */ | 1215 /* DC coef */ |
| 1216 component = (n <= 3 ? 0 : n - 4 + 1); | 1216 component = (n <= 3 ? 0 : n - 4 + 1); |
| 1217 diff = decode_dc(s, component); | 1217 diff = decode_dc(s, component); |
| 1278 DCTELEM *block, | 1278 DCTELEM *block, |
| 1279 int n) | 1279 int n) |
| 1280 { | 1280 { |
| 1281 int level, i, j, run; | 1281 int level, i, j, run; |
| 1282 RLTable *rl = &rl_mpeg1; | 1282 RLTable *rl = &rl_mpeg1; |
| 1283 UINT8 * const scantable= s->intra_scantable.permutated; | 1283 uint8_t * const scantable= s->intra_scantable.permutated; |
| 1284 const UINT16 *quant_matrix= s->inter_matrix; | 1284 const uint16_t *quant_matrix= s->inter_matrix; |
| 1285 const int qscale= s->qscale; | 1285 const int qscale= s->qscale; |
| 1286 | 1286 |
| 1287 { | 1287 { |
| 1288 int v; | 1288 int v; |
| 1289 OPEN_READER(re, &s->gb); | 1289 OPEN_READER(re, &s->gb); |
| 1356 DCTELEM *block, | 1356 DCTELEM *block, |
| 1357 int n) | 1357 int n) |
| 1358 { | 1358 { |
| 1359 int level, i, j, run; | 1359 int level, i, j, run; |
| 1360 RLTable *rl = &rl_mpeg1; | 1360 RLTable *rl = &rl_mpeg1; |
| 1361 UINT8 * const scantable= s->intra_scantable.permutated; | 1361 uint8_t * const scantable= s->intra_scantable.permutated; |
| 1362 const UINT16 *quant_matrix; | 1362 const uint16_t *quant_matrix; |
| 1363 const int qscale= s->qscale; | 1363 const int qscale= s->qscale; |
| 1364 int mismatch; | 1364 int mismatch; |
| 1365 | 1365 |
| 1366 mismatch = 1; | 1366 mismatch = 1; |
| 1367 | 1367 |
| 1436 int n) | 1436 int n) |
| 1437 { | 1437 { |
| 1438 int level, dc, diff, i, j, run; | 1438 int level, dc, diff, i, j, run; |
| 1439 int component; | 1439 int component; |
| 1440 RLTable *rl; | 1440 RLTable *rl; |
| 1441 UINT8 * const scantable= s->intra_scantable.permutated; | 1441 uint8_t * const scantable= s->intra_scantable.permutated; |
| 1442 const UINT16 *quant_matrix; | 1442 const uint16_t *quant_matrix; |
| 1443 const int qscale= s->qscale; | 1443 const int qscale= s->qscale; |
| 1444 int mismatch; | 1444 int mismatch; |
| 1445 | 1445 |
| 1446 /* DC coef */ | 1446 /* DC coef */ |
| 1447 if (n < 4){ | 1447 if (n < 4){ |
| 1514 /* compressed picture size */ | 1514 /* compressed picture size */ |
| 1515 #define PICTURE_BUFFER_SIZE 100000 | 1515 #define PICTURE_BUFFER_SIZE 100000 |
| 1516 | 1516 |
| 1517 typedef struct Mpeg1Context { | 1517 typedef struct Mpeg1Context { |
| 1518 MpegEncContext mpeg_enc_ctx; | 1518 MpegEncContext mpeg_enc_ctx; |
| 1519 UINT32 header_state; | 1519 uint32_t header_state; |
| 1520 int start_code; /* current start code */ | 1520 int start_code; /* current start code */ |
| 1521 UINT8 buffer[PICTURE_BUFFER_SIZE]; | 1521 uint8_t buffer[PICTURE_BUFFER_SIZE]; |
| 1522 UINT8 *buf_ptr; | 1522 uint8_t *buf_ptr; |
| 1523 int buffer_size; | 1523 int buffer_size; |
| 1524 int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ | 1524 int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ |
| 1525 int repeat_field; /* true if we must repeat the field */ | 1525 int repeat_field; /* true if we must repeat the field */ |
| 1526 } Mpeg1Context; | 1526 } Mpeg1Context; |
| 1527 | 1527 |
| 1544 return 0; | 1544 return 0; |
| 1545 } | 1545 } |
| 1546 | 1546 |
| 1547 /* return the 8 bit start code value and update the search | 1547 /* return the 8 bit start code value and update the search |
| 1548 state. Return -1 if no start code found */ | 1548 state. Return -1 if no start code found */ |
| 1549 static int find_start_code(UINT8 **pbuf_ptr, UINT8 *buf_end, | 1549 static int find_start_code(uint8_t **pbuf_ptr, uint8_t *buf_end, |
| 1550 UINT32 *header_state) | 1550 uint32_t *header_state) |
| 1551 { | 1551 { |
| 1552 UINT8 *buf_ptr; | 1552 uint8_t *buf_ptr; |
| 1553 unsigned int state, v; | 1553 unsigned int state, v; |
| 1554 int val; | 1554 int val; |
| 1555 | 1555 |
| 1556 state = *header_state; | 1556 state = *header_state; |
| 1557 buf_ptr = *pbuf_ptr; | 1557 buf_ptr = *pbuf_ptr; |
| 1570 *header_state = state; | 1570 *header_state = state; |
| 1571 return val; | 1571 return val; |
| 1572 } | 1572 } |
| 1573 | 1573 |
| 1574 static int mpeg1_decode_picture(AVCodecContext *avctx, | 1574 static int mpeg1_decode_picture(AVCodecContext *avctx, |
| 1575 UINT8 *buf, int buf_size) | 1575 uint8_t *buf, int buf_size) |
| 1576 { | 1576 { |
| 1577 Mpeg1Context *s1 = avctx->priv_data; | 1577 Mpeg1Context *s1 = avctx->priv_data; |
| 1578 MpegEncContext *s = &s1->mpeg_enc_ctx; | 1578 MpegEncContext *s = &s1->mpeg_enc_ctx; |
| 1579 int ref, f_code; | 1579 int ref, f_code; |
| 1580 | 1580 |
| 1722 dprintf("frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct); | 1722 dprintf("frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct); |
| 1723 dprintf("progressive_frame=%d\n", s->progressive_frame); | 1723 dprintf("progressive_frame=%d\n", s->progressive_frame); |
| 1724 } | 1724 } |
| 1725 | 1725 |
| 1726 static void mpeg_decode_extension(AVCodecContext *avctx, | 1726 static void mpeg_decode_extension(AVCodecContext *avctx, |
| 1727 UINT8 *buf, int buf_size) | 1727 uint8_t *buf, int buf_size) |
| 1728 { | 1728 { |
| 1729 Mpeg1Context *s1 = avctx->priv_data; | 1729 Mpeg1Context *s1 = avctx->priv_data; |
| 1730 MpegEncContext *s = &s1->mpeg_enc_ctx; | 1730 MpegEncContext *s = &s1->mpeg_enc_ctx; |
| 1731 int ext_type; | 1731 int ext_type; |
| 1732 | 1732 |
| 1762 * DECODE_SLICE_EOP if the end of the picture is reached | 1762 * DECODE_SLICE_EOP if the end of the picture is reached |
| 1763 */ | 1763 */ |
| 1764 static int mpeg_decode_slice(AVCodecContext *avctx, | 1764 static int mpeg_decode_slice(AVCodecContext *avctx, |
| 1765 AVFrame *pict, | 1765 AVFrame *pict, |
| 1766 int start_code, | 1766 int start_code, |
| 1767 UINT8 *buf, int buf_size) | 1767 uint8_t *buf, int buf_size) |
| 1768 { | 1768 { |
| 1769 Mpeg1Context *s1 = avctx->priv_data; | 1769 Mpeg1Context *s1 = avctx->priv_data; |
| 1770 MpegEncContext *s = &s1->mpeg_enc_ctx; | 1770 MpegEncContext *s = &s1->mpeg_enc_ctx; |
| 1771 int ret; | 1771 int ret; |
| 1772 | 1772 |
| 1895 return DECODE_SLICE_OK; | 1895 return DECODE_SLICE_OK; |
| 1896 } | 1896 } |
| 1897 } | 1897 } |
| 1898 | 1898 |
| 1899 static int mpeg1_decode_sequence(AVCodecContext *avctx, | 1899 static int mpeg1_decode_sequence(AVCodecContext *avctx, |
| 1900 UINT8 *buf, int buf_size) | 1900 uint8_t *buf, int buf_size) |
| 1901 { | 1901 { |
| 1902 Mpeg1Context *s1 = avctx->priv_data; | 1902 Mpeg1Context *s1 = avctx->priv_data; |
| 1903 MpegEncContext *s = &s1->mpeg_enc_ctx; | 1903 MpegEncContext *s = &s1->mpeg_enc_ctx; |
| 1904 int width, height, i, v, j; | 1904 int width, height, i, v, j; |
| 1905 float aspect; | 1905 float aspect; |
| 2008 } | 2008 } |
| 2009 | 2009 |
| 2010 /* handle buffering and image synchronisation */ | 2010 /* handle buffering and image synchronisation */ |
| 2011 static int mpeg_decode_frame(AVCodecContext *avctx, | 2011 static int mpeg_decode_frame(AVCodecContext *avctx, |
| 2012 void *data, int *data_size, | 2012 void *data, int *data_size, |
| 2013 UINT8 *buf, int buf_size) | 2013 uint8_t *buf, int buf_size) |
| 2014 { | 2014 { |
| 2015 Mpeg1Context *s = avctx->priv_data; | 2015 Mpeg1Context *s = avctx->priv_data; |
| 2016 UINT8 *buf_end, *buf_ptr, *buf_start; | 2016 uint8_t *buf_end, *buf_ptr, *buf_start; |
| 2017 int len, start_code_found, ret, code, start_code, input_size; | 2017 int len, start_code_found, ret, code, start_code, input_size; |
| 2018 AVFrame *picture = data; | 2018 AVFrame *picture = data; |
| 2019 MpegEncContext *s2 = &s->mpeg_enc_ctx; | 2019 MpegEncContext *s2 = &s->mpeg_enc_ctx; |
| 2020 | 2020 |
| 2021 dprintf("fill_buffer\n"); | 2021 dprintf("fill_buffer\n"); |
