]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpegvideo_common.h
uses FF_ARRAY_ELEMS() where appropriate
[ffmpeg] / libavcodec / mpegvideo_common.h
index 2be817261b83b6d2590c9b7268bd93b80b45e963..6875e8531392224833d20ca212066ddf72822b9e 100644 (file)
@@ -27,8 +27,8 @@
  * The simplest mpeg encoder (well, it was the simplest!).
  */
 
-#ifndef FFMPEG_MPEGVIDEO_COMMON_H
-#define FFMPEG_MPEGVIDEO_COMMON_H
+#ifndef AVCODEC_MPEGVIDEO_COMMON_H
+#define AVCODEC_MPEGVIDEO_COMMON_H
 
 #include "avcodec.h"
 #include "dsputil.h"
@@ -41,7 +41,6 @@
 int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
 int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
 void  denoise_dct_c(MpegEncContext *s, DCTELEM *block);
-void copy_picture(Picture *dst, Picture *src);
 
 /**
  * allocates a Picture
@@ -237,15 +236,16 @@ static inline int hpel_motion(MpegEncContext *s,
     return emu;
 }
 
-/* apply one mpeg motion vector to the three components */
-static av_always_inline void mpeg_motion(MpegEncContext *s,
-                               uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
-                               int field_based, int bottom_field, int field_select,
-                               uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
-                               int motion_x, int motion_y, int h)
+static av_always_inline
+void mpeg_motion_internal(MpegEncContext *s,
+                 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+                 int field_based, int bottom_field, int field_select,
+                 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
+                 int motion_x, int motion_y, int h, int is_mpeg12)
 {
     uint8_t *ptr_y, *ptr_cb, *ptr_cr;
-    int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
+    int dxy, uvdxy, mx, my, src_x, src_y,
+        uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
 
 #if 0
 if(s->quarter_sample)
@@ -263,7 +263,7 @@ if(s->quarter_sample)
     src_x = s->mb_x* 16               + (motion_x >> 1);
     src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1);
 
