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 "mpegvideo.h"
22 #include "h263.h"
23 
24 /* don't understand why they choose a different header ! */
26 {
27  int format;
28 
29  /* picture header */
30  if (get_bits_long(&s->gb, 22) != 0x20) {
31  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
32  return -1;
33  }
34  s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
35 
36  if (get_bits1(&s->gb) != 1) {
37  av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
38  return -1; /* marker */
39  }
40  if (get_bits1(&s->gb) != 0) {
41  av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");
42  return -1; /* h263 id */
43  }
44  skip_bits1(&s->gb); /* split screen off */
45  skip_bits1(&s->gb); /* camera off */
46  skip_bits1(&s->gb); /* freeze picture release off */
47 
48  format = get_bits(&s->gb, 3);
49  if (format == 0 || format == 6) {
50  av_log(s->avctx, AV_LOG_ERROR, "Intel H263 free format not supported\n");
51  return -1;
52  }
53  s->h263_plus = 0;
54 
56 
57  s->h263_long_vectors = get_bits1(&s->gb);
58 
59  if (get_bits1(&s->gb) != 0) {
60  av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
61  return -1; /* SAC: off */
62  }
63  s->obmc= get_bits1(&s->gb);
65  s->pb_frame = get_bits1(&s->gb);
66 
67  if (format < 6) {
68  s->width = ff_h263_format[format][0];
69  s->height = ff_h263_format[format][1];
70  s->avctx->sample_aspect_ratio.num = 12;
71  s->avctx->sample_aspect_ratio.den = 11;
72  } else {
73  format = get_bits(&s->gb, 3);
74  if(format == 0 || format == 7){
75  av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H263 format\n");
76  return -1;
77  }
78  if(get_bits(&s->gb, 2))
79  av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
80  s->loop_filter = get_bits1(&s->gb) * !s->avctx->lowres;
81  if(get_bits1(&s->gb))
82  av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
83  if(get_bits1(&s->gb))
84  s->pb_frame = 2;
85  if(get_bits(&s->gb, 5))
86  av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
87  if(get_bits(&s->gb, 5) != 1)
88  av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n");
89  }
90  if(format == 6){
91  int ar = get_bits(&s->gb, 4);
92  skip_bits(&s->gb, 9); // display width
93  skip_bits1(&s->gb);
94  skip_bits(&s->gb, 9); // display height
95  if(ar == 15){
96  s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width
97  s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height
98  } else {
100  }
101  if (s->avctx->sample_aspect_ratio.num == 0)
102  av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
103  }
104 
105  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
106  skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
107 
108  if(s->pb_frame){
109  skip_bits(&s->gb, 3); //temporal reference for B-frame
110  skip_bits(&s->gb, 2); //dbquant
111  }
112 
113  /* PEI */
114  while (get_bits1(&s->gb) != 0) {
115  skip_bits(&s->gb, 8);
116  }
117  s->f_code = 1;
118 
119  s->y_dc_scale_table=
121 
123 
124  return 0;
125 }
126 
128  .name = "h263i",
129  .type = AVMEDIA_TYPE_VIDEO,
130  .id = AV_CODEC_ID_H263I,
131  .priv_data_size = sizeof(MpegEncContext),
135  .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
136  .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"),
137  .pix_fmts = ff_pixfmt_list_420,
138 };
int picture_number
Definition: mpegvideo.h:275
const char * s
Definition: avisynth_c.h:668
struct MpegEncContext MpegEncContext
MpegEncContext.
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:351
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int num
numerator
Definition: rational.h:44
AVCodec ff_h263i_decoder
Definition: intelh263dec.c:127
int obmc
overlapped block motion compensation
Definition: mpegvideo.h:538
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
mpegvideo header.
const uint16_t ff_h263_format[8][2]
Definition: h263data.h:239
int qscale
QP.
Definition: mpegvideo.h:369
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
enum AVPixelFormat ff_pixfmt_list_420[]
Definition: mpegvideo.c:127
const AVRational ff_h263_pixel_aspect[16]
Definition: h263data.h:280
int h263_plus
h263 plus headers
Definition: mpegvideo.h:254
int unrestricted_mv
mv can point outside of the coded picture
Definition: mpegvideo.h:388
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
GetBitContext gb
Definition: mpegvideo.h:649
int ff_h263_decode_init(AVCodecContext *avctx)
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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 format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
int pb_frame
PB frame mode (0 = none, 1 = base, 2 = improved)
Definition: mpegvideo.h:251
int ff_intel_h263_decode_picture_header(MpegEncContext *s)
Definition: intelh263dec.c:25
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:245
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
const uint8_t ff_mpeg1_dc_scale_table[128]
Definition: mpegvideo.c:72
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:273
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:298
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:265
int f_code
forward MV resolution
Definition: mpegvideo.h:395
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:306
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:377
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
Definition: mpegvideo.h:352
MpegEncContext.
Definition: mpegvideo.h:241
struct AVCodecContext * avctx
Definition: mpegvideo.h:243
int den
denominator
Definition: rational.h:45
int ff_h263_decode_end(AVCodecContext *avctx)
int chroma_qscale
chroma QP
Definition: mpegvideo.h:370
void ff_h263_show_pict_info(MpegEncContext *s)
Print picture info if FF_DEBUG_PICT_INFO is set.
Definition: ituh263dec.c:71
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
int h263_long_vectors
use horrible h263v1 long vector mode
Definition: mpegvideo.h:389