FFmpeg  4.0
intelh263dec.c
Go to the documentation of this file.
1 /*
2  * H.263i decoder
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "mpegutils.h"
22 #include "mpegvideo.h"
23 #include "h263.h"
24 #include "mpegvideodata.h"
25 
26 /* don't understand why they choose a different header ! */
28 {
29  int format;
30 
31  if (get_bits_left(&s->gb) == 64) { /* special dummy frames */
32  return FRAME_SKIPPED;
33  }
34 
35  /* picture header */
36  if (get_bits_long(&s->gb, 22) != 0x20) {
37  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
38  return -1;
39  }
40  s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
41 
42  if (check_marker(s->avctx, &s->gb, "after picture_number") != 1) {
43  return -1; /* marker */
44  }
45  if (get_bits1(&s->gb) != 0) {
46  av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
47  return -1; /* H.263 id */
48  }
49  skip_bits1(&s->gb); /* split screen off */
50  skip_bits1(&s->gb); /* camera off */
51  skip_bits1(&s->gb); /* freeze picture release off */
52 
53  format = get_bits(&s->gb, 3);
54  if (format == 0 || format == 6) {
55  av_log(s->avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
56  return -1;
57  }
58  s->h263_plus = 0;
59 
61 
62  s->h263_long_vectors = get_bits1(&s->gb);
63 
64  if (get_bits1(&s->gb) != 0) {
65  av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
66  return -1; /* SAC: off */
67  }
68  s->obmc= get_bits1(&s->gb);
70  s->pb_frame = get_bits1(&s->gb);
71 
72  if (format < 6) {
73  s->width = ff_h263_format[format][0];
74  s->height = ff_h263_format[format][1];
75  s->avctx->sample_aspect_ratio.num = 12;
76  s->avctx->sample_aspect_ratio.den = 11;
77  } else {
78  format = get_bits(&s->gb, 3);
79  if(format == 0 || format == 7){
80  av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
81  return -1;
82  }
83  if(get_bits(&s->gb, 2))
84  av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
85  s->loop_filter = get_bits1(&s->gb) * !s->avctx->lowres;
86  if(get_bits1(&s->gb))
87  av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
88  if(get_bits1(&s->gb))
89  s->pb_frame = 2;
90  if(get_bits(&s->gb, 5))
91  av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
92  if(get_bits(&s->gb, 5) != 1)
93  av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n");
94  }
95  if(format == 6){
96  int ar = get_bits(&s->gb, 4);
97  skip_bits(&s->gb, 9); // display width
98  check_marker(s->avctx, &s->gb, "in dimensions");
99  skip_bits(&s->gb, 9); // display height
100  if(ar == 15){
101  s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width
102  s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height
103  } else {
105  }
106  if (s->avctx->sample_aspect_ratio.num == 0)
107  av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
108  }
109 
110  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
111  skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
112 
113  if(s->pb_frame){
114  skip_bits(&s->gb, 3); //temporal reference for B-frame
115  skip_bits(&s->gb, 2); //dbquant
116  }
117 
118  /* PEI */
119  if (skip_1stop_8data_bits(&s->gb) < 0)
120  return AVERROR_INVALIDDATA;
121  s->f_code = 1;
122 
123  s->y_dc_scale_table=
125 
127 
128  return 0;
129 }
130 
132  .name = "h263i",
133  .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"),
134  .type = AVMEDIA_TYPE_VIDEO,
135  .id = AV_CODEC_ID_H263I,
136  .priv_data_size = sizeof(MpegEncContext),
138  .close = ff_h263_decode_end,
141  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
142  .pix_fmts = (const enum AVPixelFormat[]) {
145  },
146 };
int picture_number
Definition: mpegvideo.h:127
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static const char * format[]
Definition: af_aiir.c:311
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:188
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:269
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
Definition: get_bits.h:415
int num
Numerator.
Definition: rational.h:59
AVCodec ff_h263i_decoder
Definition: intelh263dec.c:131
int obmc
overlapped block motion compensation
Definition: mpegvideo.h:366
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1896
mpegvideo header.
const uint16_t ff_h263_format[8][2]
Definition: h263data.c:238
AVCodec.
Definition: avcodec.h:3408
int qscale
QP.
Definition: mpegvideo.h:204
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
const uint8_t ff_mpeg1_dc_scale_table[128]
Definition: mpegvideodata.c:34
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:2749
#define av_log(a,...)
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:596
int h263_plus
H.263+ headers.
Definition: mpegvideo.h:109
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int unrestricted_mv
mv can point outside of the coded picture
Definition: mpegvideo.h:223
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
const char * name
Name of the codec implementation.
Definition: avcodec.h:3415
GetBitContext gb
Definition: mpegvideo.h:448
int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:68
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:420
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:953
int pb_frame
PB-frame mode (0 = none, 1 = base, 2 = improved)
Definition: mpegvideo.h:106
#define FRAME_SKIPPED
Return value for header parsers if frame is not coded.
Definition: mpegutils.h:34
int ff_intel_h263_decode_picture_header(MpegEncContext *s)
Definition: intelh263dec.c:27
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:100
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:321
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:346
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:314
int f_code
forward MV resolution
Definition: mpegvideo.h:238
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:354
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:212
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
const AVRational ff_h263_pixel_aspect[16]
Definition: h263data.c:275
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
Definition: mpegvideo.h:189
MpegEncContext.
Definition: mpegvideo.h:81
struct AVCodecContext * avctx
Definition: mpegvideo.h:98
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
Definition: internal.h:60
int den
Denominator.
Definition: rational.h:60
int ff_h263_decode_end(AVCodecContext *avctx)
Definition: h263dec.c:155
int chroma_qscale
chroma QP
Definition: mpegvideo.h:205
void ff_h263_show_pict_info(MpegEncContext *s)
Print picture info if FF_DEBUG_PICT_INFO is set.
Definition: ituh263dec.c:76
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:601
int h263_long_vectors
use horrible H.263v1 long vector mode
Definition: mpegvideo.h:224
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:959