FFmpeg
mpeg_er.c
Go to the documentation of this file.
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 
19 #include "error_resilience.h"
20 #include "mpegvideo.h"
21 #include "mpegvideodec.h"
22 #include "mpeg_er.h"
23 
24 static void set_erpic(ERPicture *dst, Picture *src)
25 {
26  int i;
27 
28  memset(dst, 0, sizeof(*dst));
29  if (!src) {
30  dst->f = NULL;
31  dst->tf = NULL;
32  return;
33  }
34 
35  dst->f = src->f;
36  dst->tf = &src->tf;
37 
38  for (i = 0; i < 2; i++) {
39  dst->motion_val[i] = src->motion_val[i];
40  dst->ref_index[i] = src->ref_index[i];
41  }
42 
43  dst->mb_type = src->mb_type;
44  dst->field_picture = src->field_picture;
45 }
46 
48 {
49  ERContext *er = &s->er;
50 
51  set_erpic(&er->cur_pic, s->current_picture_ptr);
52  set_erpic(&er->next_pic, s->next_picture_ptr);
53  set_erpic(&er->last_pic, s->last_picture_ptr);
54 
55  er->pp_time = s->pp_time;
56  er->pb_time = s->pb_time;
57  er->quarter_sample = s->quarter_sample;
58  er->partitioned_frame = s->partitioned_frame;
59 
61 }
62 
63 static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
64  int (*mv)[2][4][2], int mb_x, int mb_y,
65  int mb_intra, int mb_skipped)
66 {
67  MpegEncContext *s = opaque;
68 
69  s->mv_dir = mv_dir;
70  s->mv_type = mv_type;
71  s->mb_intra = mb_intra;
72  s->mb_skipped = mb_skipped;
73  s->mb_x = mb_x;
74  s->mb_y = mb_y;
75  s->mcsel = 0;
76  memcpy(s->mv, mv, sizeof(*mv));
77 
79  ff_update_block_index(s, s->avctx->bits_per_raw_sample,
80  s->avctx->lowres, s->chroma_x_shift);
81 
82  s->bdsp.clear_blocks(s->block[0]);
83  if (!s->chroma_y_shift)
84  s->bdsp.clear_blocks(s->block[6]);
85 
86  s->dest[0] = s->current_picture.f->data[0] +
87  s->mb_y * 16 * s->linesize +
88  s->mb_x * 16;
89  s->dest[1] = s->current_picture.f->data[1] +
90  s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
91  s->mb_x * (16 >> s->chroma_x_shift);
92  s->dest[2] = s->current_picture.f->data[2] +
93  s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
94  s->mb_x * (16 >> s->chroma_x_shift);
95 
96  if (ref)
97  av_log(s->avctx, AV_LOG_DEBUG,
98  "Interlaced error concealment is not fully implemented\n");
99  ff_mpv_reconstruct_mb(s, s->block);
100 }
101 
103 {
104  ERContext *er = &s->er;
105  int mb_array_size = s->mb_height * s->mb_stride;
106  int i;
107 
108  er->avctx = s->avctx;
109 
110  er->mb_index2xy = s->mb_index2xy;
111  er->mb_num = s->mb_num;
112  er->mb_width = s->mb_width;
113  er->mb_height = s->mb_height;
114  er->mb_stride = s->mb_stride;
115  er->b8_stride = s->b8_stride;
116 
117  er->er_temp_buffer = av_malloc(s->mb_height * s->mb_stride * (4*sizeof(int) + 1));
118  er->error_status_table = av_mallocz(mb_array_size);
119  if (!er->er_temp_buffer || !er->error_status_table)
120  goto fail;
121 
122  er->mbskip_table = s->mbskip_table;
123  er->mbintra_table = s->mbintra_table;
124 
125  for (i = 0; i < FF_ARRAY_ELEMS(s->dc_val); i++)
126  er->dc_val[i] = s->dc_val[i];
127 
129  er->opaque = s;
130 
131  return 0;
132 fail:
133  av_freep(&er->er_temp_buffer);
135  return AVERROR(ENOMEM);
136 }
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ERContext::pb_time
uint16_t pb_time
Definition: error_resilience.h:81
mv
static const int8_t mv[256][2]
Definition: 4xm.c:80
ERPicture::ref_index
int8_t * ref_index[2]
Definition: error_resilience.h:46
ERContext::mbintra_table
uint8_t * mbintra_table
Definition: error_resilience.h:70
ERContext::mb_index2xy
int * mb_index2xy
Definition: error_resilience.h:58
ff_er_frame_start
void ff_er_frame_start(ERContext *s)
Definition: error_resilience.c:787
ERContext
Definition: error_resilience.h:52
ff_init_block_index
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:845
mpegvideo.h
Picture
Picture.
Definition: mpegpicture.h:46
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
ERPicture
Definition: error_resilience.h:40
ff_mpv_reconstruct_mb
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo_dec.c:1008
set_erpic
static void set_erpic(ERPicture *dst, Picture *src)
Definition: mpeg_er.c:24
ERContext::partitioned_frame
int partitioned_frame
Definition: error_resilience.h:83
fail
#define fail()
Definition: checkasm.h:179
ERPicture::motion_val
int16_t(*[2] motion_val)[2]
Definition: error_resilience.h:45
ERContext::mb_num
int mb_num
Definition: error_resilience.h:59
ERContext::avctx
AVCodecContext * avctx
Definition: error_resilience.h:53
mpegvideodec.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
ERPicture::field_picture
int field_picture
Definition: error_resilience.h:49
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_mpeg_er_frame_start
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:47
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ERContext::dc_val
int16_t * dc_val[3]
Definition: error_resilience.h:68
ERPicture::f
AVFrame * f
Definition: error_resilience.h:41
ERPicture::mb_type
uint32_t * mb_type
Definition: error_resilience.h:48
NULL
#define NULL
Definition: coverity.c:32
ERPicture::tf
const struct ThreadFrame * tf
Definition: error_resilience.h:42
ERContext::mbskip_table
uint8_t * mbskip_table
Definition: error_resilience.h:69
ERContext::opaque
void * opaque
Definition: error_resilience.h:88
ff_mpeg_er_init
int ff_mpeg_er_init(MpegEncContext *s)
Definition: mpeg_er.c:102
ff_update_block_index
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
Definition: mpegvideo.h:594
ERContext::b8_stride
ptrdiff_t b8_stride
Definition: error_resilience.h:62
ERContext::mb_stride
ptrdiff_t mb_stride
Definition: error_resilience.h:61
ERContext::decode_mb
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)
Definition: error_resilience.h:85
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
ERContext::mb_width
int mb_width
Definition: error_resilience.h:60
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
mpeg_er_decode_mb
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:63
ERContext::cur_pic
ERPicture cur_pic
Definition: error_resilience.h:73
ERContext::mb_height
int mb_height
Definition: error_resilience.h:60
ERContext::last_pic
ERPicture last_pic
Definition: error_resilience.h:74
error_resilience.h
ERContext::pp_time
uint16_t pp_time
Definition: error_resilience.h:80
ERContext::error_status_table
uint8_t * error_status_table
Definition: error_resilience.h:66
ERContext::quarter_sample
int quarter_sample
Definition: error_resilience.h:82
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
ERContext::er_temp_buffer
uint8_t * er_temp_buffer
Definition: error_resilience.h:67
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
mpeg_er.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:67
ERContext::next_pic
ERPicture next_pic
Definition: error_resilience.h:75