FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 #include "mpegvideodata.h"
24 
25 /* don't understand why they choose a different header ! */
27 {
28  int format;
29 
30  if (get_bits_left(&s->gb) == 64) { /* special dummy frames */
31  return FRAME_SKIPPED;
32  }
33 
34  /* picture header */
35  if (get_bits_long(&s->gb, 22) != 0x20) {
36  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
37  return -1;
38  }
39  s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
40 
41  if (check_marker(&s->gb, "after picture_number") != 1) {
42  return -1; /* marker */
43  }
44  if (get_bits1(&s->gb) != 0) {
45  av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");
46  return -1; /* h263 id */
47  }
48  skip_bits1(&s->gb); /* split screen off */
49  skip_bits1(&s->gb); /* camera off */
50  skip_bits1(&s->gb); /* freeze picture release off */
51 
52  format = get_bits(&s->gb, 3);
53  if (format == 0 || format == 6) {
54  av_log(s->avctx, AV_LOG_ERROR, "Intel H263 free format not supported\n");
55  return -1;
56  }
57  s->h263_plus = 0;
58 
60 
61  s->h263_long_vectors = get_bits1(&s->gb);
62 
63  if (get_bits1(&s->gb) != 0) {
64  av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
65  return -1; /* SAC: off */
66  }
67  s->obmc= get_bits1(&s->gb);
69  s->pb_frame = get_bits1(&s->gb);
70 
71  if (format < 6) {
72  s->width = ff_h263_format[format][0];
73  s->height = ff_h263_format[format][1];
74  s->avctx->sample_aspect_ratio.num = 12;
75  s->avctx->sample_aspect_ratio.den = 11;
76  } else {
77  format = get_bits(&s->gb, 3);
78  if(format == 0 || format == 7){
79  av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H263 format\n");
80  return -1;
81  }
82  if(get_bits(&s->gb, 2))
83  av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
84  s->loop_filter = get_bits1(&s->gb) * !s->avctx->lowres;
85  if(get_bits1(&s->gb))
86  av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
87  if(get_bits1(&s->gb))
88  s->pb_frame = 2;
89  if(get_bits(&s->gb, 5))
90  av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
91  if(get_bits(&s->gb, 5) != 1)
92  av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n");
93  }
94  if(format == 6){
95  int ar = get_bits(&s->gb, 4);
96  skip_bits(&s->gb, 9); // display width
97  check_marker(&s->gb, "in dimensions");
98  skip_bits(&s->gb, 9); // display height
99  if(ar == 15){
100  s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width
101  s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height
102  } else {
104  }
105  if (s->avctx->sample_aspect_ratio.num == 0)
106  av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
107  }
108 
109  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
110  skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
111 
112  if(s->pb_frame){
113  skip_bits(&s->gb, 3); //temporal reference for B-frame
114  skip_bits(&s->gb, 2); //dbquant
115  }
116 
117  /* PEI */
118  if (skip_1stop_8data_bits(&s->gb) < 0)
119  return AVERROR_INVALIDDATA;
120  s->f_code = 1;
121 
122  s->y_dc_scale_table=
124 
126 
127  return 0;
128 }
129 
131  .name = "h263i",
132  .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"),
133  .type = AVMEDIA_TYPE_VIDEO,
134  .id = AV_CODEC_ID_H263I,
135  .priv_data_size = sizeof(MpegEncContext),
137  .close = ff_h263_decode_end,
140  .pix_fmts = (const enum AVPixelFormat[]) {
143  },
144 };
int picture_number
Definition: mpegvideo.h:134
const char * s
Definition: avisynth_c.h:631
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:195
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:260
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:130
int obmc
overlapped block motion compensation
Definition: mpegvideo.h:373
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:1902
mpegvideo header.
const uint16_t ff_h263_format[8][2]
Definition: h263data.c:238
AVCodec.
Definition: avcodec.h:3472
int qscale
QP.
Definition: mpegvideo.h:211
const uint8_t ff_mpeg1_dc_scale_table[128]
Definition: mpegvideodata.c:27
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:3013
#define av_log(a,...)
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:588
int h263_plus
h263 plus headers
Definition: mpegvideo.h:116
#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:230
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
const char * name
Name of the codec implementation.
Definition: avcodec.h:3479
GetBitContext gb
Definition: mpegvideo.h:451
static int check_marker(GetBitContext *s, const char *msg)
Definition: get_bits.h:393
int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:62
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:409
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:851
int pb_frame
PB frame mode (0 = none, 1 = base, 2 = improved)
Definition: mpegvideo.h:113
int ff_intel_h263_decode_picture_header(MpegEncContext *s)
Definition: intelh263dec.c:26
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:107
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:304
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:329
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:297
int f_code
forward MV resolution
Definition: mpegvideo.h:245
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:337
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:219
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:209
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:196
MpegEncContext.
Definition: mpegvideo.h:88
struct AVCodecContext * avctx
Definition: mpegvideo.h:105
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:523
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
int den
denominator
Definition: rational.h:45
int ff_h263_decode_end(AVCodecContext *avctx)
Definition: h263dec.c:149
int chroma_qscale
chroma QP
Definition: mpegvideo.h:212
void ff_h263_show_pict_info(MpegEncContext *s)
Print picture info if FF_DEBUG_PICT_INFO is set.
Definition: ituh263dec.c:76
#define FRAME_SKIPPED
return value for header parsers if frame is not coded
Definition: mpegvideo.h:61
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:593
int h263_long_vectors
use horrible h263v1 long vector mode
Definition: mpegvideo.h:231
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:857