6
6
* 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
8
* This file is part of FFmpeg.
8
* This file is part of Libav.
10
* FFmpeg is free software; you can redistribute it and/or
10
* Libav is free software; you can redistribute it and/or
11
11
* modify it under the terms of the GNU Lesser General Public
12
12
* License as published by the Free Software Foundation; either
13
13
* version 2.1 of the License, or (at your option) any later version.
15
* FFmpeg is distributed in the hope that it will be useful,
15
* Libav is distributed in the hope that it will be useful,
16
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
18
* Lesser General Public License for more details.
20
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with FFmpeg; if not, write to the Free Software
21
* License along with Libav; if not, write to the Free Software
22
22
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
357
359
static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){
360
int y_size = s->b8_stride * (2 * s->mb_height + 1);
361
int c_size = s->mb_stride * (s->mb_height + 1);
362
int yc_size = y_size + 2 * c_size;
360
365
// edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264)
380
385
for(i=0;i<12;i++){
381
386
s->pblocks[i] = &s->block[i];
389
if (s->out_format == FMT_H263) {
391
FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail);
392
s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
393
s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
394
s->ac_val[2] = s->ac_val[1] + c_size;
385
399
return -1; //free() through MPV_common_end()
480
499
if(s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
481
500
s->mb_height = (s->height + 31) / 32 * 2;
501
else if (s->codec_id != CODEC_ID_H264)
483
502
s->mb_height = (s->height + 15) / 16;
485
504
if(s->avctx->pix_fmt == PIX_FMT_NONE){
495
if((s->width || s->height) && avcodec_check_dimensions(s->avctx, s->width, s->height))
514
if((s->width || s->height) && av_image_check_size(s->width, s->height, 0, s->avctx))
498
517
dsputil_init(&s->dsp, s->avctx);
530
549
yc_size = y_size + 2 * c_size;
532
551
/* convert fourcc to upper case */
533
s->codec_tag= toupper( s->avctx->codec_tag &0xFF)
534
+ (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 )
535
+ (toupper((s->avctx->codec_tag>>16)&0xFF)<<16)
536
+ (toupper((s->avctx->codec_tag>>24)&0xFF)<<24);
552
s->codec_tag = ff_toupper4(s->avctx->codec_tag);
538
s->stream_codec_tag= toupper( s->avctx->stream_codec_tag &0xFF)
539
+ (toupper((s->avctx->stream_codec_tag>>8 )&0xFF)<<8 )
540
+ (toupper((s->avctx->stream_codec_tag>>16)&0xFF)<<16)
541
+ (toupper((s->avctx->stream_codec_tag>>24)&0xFF)<<24);
554
s->stream_codec_tag = ff_toupper4(s->avctx->stream_codec_tag);
543
556
s->avctx->coded_frame= (AVFrame*)&s->current_picture;
612
625
if (s->out_format == FMT_H263) {
614
FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail);
615
s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
616
s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
617
s->ac_val[2] = s->ac_val[1] + c_size;
620
627
FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);
621
628
s->coded_block= s->coded_block_base + s->b8_stride + 1;
959
965
s->current_picture_ptr= pic;
960
s->current_picture_ptr->top_field_first= s->top_field_first; //FIXME use only the vars from current_pic
966
//FIXME use only the vars from current_pic
967
s->current_picture_ptr->top_field_first= s->top_field_first;
968
if(s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) {
969
if(s->picture_structure != PICT_FRAME)
970
s->current_picture_ptr->top_field_first= (s->picture_structure == PICT_TOP_FIELD) == s->first_field;
961
972
s->current_picture_ptr->interlaced_frame= !s->progressive_frame && !s->progressive_sequence;
1056
1069
&& s->current_picture.reference
1057
1070
&& !s->intra_only
1058
1071
&& !(s->flags&CODEC_FLAG_EMU_EDGE)) {
1059
s->dsp.draw_edges(s->current_picture.data[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH );
1060
s->dsp.draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
1061
s->dsp.draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
1072
s->dsp.draw_edges(s->current_picture.data[0], s->linesize ,
1073
s->h_edge_pos , s->v_edge_pos ,
1074
EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM);
1075
s->dsp.draw_edges(s->current_picture.data[1], s->uvlinesize,
1076
s->h_edge_pos>>1, s->v_edge_pos>>1,
1077
EDGE_WIDTH/2, EDGE_TOP | EDGE_BOTTOM);
1078
s->dsp.draw_edges(s->current_picture.data[2], s->uvlinesize,
1079
s->h_edge_pos>>1, s->v_edge_pos>>1,
1080
EDGE_WIDTH/2, EDGE_TOP | EDGE_BOTTOM);
1249
1268
av_log(s->avctx, AV_LOG_DEBUG, "?");
1252
if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264)
1271
if(IS_INTERLACED(mb_type))
1253
1272
av_log(s->avctx, AV_LOG_DEBUG, "=");
1255
1274
av_log(s->avctx, AV_LOG_DEBUG, " ");
1469
1488
if( (unsigned)src_x > h_edge_pos - (!!sx) - w
1470
1489
|| (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){
1471
ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
1490
s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
1472
1491
src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
1473
1492
src= s->edge_emu_buffer;
1542
1561
if( (unsigned)src_x > h_edge_pos - (!!sx) - 2*block_s
1543
1562
|| (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){
1544
ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
1563
s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
1545
1564
src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
1546
1565
ptr_y = s->edge_emu_buffer;
1547
1566
if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
1548
1567
uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
1549
ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based,
1568
s->dsp.emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based,
1550
1569
uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
1551
ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
1570
s->dsp.emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
1552
1571
uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
1554
1573
ptr_cr= uvbuf+16;
1614
1633
if(s->flags&CODEC_FLAG_EMU_EDGE){
1615
1634
if( (unsigned)src_x > h_edge_pos - (!!sx) - block_s
1616
1635
|| (unsigned)src_y > v_edge_pos - (!!sy) - block_s){
1617
ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos);
1636
s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos);
1618
1637
ptr= s->edge_emu_buffer;
1626
1645
ptr = ref_picture[2] + offset;
1628
ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos);
1647
s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos);
1629
1648
ptr= s->edge_emu_buffer;
1631
1650
pix_op[op_index](dest_cr, ptr, s->uvlinesize, block_s, sx, sy);
1639
1658
* @param dest_cr chroma cr/v destination pointer
1640
1659
* @param dir direction (0->forward, 1->backward)
1641
1660
* @param ref_picture array[3] of pointers to the 3 planes of the reference picture
1642
* @param pic_op halfpel motion compensation function (average or put normally)
1661
* @param pix_op halfpel motion compensation function (average or put normally)
1643
1662
* the motion vectors are taken from s->mv and the MV type from s->mv_type
1645
1664
static inline void MPV_motion_lowres(MpegEncContext *s,
1947
1966
/* skip dequant / idct if we are really late ;) */
1948
1968
if(s->hurry_up>1) goto skip_idct;
1949
1970
if(s->avctx->skip_idct){
1950
1971
if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == FF_B_TYPE)
1951
1972
||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != FF_I_TYPE)