-    if (s->out_format == FMT_H263) {
+    if (!is_mpeg12 && s->out_format == FMT_H263) {
         if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){
             mx = (motion_x>>1)|(motion_x&1);
             my = motion_y >>1;
@@ -275,7 +275,7 @@ if(s->quarter_sample)
             uvsrc_x = src_x>>1;
             uvsrc_y = src_y>>1;
         }
-    }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261
+    }else if(!is_mpeg12 && s->out_format == FMT_H261){//even chroma mv's are full pel in H261
         mx = motion_x / 4;
         my = motion_y / 4;
         uvdxy = 0;
@@ -310,20 +310,29 @@ if(s->quarter_sample)
 
     if(   (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16
        || (unsigned)src_y >    v_edge_pos - (motion_y&1) - h){
-            if(s->codec_id == CODEC_ID_MPEG2VIDEO ||
+            if(is_mpeg12 || s->codec_id == CODEC_ID_MPEG2VIDEO ||
                s->codec_id == CODEC_ID_MPEG1VIDEO){
-                av_log(s->avctx,AV_LOG_DEBUG,"MPEG motion vector out of boundary\n");
+                av_log(s->avctx,AV_LOG_DEBUG,
+                        "MPEG motion vector out of boundary\n");
                 return ;
             }
-            ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
-                             src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
+            ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize,
+                                17, 17+field_based,
+                                src_x, src_y<<field_based,
+                                s->h_edge_pos, s->v_edge_pos);
             ptr_y = s->edge_emu_buffer;
             if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
                 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
-                ff_emulated_edge_mc(uvbuf  , ptr_cb, s->uvlinesize, 9, 9+field_based,
-                                 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
-                ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
-                                 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
+                ff_emulated_edge_mc(uvbuf ,
+                                    ptr_cb, s->uvlinesize,
+                                    9, 9+field_based,
+                                    uvsrc_x, uvsrc_y<<field_based,
+                                    s->h_edge_pos>>1, s->v_edge_pos>>1);
+                ff_emulated_edge_mc(uvbuf+16,
+                                    ptr_cr, s->uvlinesize,
+                                    9, 9+field_based,
+                                    uvsrc_x, uvsrc_y<<field_based,
+                                    s->h_edge_pos>>1, s->v_edge_pos>>1);
                 ptr_cb= uvbuf;
                 ptr_cr= uvbuf+16;
             }
@@ -344,13 +353,35 @@ if(s->quarter_sample)
     pix_op[0][dxy](dest_y, ptr_y, linesize, h);
 
     if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
-        pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
-        pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
+        pix_op[s->chroma_x_shift][uvdxy]
+                (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
+        pix_op[s->chroma_x_shift][uvdxy]
+                (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
     }
-    if((ENABLE_H261_ENCODER || ENABLE_H261_DECODER) && s->out_format == FMT_H261){
+    if(!is_mpeg12 && (ENABLE_H261_ENCODER || ENABLE_H261_DECODER) &&
+         s->out_format == FMT_H261){
         ff_h261_loop_filter(s);
     }
 }
+/* apply one mpeg motion vector to the three components */
+static av_always_inline
+void mpeg_motion(MpegEncContext *s,
+                 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+                 int field_based, int bottom_field, int field_select,
+                 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
+                 int motion_x, int motion_y, int h)
+{
+#ifndef CONFIG_SMALL
+    if(s->out_format == FMT_MPEG1)
+        mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based,
+                    bottom_field, field_select, ref_picture, pix_op,
+                    motion_x, motion_y, h, 1);
+    else
+#endif
+        mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based,
+                    bottom_field, field_select, ref_picture, pix_op,
+                    motion_x, motion_y, h, 0);
+}
 
 //FIXME move to dsputil, avg variant, 16x16 version
 static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){
@@ -482,15 +513,20 @@ static inline void qpel_motion(MpegEncContext *s,
 
     if(   (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16
        || (unsigned)src_y >    v_edge_pos - (motion_y&3) - h  ){
-        ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
-                         src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
+        ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize,
+                            17, 17+field_based, src_x, src_y<<field_based,
+                            s->h_edge_pos, s->v_edge_pos);
         ptr_y= s->edge_emu_buffer;
         if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
             uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
-            ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, 9, 9 + field_based,
-                             uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
-            ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, 9 + field_based,
-                             uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
+            ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize,
+                                9, 9 + field_based,
+                                uvsrc_x, uvsrc_y<<field_based,
+                                s->h_edge_pos>>1, s->v_edge_pos>>1);
+            ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize,
+                                9, 9 + field_based,
+                                uvsrc_x, uvsrc_y<<field_based,
+                                s->h_edge_pos>>1, s->v_edge_pos>>1);
             ptr_cb= uvbuf;
             ptr_cr= uvbuf + 16;
         }
@@ -555,7 +591,9 @@ static inline void chroma_4mv_motion(MpegEncContext *s,
     if(s->flags&CODEC_FLAG_EMU_EDGE){
         if(   (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8
            || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){
-            ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
+            ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize,
+                                9, 9, src_x, src_y,
+                                s->h_edge_pos>>1, s->v_edge_pos>>1);
             ptr= s->edge_emu_buffer;
             emu=1;
         }
@@ -564,7 +602,9 @@ static inline void chroma_4mv_motion(MpegEncContext *s,
 
     ptr = ref_picture[2] + offset;
     if(emu){
-        ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
+        ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize,
+                            9, 9, src_x, src_y,
+                            s->h_edge_pos>>1, s->v_edge_pos>>1);
         ptr= s->edge_emu_buffer;
     }
     pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8);
@@ -594,10 +634,12 @@ static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){
  * @param pic_op qpel motion compensation function (average or put normally)
  * the motion vectors are taken from s->mv and the MV type from s->mv_type
  */
-static inline void MPV_motion(MpegEncContext *s,
-                              uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
-                              int dir, uint8_t **ref_picture,
-                              op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16])
+static av_always_inline void MPV_motion_internal(MpegEncContext *s,
+                              uint8_t *dest_y, uint8_t *dest_cb,
+                              uint8_t *dest_cr, int dir,
+                              uint8_t **ref_picture,
+                              op_pixels_func (*pix_op)[4],
+                              qpel_mc_func (*qpix_op)[16], int is_mpeg12)
 {
     int dxy, mx, my, src_x, src_y, motion_x, motion_y;
     int mb_x, mb_y, i;
@@ -608,7 +650,7 @@ static inline void MPV_motion(MpegEncContext *s,
 
     prefetch_motion(s, ref_picture, dir);
 
-    if(s->obmc && s->pict_type != FF_B_TYPE){
+    if(!is_mpeg12 && s->obmc && s->pict_type != FF_B_TYPE){
         int16_t mv_cache[4][4][2];
         const int xy= s->mb_x + s->mb_y*s->mb_stride;
         const int mot_stride= s->b8_stride;
@@ -679,12 +721,12 @@ static inline void MPV_motion(MpegEncContext *s,
                 gmc_motion(s, dest_y, dest_cb, dest_cr,
                             ref_picture);
             }
-        }else if(s->quarter_sample){
+        }else if(!is_mpeg12 && s->quarter_sample){
             qpel_motion(s, dest_y, dest_cb, dest_cr,
                         0, 0, 0,
                         ref_picture, pix_op, qpix_op,
                         s->mv[dir][0][0], s->mv[dir][0][1], 16);
-        }else if(ENABLE_WMV2 && s->mspel){
+        }else if(!is_mpeg12 && ENABLE_WMV2 && s->mspel){
             ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
                         ref_picture, pix_op,
                         s->mv[dir][0][0], s->mv[dir][0][1], 16);
@@ -697,6 +739,7 @@ static inline void MPV_motion(MpegEncContext *s,
         }
         break;
     case MV_TYPE_8X8:
+    if (!is_mpeg12) {
         mx = 0;
         my = 0;
         if(s->quarter_sample){
@@ -720,7 +763,10 @@ static inline void MPV_motion(MpegEncContext *s,
                 if(s->flags&CODEC_FLAG_EMU_EDGE){
                     if(   (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8
                        || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){
-                        ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
+                        ff_emulated_edge_mc(s->edge_emu_buffer, ptr,
+                                            s->linesize, 9, 9,
+                                            src_x, src_y,
+                                            s->h_edge_pos, s->v_edge_pos);
                         ptr= s->edge_emu_buffer;
                     }
                 }
@@ -747,10 +793,11 @@ static inline void MPV_motion(MpegEncContext *s,
 
         if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
             chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
+    }
         break;
     case MV_TYPE_FIELD:
         if (s->picture_structure == PICT_FRAME) {
-            if(s->quarter_sample){
+            if(!is_mpeg12 && s->quarter_sample){
                 for(i=0; i<2; i++){
                     qpel_motion(s, dest_y, dest_cb, dest_cr,
                                 1, i, s->field_select[dir][i],
@@ -784,7 +831,8 @@ static inline void MPV_motion(MpegEncContext *s,
         for(i=0; i<2; i++){
             uint8_t ** ref2picture;
 
-            if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == FF_B_TYPE || s->first_field){
+            if(s->picture_structure == s->field_select[dir][i] + 1
+               || s->pict_type == FF_B_TYPE || s->first_field){
                 ref2picture= ref_picture;
             }else{
                 ref2picture= s->current_picture_ptr->data;
@@ -833,4 +881,20 @@ static inline void MPV_motion(MpegEncContext *s,
     }
 }
 
-#endif /* FFMPEG_MPEGVIDEO_COMMON_H */
+static inline void MPV_motion(MpegEncContext *s,
+                              uint8_t *dest_y, uint8_t *dest_cb,
+                              uint8_t *dest_cr, int dir,
+                              uint8_t **ref_picture,
+                              op_pixels_func (*pix_op)[4],
+                              qpel_mc_func (*qpix_op)[16])
+{
+#ifndef CONFIG_SMALL
+    if(s->out_format == FMT_MPEG1)
+        MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
+                            ref_picture, pix_op, qpix_op, 1);
+    else
+#endif
+        MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
+                            ref_picture, pix_op, qpix_op, 0);
+}
+#endif /* AVCODEC_MPEGVIDEO_COMMON_H */