Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.49 KB | None | 0 0
  1. diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
  2. index dc3de30..0256f41 100644
  3. --- a/libavcodec/ituh263dec.c
  4. +++ b/libavcodec/ituh263dec.c
  5. @@ -1095,7 +1095,6 @@ int ff_h263_decode_picture_header(MpegEncContext *s)
  6. s->pp_time = 2;
  7. s->pb_time = 1;
  8. }
  9. - ff_mpeg4_init_direct_mv(s);
  10. }
  11.  
  12. /* PEI */
  13. diff --git a/libavcodec/mpeg4video.c b/libavcodec/mpeg4video.c
  14. index 84fa26b..69e469b 100644
  15. --- a/libavcodec/mpeg4video.c
  16. +++ b/libavcodec/mpeg4video.c
  17. @@ -74,23 +74,26 @@ void ff_mpeg4_clean_buffers(MpegEncContext *s)
  18. s->last_mv[1][0][1] = 0;
  19. }
  20.  
  21. -#define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
  22. +Mpeg4DecContext *ctx;
  23. +
  24. +#define tab_size ((signed)FF_ARRAY_ELEMS(ctx->direct_scale_mv[0]))
  25. #define tab_bias (tab_size / 2)
  26.  
  27. -// used by mpeg4 and rv10 decoder
  28. -void ff_mpeg4_init_direct_mv(MpegEncContext *s)
  29. +void ff_mpeg4_init_direct_mv(Mpeg4DecContext *ctx)
  30. {
  31. int i;
  32. + MpegEncContext *s = &ctx->m;
  33. for (i = 0; i < tab_size; i++) {
  34. - s->direct_scale_mv[0][i] = (i - tab_bias) * s->pb_time / s->pp_time;
  35. - s->direct_scale_mv[1][i] = (i - tab_bias) * (s->pb_time - s->pp_time) /
  36. + ctx->direct_scale_mv[0][i] = (i - tab_bias) * s->pb_time / s->pp_time;
  37. + ctx->direct_scale_mv[1][i] = (i - tab_bias) * (s->pb_time - s->pp_time) /
  38. s->pp_time;
  39. }
  40. }
  41.  
  42. -static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx,
  43. +static inline void ff_mpeg4_set_one_direct_mv(Mpeg4DecContext *ctx, int mx,
  44. int my, int i)
  45. {
  46. + MpegEncContext *s = &ctx->m;
  47. int xy = s->block_index[i];
  48. uint16_t time_pp = s->pp_time;
  49. uint16_t time_pb = s->pb_time;
  50. @@ -98,9 +101,9 @@ static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx,
  51.  
  52. p_mx = s->next_picture.motion_val[0][xy][0];
  53. if ((unsigned)(p_mx + tab_bias) < tab_size) {
  54. - s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias] + mx;
  55. + s->mv[0][i][0] = ctx->direct_scale_mv[0][p_mx + tab_bias] + mx;
  56. s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
  57. - : s->direct_scale_mv[1][p_mx + tab_bias];
  58. + : ctx->direct_scale_mv[1][p_mx + tab_bias];
  59. } else {
  60. s->mv[0][i][0] = p_mx * time_pb / time_pp + mx;
  61. s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
  62. @@ -108,9 +111,9 @@ static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx,
  63. }
  64. p_my = s->next_picture.motion_val[0][xy][1];
  65. if ((unsigned)(p_my + tab_bias) < tab_size) {
  66. - s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias] + my;
  67. + s->mv[0][i][1] = ctx->direct_scale_mv[0][p_my + tab_bias] + my;
  68. s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my
  69. - : s->direct_scale_mv[1][p_my + tab_bias];
  70. + : ctx->direct_scale_mv[1][p_my + tab_bias];
  71. } else {
  72. s->mv[0][i][1] = p_my * time_pb / time_pp + my;
  73. s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my
  74. @@ -126,11 +129,16 @@ static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx,
  75. */
  76. int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
  77. {
  78. + Mpeg4DecContext *ctx;
  79. const int mb_index = s->mb_x + s->mb_y * s->mb_stride;
  80. const int colocated_mb_type = s->next_picture.mb_type[mb_index];
  81. uint16_t time_pp;
  82. uint16_t time_pb;
  83. int i;
  84. + ctx = av_malloc(sizeof(Mpeg4DecContext));
  85. + if (!ctx)
  86. + return AVERROR(ENOMEM);
  87. + ctx->m = *s;
  88.  
  89. // FIXME avoid divides
  90. // try special case with shifts for 1 and 3 B-frames?
  91. @@ -138,7 +146,7 @@ int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
  92. if (IS_8X8(colocated_mb_type)) {
  93. s->mv_type = MV_TYPE_8X8;
  94. for (i = 0; i < 4; i++)
  95. - ff_mpeg4_set_one_direct_mv(s, mx, my, i);
  96. + ff_mpeg4_set_one_direct_mv(ctx, mx, my, i);
  97. return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1;
  98. } else if (IS_INTERLACED(colocated_mb_type)) {
  99. s->mv_type = MV_TYPE_FIELD;
  100. @@ -169,7 +177,7 @@ int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
  101. return MB_TYPE_DIRECT2 | MB_TYPE_16x8 |
  102. MB_TYPE_L0L1 | MB_TYPE_INTERLACED;
  103. } else {
  104. - ff_mpeg4_set_one_direct_mv(s, mx, my, 0);
  105. + ff_mpeg4_set_one_direct_mv(ctx, mx, my, 0);
  106. s->mv[0][1][0] =
  107. s->mv[0][2][0] =
  108. s->mv[0][3][0] = s->mv[0][0][0];
  109. diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
  110. index b092684..a87ccfb 100644
  111. --- a/libavcodec/mpeg4video.h
  112. +++ b/libavcodec/mpeg4video.h
  113. @@ -100,6 +100,9 @@ typedef struct Mpeg4DecContext {
  114. int cplx_estimation_trash_i;
  115. int cplx_estimation_trash_p;
  116. int cplx_estimation_trash_b;
  117. +
  118. + int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
  119. +
  120. } Mpeg4DecContext;
  121.  
  122. /* dc encoding for mpeg4 */
  123. @@ -147,7 +150,7 @@ void ff_clean_mpeg4_qscales(MpegEncContext *s);
  124. int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx);
  125. int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
  126. int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx);
  127. -void ff_mpeg4_init_direct_mv(MpegEncContext *s);
  128. +void ff_mpeg4_init_direct_mv(Mpeg4DecContext *ctx);
  129. int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
  130.  
  131. /**
  132. diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
  133. index 199e3b3..b1db0e1 100644
  134. --- a/libavcodec/mpeg4videodec.c
  135. +++ b/libavcodec/mpeg4videodec.c
  136. @@ -2151,7 +2151,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
  137. /* messed up order, maybe after seeking? skipping current b-frame */
  138. return FRAME_SKIPPED;
  139. }
  140. - ff_mpeg4_init_direct_mv(s);
  141. + ff_mpeg4_init_direct_mv(ctx);
  142.  
  143. if (ctx->t_frame == 0)
  144. ctx->t_frame = s->pb_time;
  145. diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
  146. index 6b87ec7..cb05914 100644
  147. --- a/libavcodec/mpeg4videoenc.c
  148. +++ b/libavcodec/mpeg4videoenc.c
  149. @@ -890,9 +890,7 @@ void ff_mpeg4_stuffing(PutBitContext *pbc)
  150. /* must be called before writing the header */
  151. void ff_set_mpeg4_time(MpegEncContext *s)
  152. {
  153. - if (s->pict_type == AV_PICTURE_TYPE_B) {
  154. - ff_mpeg4_init_direct_mv(s);
  155. - } else {
  156. + if (s->pict_type != AV_PICTURE_TYPE_B) {
  157. s->last_time_base = s->time_base;
  158. s->time_base = s->time / s->avctx->time_base.den;
  159. }
  160. diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
  161. index 1333d44..6e36fda 100644
  162. --- a/libavcodec/mpegvideo.h
  163. +++ b/libavcodec/mpegvideo.h
  164. @@ -399,7 +399,6 @@ typedef struct MpegEncContext {
  165. int field_select[2][2];
  166. int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG1 & B-frame MPEG4
  167. uint8_t *fcode_tab; ///< smallest fcode needed for each MV
  168. - int16_t direct_scale_mv[2][64]; ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
  169.  
  170. MotionEstContext me;
  171.  
  172. diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
  173. index 835a1aa..3d1b51d 100644
  174. --- a/libavcodec/rv10.c
  175. +++ b/libavcodec/rv10.c
  176. @@ -412,7 +412,6 @@ static int rv20_decode_picture_header(RVDecContext *rv)
  177. "from seeking? skipping current b frame\n");
  178. return FRAME_SKIPPED;
  179. }
  180. - ff_mpeg4_init_direct_mv(s);
  181. }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement