You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.8KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "error_resilience.h"
  19. #include "mpegvideo.h"
  20. #include "mpeg_er.h"
  21. static void set_erpic(ERPicture *dst, Picture *src)
  22. {
  23. int i;
  24. memset(dst, 0, sizeof(*dst));
  25. if (!src) {
  26. dst->f = NULL;
  27. dst->tf = NULL;
  28. return;
  29. }
  30. dst->f = src->f;
  31. dst->tf = &src->tf;
  32. for (i = 0; i < 2; i++) {
  33. dst->motion_val[i] = src->motion_val[i];
  34. dst->ref_index[i] = src->ref_index[i];
  35. }
  36. dst->mb_type = src->mb_type;
  37. dst->field_picture = src->field_picture;
  38. }
  39. void ff_mpeg_er_frame_start(MpegEncContext *s)
  40. {
  41. ERContext *er = &s->er;
  42. set_erpic(&er->cur_pic, s->current_picture_ptr);
  43. set_erpic(&er->next_pic, s->next_picture_ptr);
  44. set_erpic(&er->last_pic, s->last_picture_ptr);
  45. er->pp_time = s->pp_time;
  46. er->pb_time = s->pb_time;
  47. er->quarter_sample = s->quarter_sample;
  48. er->partitioned_frame = s->partitioned_frame;
  49. ff_er_frame_start(er);
  50. }
  51. static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
  52. int (*mv)[2][4][2], int mb_x, int mb_y,
  53. int mb_intra, int mb_skipped)
  54. {
  55. MpegEncContext *s = opaque;
  56. s->mv_dir = mv_dir;
  57. s->mv_type = mv_type;
  58. s->mb_intra = mb_intra;
  59. s->mb_skipped = mb_skipped;
  60. s->mb_x = mb_x;
  61. s->mb_y = mb_y;
  62. s->mcsel = 0;
  63. memcpy(s->mv, mv, sizeof(*mv));
  64. ff_init_block_index(s);
  65. ff_update_block_index(s);
  66. s->bdsp.clear_blocks(s->block[0]);
  67. s->dest[0] = s->current_picture.f->data[0] +
  68. s->mb_y * 16 * s->linesize +
  69. s->mb_x * 16;
  70. s->dest[1] = s->current_picture.f->data[1] +
  71. s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
  72. s->mb_x * (16 >> s->chroma_x_shift);
  73. s->dest[2] = s->current_picture.f->data[2] +
  74. s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
  75. s->mb_x * (16 >> s->chroma_x_shift);
  76. if (ref)
  77. av_log(s->avctx, AV_LOG_DEBUG,
  78. "Interlaced error concealment is not fully implemented\n");
  79. ff_mpv_decode_mb(s, s->block);
  80. }
  81. int ff_mpeg_er_init(MpegEncContext *s)
  82. {
  83. ERContext *er = &s->er;
  84. int mb_array_size = s->mb_height * s->mb_stride;
  85. int i;
  86. er->avctx = s->avctx;
  87. er->mb_index2xy = s->mb_index2xy;
  88. er->mb_num = s->mb_num;
  89. er->mb_width = s->mb_width;
  90. er->mb_height = s->mb_height;
  91. er->mb_stride = s->mb_stride;
  92. er->b8_stride = s->b8_stride;
  93. er->er_temp_buffer = av_malloc(s->mb_height * s->mb_stride);
  94. er->error_status_table = av_mallocz(mb_array_size);
  95. if (!er->er_temp_buffer || !er->error_status_table)
  96. goto fail;
  97. er->mbskip_table = s->mbskip_table;
  98. er->mbintra_table = s->mbintra_table;
  99. for (i = 0; i < FF_ARRAY_ELEMS(s->dc_val); i++)
  100. er->dc_val[i] = s->dc_val[i];
  101. er->decode_mb = mpeg_er_decode_mb;
  102. er->opaque = s;
  103. return 0;
  104. fail:
  105. av_freep(&er->er_temp_buffer);
  106. av_freep(&er->error_status_table);
  107. return AVERROR(ENOMEM);
  108. }