FFmpeg
Loading...
Searching...
No Matches
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 "codec_internal.h"
22#include "h263.h"
23#include "mpegvideo.h"
24#include "mpegvideodec.h"
25#include "h263data.h"
26#include "h263dec.h"
27
28/* don't understand why they choose a different header ! */
30{
31 int format;
32
33 if (get_bits_left(&h->gb) == 64) { /* special dummy frames */
34 return FRAME_SKIPPED;
35 }
36
37 /* picture header */
38 if (get_bits(&h->gb, 22) != 0x20) {
39 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
40 return -1;
41 }
42 h->picture_number = get_bits(&h->gb, 8); /* picture timestamp */
43
44 if (check_marker(h->c.avctx, &h->gb, "after picture_number") != 1) {
45 return -1; /* marker */
46 }
47 if (get_bits1(&h->gb) != 0) {
48 av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
49 return -1; /* H.263 id */
50 }
51 skip_bits1(&h->gb); /* split screen off */
52 skip_bits1(&h->gb); /* camera off */
53 skip_bits1(&h->gb); /* freeze picture release off */
54
55 format = get_bits(&h->gb, 3);
56 if (format == 0 || format == 6) {
57 av_log(h->c.avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
58 return -1;
59 }
60
61 h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb);
62
63 h->h263_long_vectors = get_bits1(&h->gb);
64
65 if (get_bits1(&h->gb) != 0) {
66 av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n");
67 return -1; /* SAC: off */
68 }
69 h->c.obmc = get_bits1(&h->gb);
70 h->pb_frame = get_bits1(&h->gb);
71
72 if (format < 6) {
73 h->c.width = ff_h263_format[format][0];
74 h->c.height = ff_h263_format[format][1];
75 h->c.avctx->sample_aspect_ratio.num = 12;
76 h->c.avctx->sample_aspect_ratio.den = 11;
77 } else {
78 format = get_bits(&h->gb, 3);
79 if(format == 0 || format == 7){
80 av_log(h->c.avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
81 return -1;
82 }
83 if (get_bits(&h->gb, 2))
84 av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
85 h->loop_filter = get_bits1(&h->gb) * !h->c.avctx->lowres;
86 if (get_bits1(&h->gb))
87 av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
88 if (get_bits1(&h->gb))
89 h->pb_frame = 2;
90 if (get_bits(&h->gb, 5))
91 av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
92 if (get_bits(&h->gb, 5) != 1)
93 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid marker\n");
94 }
95 if(format == 6){
96 int ar = get_bits(&h->gb, 4);
97 skip_bits(&h->gb, 9); // display width
98 check_marker(h->c.avctx, &h->gb, "in dimensions");
99 skip_bits(&h->gb, 9); // display height
100 if (ar == 15) {
101 h->c.avctx->sample_aspect_ratio.num = get_bits(&h->gb, 8); // aspect ratio - width
102 h->c.avctx->sample_aspect_ratio.den = get_bits(&h->gb, 8); // aspect ratio - height
103 } else {
104 h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
105 }
106 if (h->c.avctx->sample_aspect_ratio.num == 0)
107 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
108 }
109
110 h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
111 skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
112
113 if (h->pb_frame) {
114 skip_bits(&h->gb, 3); //temporal reference for B-frame
115 skip_bits(&h->gb, 2); //dbquant
116 }
117
118 /* PEI */
119 if (skip_1stop_8data_bits(&h->gb) < 0)
120 return AVERROR_INVALIDDATA;
121
122 h->gob_index = H263_GOB_HEIGHT(h->c.height);
123
125
126 return 0;
127}
128
130 .p.name = "h263i",
131 CODEC_LONG_NAME("Intel H.263"),
132 .p.type = AVMEDIA_TYPE_VIDEO,
133 .p.id = AV_CODEC_ID_H263I,
134 .priv_data_size = sizeof(H263DecContext),
137 .close = ff_mpv_decode_close,
139 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
141};
static const char *const format[]
Definition af_aiir.c:444
const FFCodec ff_h263i_decoder
#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...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static int get_bits_left(GetBitContext *gb)
Definition get_bits.h:688
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static void skip_bits(GetBitContext *s, int n)
Definition get_bits.h:383
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition get_bits.h:693
static void skip_bits1(GetBitContext *s)
Definition get_bits.h:416
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition codec.h:41
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_H263I
Definition codec_id.h:70
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
#define H263_GOB_HEIGHT(h)
Definition h263.h:28
const AVRational ff_h263_pixel_aspect[16]
Definition h263data.c:273
const uint16_t ff_h263_format[8][2]
Definition h263data.c:236
H.263 tables.
#define FRAME_SKIPPED
Frame is not coded.
Definition h263dec.h:90
void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
Print picture info if FF_DEBUG_PICT_INFO is set.
Definition ituh263dec.c:80
int ff_intel_h263_decode_picture_header(H263DecContext *const h)
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition h263dec.c:94
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition h263dec.c:443
mpegvideo header.
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
mpegvideo decoder header.
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
#define av_log(a,...)