Libav
mpeg_er.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "error_resilience.h"
20 #include "mpegvideo.h"
21 #include "mpeg_er.h"
22 
23 static void set_erpic(ERPicture *dst, Picture *src)
24 {
25  int i;
26 
27  if (!src) {
28  dst->f = NULL;
29  dst->tf = NULL;
30  return;
31  }
32 
33  dst->f = src->f;
34  dst->tf = &src->tf;
35 
36  for (i = 0; i < 2; i++) {
37  dst->motion_val[i] = src->motion_val[i];
38  dst->ref_index[i] = src->ref_index[i];
39  }
40 
41  dst->mb_type = src->mb_type;
42  dst->field_picture = src->field_picture;
43 }
44 
46 {
47  ERContext *er = &s->er;
48 
52 
53  er->pp_time = s->pp_time;
54  er->pb_time = s->pb_time;
57 
59 }
60 
61 static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
62  int (*mv)[2][4][2], int mb_x, int mb_y,
63  int mb_intra, int mb_skipped)
64 {
65  MpegEncContext *s = opaque;
66 
67  s->mv_dir = mv_dir;
68  s->mv_type = mv_type;
69  s->mb_intra = mb_intra;
70  s->mb_skipped = mb_skipped;
71  s->mb_x = mb_x;
72  s->mb_y = mb_y;
73  memcpy(s->mv, mv, sizeof(*mv));
74 
77 
78  s->bdsp.clear_blocks(s->block[0]);
79 
80  s->dest[0] = s->current_picture.f->data[0] +
81  s->mb_y * 16 * s->linesize +
82  s->mb_x * 16;
83  s->dest[1] = s->current_picture.f->data[1] +
84  s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
85  s->mb_x * (16 >> s->chroma_x_shift);
86  s->dest[2] = s->current_picture.f->data[2] +
87  s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
88  s->mb_x * (16 >> s->chroma_x_shift);
89 
90  if (ref)
92  "Interlaced error concealment is not fully implemented\n");
93  ff_mpv_decode_mb(s, s->block);
94 }
95 
97 {
98  ERContext *er = &s->er;
99  int mb_array_size = s->mb_height * s->mb_stride;
100  int i;
101 
102  er->avctx = s->avctx;
103 
104  er->mb_index2xy = s->mb_index2xy;
105  er->mb_num = s->mb_num;
106  er->mb_width = s->mb_width;
107  er->mb_height = s->mb_height;
108  er->mb_stride = s->mb_stride;
109  er->b8_stride = s->b8_stride;
110 
112  er->error_status_table = av_mallocz(mb_array_size);
113  if (!er->er_temp_buffer || !er->error_status_table)
114  goto fail;
115 
116  er->mbskip_table = s->mbskip_table;
117  er->mbintra_table = s->mbintra_table;
118 
119  for (i = 0; i < FF_ARRAY_ELEMS(s->dc_val); i++)
120  er->dc_val[i] = s->dc_val[i];
121 
123  er->opaque = s;
124 
125  return 0;
126 fail:
127  av_freep(&er->er_temp_buffer);
129  return AVERROR(ENOMEM);
130 }
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:1744
int8_t * ref_index[2]
Definition: mpegpicture.h:62
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
int field_picture
whether or not the picture was encoded in separate fields
Definition: mpegpicture.h:76
uint32_t * mb_type
ERPicture last_pic
mpegvideo header.
#define FF_ARRAY_ELEMS(a)
int mb_num
number of MBs of a picture
Definition: mpegvideo.h:128
int chroma_x_shift
Definition: mpegvideo.h:459
uint16_t pp_time
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, int(*mv)[2][4][2], int mb_x, int mb_y, int mb_intra, int mb_skipped)
Definition: mpeg_er.c:61
void ff_mpv_decode_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo.c:1727
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:175
ERPicture cur_pic
uint16_t pp_time
time distance between the last 2 p,s,i frames
Definition: mpegvideo.h:377
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:124
static void ff_update_block_index(MpegEncContext *s)
Definition: mpegvideo.h:680
ThreadFrame tf
Definition: mpegpicture.h:47
#define src
Definition: vp8dsp.c:254
int16_t * dc_val[3]
used for MPEG-4 DC prediction, all 3 arrays must be continuous
Definition: mpegvideo.h:182
int mb_skipped
MUST BE SET only during DECODING.
Definition: mpegvideo.h:190
int chroma_y_shift
Definition: mpegvideo.h:460
int partitioned_frame
is current frame partitioned
Definition: mpegvideo.h:390
#define AVERROR(e)
Definition: error.h:43
void(* clear_blocks)(int16_t *blocks)
Definition: blockdsp.h:36
ERContext er
Definition: mpegvideo.h:528
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
ThreadFrame * tf
int quarter_sample
1->qpel, 0->half pel ME/MC
Definition: mpegvideo.h:386
static void set_erpic(ERPicture *dst, Picture *src)
Definition: mpeg_er.c:23
#define fail()
Definition: checkasm.h:80
uint8_t * mbintra_table
int * mb_index2xy
uint8_t * error_status_table
int ff_mpeg_er_init(MpegEncContext *s)
Definition: mpeg_er.c:96
uint8_t * er_temp_buffer
uint8_t * mbskip_table
used to avoid copy if macroblock skipped (for black regions for example) and used for B-frame encodin...
Definition: mpegvideo.h:191
int16_t(*[2] motion_val)[2]
Definition: mpegpicture.h:53
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:179
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:45
Picture.
Definition: mpegpicture.h:45
uint16_t pb_time
uint8_t * mbintra_table
used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
Definition: mpegvideo.h:193
int * mb_index2xy
mb_index -> mb_x + mb_y*mb_stride
Definition: mpegvideo.h:291
static const int8_t mv[256][2]
Definition: 4xm.c:75
NULL
Definition: eval.c:55
ptrdiff_t linesize
line size, in bytes, may be different from width
Definition: mpegvideo.h:129
BlockDSPContext bdsp
Definition: mpegvideo.h:218
ERPicture next_pic
struct AVFrame * f
Definition: mpegpicture.h:46
ptrdiff_t uvlinesize
line size, for chroma in bytes, may be different from width
Definition: mpegvideo.h:130
AVCodecContext * avctx
int8_t * ref_index[2]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
Definition: mpegvideo.h:270
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
Definition: mpegvideo.h:126
MpegEncContext.
Definition: mpegvideo.h:76
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
Definition: mpegvideo.h:178
struct AVCodecContext * avctx
Definition: mpegvideo.h:93
int partitioned_frame
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
Definition: mpegvideo.h:125
uint8_t * dest[3]
Definition: mpegvideo.h:289
int16_t * dc_val[3]
Picture * last_picture_ptr
pointer to the previous picture.
Definition: mpegvideo.h:177
AVFrame * f
int16_t(*[2] motion_val)[2]
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:476
void ff_er_frame_start(ERContext *s)
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegpicture.h:56
uint8_t * mbskip_table
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:211
void(* decode_mb)(void *opaque, int ref, int mv_dir, int mv_type, int(*mv)[2][4][2], int mb_x, int mb_y, int mb_intra, int mb_skipped)
uint16_t pb_time
time distance between the last b and p,s,i frame
Definition: mpegvideo.h:378