annotate h261.c @ 3485:f574901e49d2 libavcodec

some fixmes if someone ever wants to implement theora support correctly ...
author michael
date Sun, 16 Jul 2006 20:47:48 +0000
parents cc4b4ea83e29
children df07afe83a62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1 /*
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
2 * H261 decoder
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
4 * Copyright (c) 2004 Maarten Daniels
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
5 *
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
10 *
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
14 * Lesser General Public License for more details.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
15 *
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
19 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
20
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
21 /**
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
22 * @file h261.c
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
23 * h261codec.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
24 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
25
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
26 #include "common.h"
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
27 #include "dsputil.h"
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
28 #include "avcodec.h"
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
29 #include "mpegvideo.h"
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
30 #include "h261data.h"
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
31
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
32
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
33 #define H261_MBA_VLC_BITS 9
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
34 #define H261_MTYPE_VLC_BITS 6
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
35 #define H261_MV_VLC_BITS 7
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
36 #define H261_CBP_VLC_BITS 9
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
37 #define TCOEFF_VLC_BITS 9
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
38
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
39 #define MBA_STUFFING 33
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
40 #define MBA_STARTCODE 34
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
41 #define IS_FIL(a) ((a)&MB_TYPE_H261_FIL)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
42
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
43 /**
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
44 * H261Context
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
45 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
46 typedef struct H261Context{
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
47 MpegEncContext s;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
48
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
49 int current_mba;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
50 int previous_mba;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
51 int mba_diff;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
52 int mtype;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
53 int current_mv_x;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
54 int current_mv_y;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
55 int gob_number;
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
56 int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
57 }H261Context;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
58
2291
c4e882a7c07c h.261 loop filter fix
michael
parents: 2290
diff changeset
59 void ff_h261_loop_filter(MpegEncContext *s){
c4e882a7c07c h.261 loop filter fix
michael
parents: 2290
diff changeset
60 H261Context * h= (H261Context*)s;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
61 const int linesize = s->linesize;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
62 const int uvlinesize= s->uvlinesize;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
63 uint8_t *dest_y = s->dest[0];
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
64 uint8_t *dest_cb= s->dest[1];
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
65 uint8_t *dest_cr= s->dest[2];
2291
c4e882a7c07c h.261 loop filter fix
michael
parents: 2290
diff changeset
66
c4e882a7c07c h.261 loop filter fix
michael
parents: 2290
diff changeset
67 if(!(IS_FIL (h->mtype)))
c4e882a7c07c h.261 loop filter fix
michael
parents: 2290
diff changeset
68 return;
c4e882a7c07c h.261 loop filter fix
michael
parents: 2290
diff changeset
69
2045
9447bbd8a7e9 rewrite h261 loop filter
michael
parents: 2044
diff changeset
70 s->dsp.h261_loop_filter(dest_y , linesize);
9447bbd8a7e9 rewrite h261 loop filter
michael
parents: 2044
diff changeset
71 s->dsp.h261_loop_filter(dest_y + 8, linesize);
9447bbd8a7e9 rewrite h261 loop filter
michael
parents: 2044
diff changeset
72 s->dsp.h261_loop_filter(dest_y + 8 * linesize , linesize);
9447bbd8a7e9 rewrite h261 loop filter
michael
parents: 2044
diff changeset
73 s->dsp.h261_loop_filter(dest_y + 8 * linesize + 8, linesize);
9447bbd8a7e9 rewrite h261 loop filter
michael
parents: 2044
diff changeset
74 s->dsp.h261_loop_filter(dest_cb, uvlinesize);
9447bbd8a7e9 rewrite h261 loop filter
michael
parents: 2044
diff changeset
75 s->dsp.h261_loop_filter(dest_cr, uvlinesize);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
76 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
77
2328
7b5353eb0dd8 cleanup
michael
parents: 2327
diff changeset
78 static int ff_h261_get_picture_format(int width, int height){
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
79 // QCIF
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
80 if (width == 176 && height == 144)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
81 return 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
82 // CIF
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
83 else if (width == 352 && height == 288)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
84 return 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
85 // ERROR
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
86 else
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
87 return -1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
88 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
89
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
90 static void h261_encode_block(H261Context * h, DCTELEM * block,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
91 int n);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
92 static int h261_decode_block(H261Context *h, DCTELEM *block,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
93 int n, int coded);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
94
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
95 void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
96 H261Context * h = (H261Context *) s;
2328
7b5353eb0dd8 cleanup
michael
parents: 2327
diff changeset
97 int format, temp_ref;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
98
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
99 align_put_bits(&s->pb);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
100
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
101 /* Update the pointer to last GOB */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
102 s->ptr_lastgob = pbBufPtr(&s->pb);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
103
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
104 put_bits(&s->pb, 20, 0x10); /* PSC */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
105
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
106 temp_ref= s->picture_number * (int64_t)30000 * s->avctx->time_base.num /
2637
ef44d24680d1 switch to native time bases
michael
parents: 2632
diff changeset
107 (1001 * (int64_t)s->avctx->time_base.den); //FIXME maybe this should use a timestamp
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
108 put_bits(&s->pb, 5, temp_ref & 0x1f); /* TemporalReference */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
109
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
110 put_bits(&s->pb, 1, 0); /* split screen off */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
111 put_bits(&s->pb, 1, 0); /* camera off */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
112 put_bits(&s->pb, 1, 0); /* freeze picture release off */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
113
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
114 format = ff_h261_get_picture_format(s->width, s->height);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
115
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
116 put_bits(&s->pb, 1, format); /* 0 == QCIF, 1 == CIF */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
117
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
118 put_bits(&s->pb, 1, 0); /* still image mode */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
119 put_bits(&s->pb, 1, 0); /* reserved */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
120
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
121 put_bits(&s->pb, 1, 0); /* no PEI */
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
122 if(format == 0)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
123 h->gob_number = -1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
124 else
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
125 h->gob_number = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
126 h->current_mba = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
127 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
128
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
129 /**
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
130 * Encodes a group of blocks header.
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
131 */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
132 static void h261_encode_gob_header(MpegEncContext * s, int mb_line){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
133 H261Context * h = (H261Context *)s;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
134 if(ff_h261_get_picture_format(s->width, s->height) == 0){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
135 h->gob_number+=2; // QCIF
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
136 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
137 else{
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
138 h->gob_number++; // CIF
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
139 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
140 put_bits(&s->pb, 16, 1); /* GBSC */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
141 put_bits(&s->pb, 4, h->gob_number); /* GN */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
142 put_bits(&s->pb, 5, s->qscale); /* GQUANT */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
143 put_bits(&s->pb, 1, 0); /* no GEI */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
144 h->current_mba = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
145 h->previous_mba = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
146 h->current_mv_x=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
147 h->current_mv_y=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
148 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
149
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
150 void ff_h261_reorder_mb_index(MpegEncContext* s){
2331
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
151 int index= s->mb_x + s->mb_y*s->mb_width;
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
152
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
153 if(index % 33 == 0)
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
154 h261_encode_gob_header(s,0);
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
155
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
156 /* for CIF the GOB's are fragmented in the middle of a scanline
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
157 that's why we need to adjust the x and y index of the macroblocks */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
158 if(ff_h261_get_picture_format(s->width,s->height) == 1){ // CIF
2331
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
159 s->mb_x = index % 11 ; index /= 11;
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
160 s->mb_y = index % 3 ; index /= 3;
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
161 s->mb_x+= 11*(index % 2); index /= 2;
5690ce009ebd simplify ff_h261_reorder_mb_index
michael
parents: 2330
diff changeset
162 s->mb_y+= 3*index;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
163
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
164 ff_init_block_index(s);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
165 ff_update_block_index(s);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
166 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
167 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
168
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
169 static void h261_encode_motion(H261Context * h, int val){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
170 MpegEncContext * const s = &h->s;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
171 int sign, code;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
172 if(val==0){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
173 code = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
174 put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
175 }
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
176 else{
2345
ada3891b859d H261 fixing and cleaning:
michael
parents: 2332
diff changeset
177 if(val > 15)
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
178 val -=32;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
179 if(val < -16)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
180 val+=32;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
181 sign = val < 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
182 code = sign ? -val : val;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
183 put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
184 put_bits(&s->pb,1,sign);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
185 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
186 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
187
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
188 static inline int get_cbp(MpegEncContext * s,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
189 DCTELEM block[6][64])
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
190 {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
191 int i, cbp;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
192 cbp= 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
193 for (i = 0; i < 6; i++) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
194 if (s->block_last_index[i] >= 0)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
195 cbp |= 1 << (5 - i);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
196 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
197 return cbp;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
198 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
199 void ff_h261_encode_mb(MpegEncContext * s,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
200 DCTELEM block[6][64],
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
201 int motion_x, int motion_y)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
202 {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
203 H261Context * h = (H261Context *)s;
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
204 int mvd, mv_diff_x, mv_diff_y, i, cbp;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
205 cbp = 63; // avoid warning
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
206 mvd = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
207
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
208 h->current_mba++;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
209 h->mtype = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
210
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
211 if (!s->mb_intra){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
212 /* compute cbp */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
213 cbp= get_cbp(s, block);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
214
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
215 /* mvd indicates if this block is motion compensated */
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
216 mvd = motion_x | motion_y;
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
217
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
218 if((cbp | mvd | s->dquant ) == 0) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
219 /* skip macroblock */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
220 s->skip_count++;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
221 h->current_mv_x=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
222 h->current_mv_y=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
223 return;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
224 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
225 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
226
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
227 /* MB is not skipped, encode MBA */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
228 put_bits(&s->pb, h261_mba_bits[(h->current_mba-h->previous_mba)-1], h261_mba_code[(h->current_mba-h->previous_mba)-1]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
229
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
230 /* calculate MTYPE */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
231 if(!s->mb_intra){
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
232 h->mtype++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
233
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
234 if(mvd || s->loop_filter)
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
235 h->mtype+=3;
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
236 if(s->loop_filter)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
237 h->mtype+=3;
2329
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
238 if(cbp || s->dquant)
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
239 h->mtype++;
bae9c6de090b fix and cleanup h261 mb_type selection
michael
parents: 2328
diff changeset
240 assert(h->mtype > 1);
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
241 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
242
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
243 if(s->dquant)
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
244 h->mtype++;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
245
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
246 put_bits(&s->pb, h261_mtype_bits[h->mtype], h261_mtype_code[h->mtype]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
247
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
248 h->mtype = h261_mtype_map[h->mtype];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
249
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
250 if(IS_QUANT(h->mtype)){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
251 ff_set_qscale(s,s->qscale+s->dquant);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
252 put_bits(&s->pb, 5, s->qscale);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
253 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
254
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
255 if(IS_16X16(h->mtype)){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
256 mv_diff_x = (motion_x >> 1) - h->current_mv_x;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
257 mv_diff_y = (motion_y >> 1) - h->current_mv_y;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
258 h->current_mv_x = (motion_x >> 1);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
259 h->current_mv_y = (motion_y >> 1);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
260 h261_encode_motion(h,mv_diff_x);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
261 h261_encode_motion(h,mv_diff_y);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
262 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
263
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
264 h->previous_mba = h->current_mba;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
265
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
266 if(HAS_CBP(h->mtype)){
3317
e2a44d47dae8 cbp must be >0 here or we are in troubble
michael
parents: 3177
diff changeset
267 assert(cbp>0);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
268 put_bits(&s->pb,h261_cbp_tab[cbp-1][1],h261_cbp_tab[cbp-1][0]);
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
269 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
270 for(i=0; i<6; i++) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
271 /* encode each block */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
272 h261_encode_block(h, block[i], i);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
273 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
274
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
275 if ( ( h->current_mba == 11 ) || ( h->current_mba == 22 ) || ( h->current_mba == 33 ) || ( !IS_16X16 ( h->mtype ) )){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
276 h->current_mv_x=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
277 h->current_mv_y=0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
278 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
279 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
280
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
281 void ff_h261_encode_init(MpegEncContext *s){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
282 static int done = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
283
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
284 if (!done) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
285 done = 1;
2370
26560d4fdb1f Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents: 2356
diff changeset
286 init_rl(&h261_rl_tcoeff, 1);
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
287 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
288
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
289 s->min_qcoeff= -127;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
290 s->max_qcoeff= 127;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
291 s->y_dc_scale_table=
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
292 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
293 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
294
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
295
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
296 /**
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
297 * encodes a 8x8 block.
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
298 * @param block the 8x8 block
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
299 * @param n block index (0-3 are luma, 4-5 are chroma)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
300 */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
301 static void h261_encode_block(H261Context * h, DCTELEM * block, int n){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
302 MpegEncContext * const s = &h->s;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
303 int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
304 RLTable *rl;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
305
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
306 rl = &h261_rl_tcoeff;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
307 if (s->mb_intra) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
308 /* DC coef */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
309 level = block[0];
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
310 /* 255 cannot be represented, so we clamp */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
311 if (level > 254) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
312 level = 254;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
313 block[0] = 254;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
314 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
315 /* 0 cannot be represented also */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
316 else if (level < 1) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
317 level = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
318 block[0] = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
319 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
320 if (level == 128)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
321 put_bits(&s->pb, 8, 0xff);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
322 else
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
323 put_bits(&s->pb, 8, level);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
324 i = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
325 } else if((block[0]==1 || block[0] == -1) && (s->block_last_index[n] > -1)){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
326 //special case
2332
cb3f0954e982 cleanup
michael
parents: 2331
diff changeset
327 put_bits(&s->pb,2,block[0]>0 ? 2 : 3 );
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
328 i = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
329 } else {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
330 i = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
331 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
332
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
333 /* AC coefs */
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
334 last_index = s->block_last_index[n];
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
335 last_non_zero = i - 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
336 for (; i <= last_index; i++) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
337 j = s->intra_scantable.permutated[i];
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
338 level = block[j];
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
339 if (level) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
340 run = i - last_non_zero - 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
341 last = (i == last_index);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
342 sign = 0;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
343 slevel = level;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
344 if (level < 0) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
345 sign = 1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
346 level = -level;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
347 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
348 code = get_rl_index(rl, 0 /*no last in H.261, EOB is used*/, run, level);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
349 if(run==0 && level < 16)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
350 code+=1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
351 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
352 if (code == rl->n) {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
353 put_bits(&s->pb, 6, run);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
354 assert(slevel != 0);
2332
cb3f0954e982 cleanup
michael
parents: 2331
diff changeset
355 assert(level <= 127);
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
356 put_bits(&s->pb, 8, slevel & 0xff);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
357 } else {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
358 put_bits(&s->pb, 1, sign);
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
359 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
360 last_non_zero = i;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
361 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
362 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
363 if(last_index > -1){
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
364 put_bits(&s->pb, rl->table_vlc[0][1], rl->table_vlc[0][0]);// END OF BLOCK
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
365 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
366 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
367
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
368 /***********************************************/
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
369 /* decoding */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
370
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
371 static VLC h261_mba_vlc;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
372 static VLC h261_mtype_vlc;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
373 static VLC h261_mv_vlc;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
374 static VLC h261_cbp_vlc;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
375
2370
26560d4fdb1f Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents: 2356
diff changeset
376 void init_vlc_rl(RLTable *rl, int use_static);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
377
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
378 static void h261_decode_init_vlc(H261Context *h){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
379 static int done = 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
380
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
381 if(!done){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
382 done = 1;
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
383 init_vlc(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
384 h261_mba_bits, 1, 1,
2370
26560d4fdb1f Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents: 2356
diff changeset
385 h261_mba_code, 1, 1, 1);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
386 init_vlc(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
387 h261_mtype_bits, 1, 1,
2370
26560d4fdb1f Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents: 2356
diff changeset
388 h261_mtype_code, 1, 1, 1);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
389 init_vlc(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
390 &h261_mv_tab[0][1], 2, 1,
2370
26560d4fdb1f Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents: 2356
diff changeset
391 &h261_mv_tab[0][0], 2, 1, 1);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
392 init_vlc(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
393 &h261_cbp_tab[0][1], 2, 1,
2370
26560d4fdb1f Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents: 2356
diff changeset
394 &h261_cbp_tab[0][0], 2, 1, 1);
26560d4fdb1f Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents: 2356
diff changeset
395 init_rl(&h261_rl_tcoeff, 1);
26560d4fdb1f Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents: 2356
diff changeset
396 init_vlc_rl(&h261_rl_tcoeff, 1);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
397 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
398 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
399
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
400 static int h261_decode_init(AVCodecContext *avctx){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
401 H261Context *h= avctx->priv_data;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
402 MpegEncContext * const s = &h->s;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
403
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
404 // set defaults
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
405 MPV_decode_defaults(s);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
406 s->avctx = avctx;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
407
2270
21f450be6cb5 lowres width/height cleanup 3rd try
michael
parents: 2266
diff changeset
408 s->width = s->avctx->coded_width;
21f450be6cb5 lowres width/height cleanup 3rd try
michael
parents: 2266
diff changeset
409 s->height = s->avctx->coded_height;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
410 s->codec_id = s->avctx->codec->id;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
411
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
412 s->out_format = FMT_H261;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
413 s->low_delay= 1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
414 avctx->pix_fmt= PIX_FMT_YUV420P;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
415
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
416 s->codec_id= avctx->codec->id;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
417
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
418 h261_decode_init_vlc(h);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
419
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
420 h->gob_start_code_skipped = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
421
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
422 return 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
423 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
424
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
425 /**
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
426 * decodes the group of blocks header or slice header.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
427 * @return <0 if an error occured
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
428 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
429 static int h261_decode_gob_header(H261Context *h){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
430 unsigned int val;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
431 MpegEncContext * const s = &h->s;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
432
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
433 if ( !h->gob_start_code_skipped ){
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
434 /* Check for GOB Start Code */
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
435 val = show_bits(&s->gb, 15);
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
436 if(val)
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
437 return -1;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
438
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
439 /* We have a GBSC */
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
440 skip_bits(&s->gb, 16);
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
441 }
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
442
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
443 h->gob_start_code_skipped = 0;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
444
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
445 h->gob_number = get_bits(&s->gb, 4); /* GN */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
446 s->qscale = get_bits(&s->gb, 5); /* GQUANT */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
447
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
448 /* Check if gob_number is valid */
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
449 if (s->mb_height==18){ //cif
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
450 if ((h->gob_number<=0) || (h->gob_number>12))
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
451 return -1;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
452 }
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
453 else{ //qcif
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
454 if ((h->gob_number!=1) && (h->gob_number!=3) && (h->gob_number!=5))
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
455 return -1;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
456 }
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
457
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
458 /* GEI */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
459 while (get_bits1(&s->gb) != 0) {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
460 skip_bits(&s->gb, 8);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
461 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
462
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
463 if(s->qscale==0)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
464 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
465
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
466 // For the first transmitted macroblock in a GOB, MBA is the absolute address. For
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
467 // subsequent macroblocks, MBA is the difference between the absolute addresses of
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
468 // the macroblock and the last transmitted macroblock.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
469 h->current_mba = 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
470 h->mba_diff = 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
471
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
472 return 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
473 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
474
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
475 /**
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
476 * decodes the group of blocks / video packet header.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
477 * @return <0 if no resync found
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
478 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
479 static int ff_h261_resync(H261Context *h){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
480 MpegEncContext * const s = &h->s;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
481 int left, ret;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
482
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
483 if ( h->gob_start_code_skipped ){
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
484 ret= h261_decode_gob_header(h);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
485 if(ret>=0)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
486 return 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
487 }
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
488 else{
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
489 if(show_bits(&s->gb, 15)==0){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
490 ret= h261_decode_gob_header(h);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
491 if(ret>=0)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
492 return 0;
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
493 }
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
494 //ok, its not where its supposed to be ...
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
495 s->gb= s->last_resync_gb;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
496 align_get_bits(&s->gb);
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
497 left= s->gb.size_in_bits - get_bits_count(&s->gb);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
498
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
499 for(;left>15+1+4+5; left-=8){
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
500 if(show_bits(&s->gb, 15)==0){
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
501 GetBitContext bak= s->gb;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
502
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
503 ret= h261_decode_gob_header(h);
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
504 if(ret>=0)
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
505 return 0;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
506
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
507 s->gb= bak;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
508 }
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
509 skip_bits(&s->gb, 8);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
510 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
511 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
512
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
513 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
514 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
515
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
516 /**
2134
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
517 * decodes skipped macroblocks
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
518 * @return 0
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
519 */
2134
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
520 static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 )
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
521 {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
522 MpegEncContext * const s = &h->s;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
523 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
524
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
525 s->mb_intra = 0;
2134
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
526
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
527 for(i=mba1; i<mba2; i++){
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
528 int j, xy;
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
529
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
530 s->mb_x= ((h->gob_number-1) % 2) * 11 + i % 11;
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
531 s->mb_y= ((h->gob_number-1) / 2) * 3 + i / 11;
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
532 xy = s->mb_x + s->mb_y * s->mb_stride;
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
533 ff_init_block_index(s);
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
534 ff_update_block_index(s);
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
535
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
536 for(j=0;j<6;j++)
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
537 s->block_last_index[j] = -1;
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
538
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
539 s->mv_dir = MV_DIR_FORWARD;
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
540 s->mv_type = MV_TYPE_16X16;
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
541 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
542 s->mv[0][0][0] = 0;
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
543 s->mv[0][0][1] = 0;
2628
511e3afc43e1 Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents: 2453
diff changeset
544 s->mb_skipped = 1;
2291
c4e882a7c07c h.261 loop filter fix
michael
parents: 2290
diff changeset
545 h->mtype &= ~MB_TYPE_H261_FIL;
2134
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
546
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
547 MPV_decode_mb(s, s->block);
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
548 }
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
549
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
550 return 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
551 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
552
2046
863ce5459aec simplify
michael
parents: 2045
diff changeset
553 static int decode_mv_component(GetBitContext *gb, int v){
863ce5459aec simplify
michael
parents: 2045
diff changeset
554 int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
555
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
556 /* check if mv_diff is valid */
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
557 if ( mv_diff < 0 )
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
558 return v;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
559
2046
863ce5459aec simplify
michael
parents: 2045
diff changeset
560 mv_diff = mvmap[mv_diff];
863ce5459aec simplify
michael
parents: 2045
diff changeset
561
863ce5459aec simplify
michael
parents: 2045
diff changeset
562 if(mv_diff && !get_bits1(gb))
863ce5459aec simplify
michael
parents: 2045
diff changeset
563 mv_diff= -mv_diff;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
564
2046
863ce5459aec simplify
michael
parents: 2045
diff changeset
565 v += mv_diff;
863ce5459aec simplify
michael
parents: 2045
diff changeset
566 if (v <=-16) v+= 32;
863ce5459aec simplify
michael
parents: 2045
diff changeset
567 else if(v >= 16) v-= 32;
863ce5459aec simplify
michael
parents: 2045
diff changeset
568
863ce5459aec simplify
michael
parents: 2045
diff changeset
569 return v;
863ce5459aec simplify
michael
parents: 2045
diff changeset
570 }
863ce5459aec simplify
michael
parents: 2045
diff changeset
571
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
572 static int h261_decode_mb(H261Context *h){
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
573 MpegEncContext * const s = &h->s;
2330
380b62dce6ec simplify
michael
parents: 2329
diff changeset
574 int i, cbp, xy;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
575
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
576 cbp = 63;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
577 // Read mba
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
578 do{
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
579 h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table, H261_MBA_VLC_BITS, 2);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
580
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
581 /* Check for slice end */
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
582 /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
583 if (h->mba_diff == MBA_STARTCODE){ // start code
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
584 h->gob_start_code_skipped = 1;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
585 return SLICE_END;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
586 }
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
587 }
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
588 while( h->mba_diff == MBA_STUFFING ); // stuffing
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
589
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
590 if ( h->mba_diff < 0 ){
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
591 if ( get_bits_count(&s->gb) + 7 >= s->gb.size_in_bits )
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
592 return SLICE_END;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
593
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
594 av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
595 return SLICE_ERROR;
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
596 }
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
597
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
598 h->mba_diff += 1;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
599 h->current_mba += h->mba_diff;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
600
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
601 if ( h->current_mba > MBA_STUFFING )
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
602 return SLICE_ERROR;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
603
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
604 s->mb_x= ((h->gob_number-1) % 2) * 11 + ((h->current_mba-1) % 11);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
605 s->mb_y= ((h->gob_number-1) / 2) * 3 + ((h->current_mba-1) / 11);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
606 xy = s->mb_x + s->mb_y * s->mb_stride;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
607 ff_init_block_index(s);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
608 ff_update_block_index(s);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
609
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
610 // Read mtype
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
611 h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
612 h->mtype = h261_mtype_map[h->mtype];
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
613
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
614 // Read mquant
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
615 if ( IS_QUANT ( h->mtype ) ){
2134
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
616 ff_set_qscale(s, get_bits(&s->gb, 5));
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
617 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
618
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
619 s->mb_intra = IS_INTRA4x4(h->mtype);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
620
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
621 // Read mv
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
622 if ( IS_16X16 ( h->mtype ) ){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
623 // Motion vector data is included for all MC macroblocks. MVD is obtained from the macroblock vector by subtracting the
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
624 // vector of the preceding macroblock. For this calculation the vector of the preceding macroblock is regarded as zero in the
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
625 // following three situations:
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
626 // 1) evaluating MVD for macroblocks 1, 12 and 23;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
627 // 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
628 // 3) MTYPE of the previous macroblock was not MC.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
629 if ( ( h->current_mba == 1 ) || ( h->current_mba == 12 ) || ( h->current_mba == 23 ) ||
2330
380b62dce6ec simplify
michael
parents: 2329
diff changeset
630 ( h->mba_diff != 1))
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
631 {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
632 h->current_mv_x = 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
633 h->current_mv_y = 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
634 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
635
2046
863ce5459aec simplify
michael
parents: 2045
diff changeset
636 h->current_mv_x= decode_mv_component(&s->gb, h->current_mv_x);
863ce5459aec simplify
michael
parents: 2045
diff changeset
637 h->current_mv_y= decode_mv_component(&s->gb, h->current_mv_y);
2330
380b62dce6ec simplify
michael
parents: 2329
diff changeset
638 }else{
380b62dce6ec simplify
michael
parents: 2329
diff changeset
639 h->current_mv_x = 0;
380b62dce6ec simplify
michael
parents: 2329
diff changeset
640 h->current_mv_y = 0;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
641 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
642
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
643 // Read cbp
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
644 if ( HAS_CBP( h->mtype ) ){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
645 cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
646 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
647
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
648 if(s->mb_intra){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
649 s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
650 goto intra;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
651 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
652
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
653 //set motion vectors
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
654 s->mv_dir = MV_DIR_FORWARD;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
655 s->mv_type = MV_TYPE_16X16;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
656 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
2330
380b62dce6ec simplify
michael
parents: 2329
diff changeset
657 s->mv[0][0][0] = h->current_mv_x * 2;//gets divided by 2 in motion compensation
380b62dce6ec simplify
michael
parents: 2329
diff changeset
658 s->mv[0][0][1] = h->current_mv_y * 2;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
659
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
660 intra:
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
661 /* decode each block */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
662 if(s->mb_intra || HAS_CBP(h->mtype)){
2632
67171616ead6 avoid unneeded clear_blocks()
michael
parents: 2628
diff changeset
663 s->dsp.clear_blocks(s->block[0]);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
664 for (i = 0; i < 6; i++) {
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
665 if (h261_decode_block(h, s->block[i], i, cbp&32) < 0){
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
666 return SLICE_ERROR;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
667 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
668 cbp+=cbp;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
669 }
2632
67171616ead6 avoid unneeded clear_blocks()
michael
parents: 2628
diff changeset
670 }else{
67171616ead6 avoid unneeded clear_blocks()
michael
parents: 2628
diff changeset
671 for (i = 0; i < 6; i++)
67171616ead6 avoid unneeded clear_blocks()
michael
parents: 2628
diff changeset
672 s->block_last_index[i]= -1;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
673 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
674
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
675 MPV_decode_mb(s, s->block);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
676
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
677 return SLICE_OK;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
678 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
679
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
680 /**
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
681 * decodes a macroblock
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
682 * @return <0 if an error occured
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
683 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
684 static int h261_decode_block(H261Context * h, DCTELEM * block,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
685 int n, int coded)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
686 {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
687 MpegEncContext * const s = &h->s;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
688 int code, level, i, j, run;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
689 RLTable *rl = &h261_rl_tcoeff;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
690 const uint8_t *scan_table;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
691
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
692 // For the variable length encoding there are two code tables, one being used for
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
693 // the first transmitted LEVEL in INTER, INTER+MC and INTER+MC+FIL blocks, the second
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
694 // for all other LEVELs except the first one in INTRA blocks which is fixed length
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
695 // coded with 8 bits.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
696 // NOTE: the two code tables only differ in one VLC so we handle that manually.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
697 scan_table = s->intra_scantable.permutated;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
698 if (s->mb_intra){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
699 /* DC coef */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
700 level = get_bits(&s->gb, 8);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
701 // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
702 if((level&0x7F) == 0){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
703 av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
704 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
705 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
706 // The code 1000 0000 is not used, the reconstruction level of 1024 being coded as 1111 1111.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
707 if (level == 255)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
708 level = 128;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
709 block[0] = level;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
710 i = 1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
711 }else if(coded){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
712 // Run Level Code
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
713 // EOB Not possible for first level when cbp is available (that's why the table is different)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
714 // 0 1 1s
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
715 // * * 0*
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
716 int check = show_bits(&s->gb, 2);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
717 i = 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
718 if ( check & 0x2 ){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
719 skip_bits(&s->gb, 2);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
720 block[0] = ( check & 0x1 ) ? -1 : 1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
721 i = 1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
722 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
723 }else{
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
724 i = 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
725 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
726 if(!coded){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
727 s->block_last_index[n] = i - 1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
728 return 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
729 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
730 for(;;){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
731 code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_VLC_BITS, 2);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
732 if (code < 0){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
733 av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
734 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
735 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
736 if (code == rl->n) {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
737 /* escape */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
738 // The remaining combinations of (run, level) are encoded with a 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits level.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
739 run = get_bits(&s->gb, 6);
2332
cb3f0954e982 cleanup
michael
parents: 2331
diff changeset
740 level = get_sbits(&s->gb, 8);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
741 }else if(code == 0){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
742 break;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
743 }else{
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
744 run = rl->table_run[code];
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
745 level = rl->table_level[code];
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
746 if (get_bits1(&s->gb))
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
747 level = -level;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
748 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
749 i += run;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
750 if (i >= 64){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
751 av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
752 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
753 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
754 j = scan_table[i];
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
755 block[j] = level;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
756 i++;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
757 }
2134
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
758 s->block_last_index[n] = i-1;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
759 return 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
760 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
761
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
762 /**
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
763 * decodes the H261 picture header.
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
764 * @return <0 if no startcode found
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
765 */
3071
cc0357a90e8f make some functions static (patch by Dieter < freebsd at sopwith.solgatos.com >)
aurel
parents: 3036
diff changeset
766 static int h261_decode_picture_header(H261Context *h){
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
767 MpegEncContext * const s = &h->s;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
768 int format, i;
2290
89a5e4601343 nonsense removial
michael
parents: 2270
diff changeset
769 uint32_t startcode= 0;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
770
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
771 for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
772 startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
773
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
774 if(startcode == 0x10)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
775 break;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
776 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
777
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
778 if (startcode != 0x10){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
779 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
780 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
781 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
782
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
783 /* temporal reference */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
784 s->picture_number = get_bits(&s->gb, 5); /* picture timestamp */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
785
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
786 /* PTYPE starts here */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
787 skip_bits1(&s->gb); /* split screen off */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
788 skip_bits1(&s->gb); /* camera off */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
789 skip_bits1(&s->gb); /* freeze picture release off */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
790
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
791 format = get_bits1(&s->gb);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
792
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
793 //only 2 formats possible
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
794 if (format == 0){//QCIF
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
795 s->width = 176;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
796 s->height = 144;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
797 s->mb_width = 11;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
798 s->mb_height = 9;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
799 }else{//CIF
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
800 s->width = 352;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
801 s->height = 288;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
802 s->mb_width = 22;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
803 s->mb_height = 18;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
804 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
805
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
806 s->mb_num = s->mb_width * s->mb_height;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
807
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
808 skip_bits1(&s->gb); /* still image mode off */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
809 skip_bits1(&s->gb); /* Reserved */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
810
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
811 /* PEI */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
812 while (get_bits1(&s->gb) != 0){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
813 skip_bits(&s->gb, 8);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
814 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
815
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
816 // h261 has no I-FRAMES, but if we pass I_TYPE for the first frame, the codec crashes if it does
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
817 // not contain all I-blocks (e.g. when a packet is lost)
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
818 s->pict_type = P_TYPE;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
819
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
820 h->gob_number = 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
821 return 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
822 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
823
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
824 static int h261_decode_gob(H261Context *h){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
825 MpegEncContext * const s = &h->s;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
826
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
827 ff_set_qscale(s, s->qscale);
2134
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
828
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
829 /* decode mb's */
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
830 while(h->current_mba <= MBA_STUFFING)
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
831 {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
832 int ret;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
833 /* DCT & quantize */
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
834 ret= h261_decode_mb(h);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
835 if(ret<0){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
836 if(ret==SLICE_END){
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
837 h261_decode_mb_skipped(h, h->current_mba, 33);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
838 return 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
839 }
2225
35fc37209ea0 H.261 decoder improvements
michael
parents: 2143
diff changeset
840 av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", s->mb_x + s->mb_y*s->mb_stride);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
841 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
842 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
843
2134
8afd396fa198 - Support empty GOB's (no mb's) and skip all mb's
michael
parents: 2050
diff changeset
844 h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
845 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
846
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
847 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
848 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
849
3455
cc4b4ea83e29 --enable/disable parsers. Warning: some combinations are broken.
mru
parents: 3317
diff changeset
850 #ifdef CONFIG_H261_PARSER
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
851 static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
2345
ada3891b859d H261 fixing and cleaning:
michael
parents: 2332
diff changeset
852 int vop_found, i, j;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
853 uint32_t state;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
854
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
855 vop_found= pc->frame_start_found;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
856 state= pc->state;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
857
2356
def33a002b94 fix parser
michael
parents: 2345
diff changeset
858 for(i=0; i<buf_size && !vop_found; i++){
def33a002b94 fix parser
michael
parents: 2345
diff changeset
859 state= (state<<8) | buf[i];
def33a002b94 fix parser
michael
parents: 2345
diff changeset
860 for(j=0; j<8; j++){
def33a002b94 fix parser
michael
parents: 2345
diff changeset
861 if(((state>>j)&0xFFFFF) == 0x00010){
def33a002b94 fix parser
michael
parents: 2345
diff changeset
862 i++;
def33a002b94 fix parser
michael
parents: 2345
diff changeset
863 vop_found=1;
def33a002b94 fix parser
michael
parents: 2345
diff changeset
864 break;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
865 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
866 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
867 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
868 if(vop_found){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
869 for(; i<buf_size; i++){
2356
def33a002b94 fix parser
michael
parents: 2345
diff changeset
870 state= (state<<8) | buf[i];
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
871 for(j=0; j<8; j++){
2356
def33a002b94 fix parser
michael
parents: 2345
diff changeset
872 if(((state>>j)&0xFFFFF) == 0x00010){
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
873 pc->frame_start_found=0;
2356
def33a002b94 fix parser
michael
parents: 2345
diff changeset
874 pc->state= state>>(2*8);
def33a002b94 fix parser
michael
parents: 2345
diff changeset
875 return i-1;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
876 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
877 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
878 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
879 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
880
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
881 pc->frame_start_found= vop_found;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
882 pc->state= state;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
883 return END_NOT_FOUND;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
884 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
885
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
886 static int h261_parse(AVCodecParserContext *s,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
887 AVCodecContext *avctx,
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
888 uint8_t **poutbuf, int *poutbuf_size,
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
889 const uint8_t *buf, int buf_size)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
890 {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
891 ParseContext *pc = s->priv_data;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
892 int next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2792
diff changeset
893
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
894 next= h261_find_frame_end(pc,avctx, buf, buf_size);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
895 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
896 *poutbuf = NULL;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
897 *poutbuf_size = 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
898 return buf_size;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
899 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
900 *poutbuf = (uint8_t *)buf;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
901 *poutbuf_size = buf_size;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
902 return next;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
903 }
3455
cc4b4ea83e29 --enable/disable parsers. Warning: some combinations are broken.
mru
parents: 3317
diff changeset
904 #endif
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
905
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
906 /**
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
907 * returns the number of bytes consumed for building the current frame
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
908 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
909 static int get_consumed_bytes(MpegEncContext *s, int buf_size){
2356
def33a002b94 fix parser
michael
parents: 2345
diff changeset
910 int pos= get_bits_count(&s->gb)>>3;
def33a002b94 fix parser
michael
parents: 2345
diff changeset
911 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
def33a002b94 fix parser
michael
parents: 2345
diff changeset
912 if(pos+10>buf_size) pos=buf_size; // oops ;)
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
913
2356
def33a002b94 fix parser
michael
parents: 2345
diff changeset
914 return pos;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
915 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
916
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
917 static int h261_decode_frame(AVCodecContext *avctx,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
918 void *data, int *data_size,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
919 uint8_t *buf, int buf_size)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
920 {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
921 H261Context *h= avctx->priv_data;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
922 MpegEncContext *s = &h->s;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
923 int ret;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
924 AVFrame *pict = data;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
925
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
926 #ifdef DEBUG
3177
8d1b2cc2a75b (f)printf --> av_log conversion
diego
parents: 3071
diff changeset
927 av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
8d1b2cc2a75b (f)printf --> av_log conversion
diego
parents: 3071
diff changeset
928 av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
929 #endif
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
930 s->flags= avctx->flags;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
931 s->flags2= avctx->flags2;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
932
2356
def33a002b94 fix parser
michael
parents: 2345
diff changeset
933 h->gob_start_code_skipped=0;
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
934
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
935 retry:
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
936
2047
541686b38a5e removing h263 specific code
michael
parents: 2046
diff changeset
937 init_get_bits(&s->gb, buf, buf_size*8);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
938
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
939 if(!s->context_initialized){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
940 if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
941 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
942 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
943
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
944 //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
945 if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
946 int i= ff_find_unused_picture(s, 0);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
947 s->current_picture_ptr= &s->picture[i];
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
948 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
949
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
950 ret = h261_decode_picture_header(h);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
951
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
952 /* skip if the header was thrashed */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
953 if (ret < 0){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
954 av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
955 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
956 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
957
2270
21f450be6cb5 lowres width/height cleanup 3rd try
michael
parents: 2266
diff changeset
958 if (s->width != avctx->coded_width || s->height != avctx->coded_height){
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
959 ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
960 s->parse_context.buffer=0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
961 MPV_common_end(s);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
962 s->parse_context= pc;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
963 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
964 if (!s->context_initialized) {
2270
21f450be6cb5 lowres width/height cleanup 3rd try
michael
parents: 2266
diff changeset
965 avcodec_set_dimensions(avctx, s->width, s->height);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
966
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
967 goto retry;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
968 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
969
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
970 // for hurry_up==5
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
971 s->current_picture.pict_type= s->pict_type;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
972 s->current_picture.key_frame= s->pict_type == I_TYPE;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
973
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
974 /* skip everything if we are in a hurry>=5 */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
975 if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size);
2792
0a8c847ad5e7 skip_idct
michael
parents: 2637
diff changeset
976 if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
0a8c847ad5e7 skip_idct
michael
parents: 2637
diff changeset
977 ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
0a8c847ad5e7 skip_idct
michael
parents: 2637
diff changeset
978 || avctx->skip_frame >= AVDISCARD_ALL)
0a8c847ad5e7 skip_idct
michael
parents: 2637
diff changeset
979 return get_consumed_bytes(s, buf_size);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
980
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
981 if(MPV_frame_start(s, avctx) < 0)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
982 return -1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
983
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
984 ff_er_frame_start(s);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
985
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
986 /* decode each macroblock */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
987 s->mb_x=0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
988 s->mb_y=0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
989
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
990 while(h->gob_number < (s->mb_height==18 ? 12 : 5)){
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
991 if(ff_h261_resync(h)<0)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
992 break;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
993 h261_decode_gob(h);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
994 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
995 MPV_frame_end(s);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
996
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
997 assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
998 assert(s->current_picture.pict_type == s->pict_type);
2356
def33a002b94 fix parser
michael
parents: 2345
diff changeset
999 *pict= *(AVFrame*)s->current_picture_ptr;
2047
541686b38a5e removing h263 specific code
michael
parents: 2046
diff changeset
1000 ff_print_debug_info(s, pict);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1001
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1002 /* Return the Picture timestamp as the frame number */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1003 /* we substract 1 because it is added on utils.c */
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1004 avctx->frame_number = s->picture_number - 1;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1005
2047
541686b38a5e removing h263 specific code
michael
parents: 2046
diff changeset
1006 *data_size = sizeof(AVFrame);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1007
2047
541686b38a5e removing h263 specific code
michael
parents: 2046
diff changeset
1008 return get_consumed_bytes(s, buf_size);
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1009 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1010
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1011 static int h261_decode_end(AVCodecContext *avctx)
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1012 {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1013 H261Context *h= avctx->priv_data;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1014 MpegEncContext *s = &h->s;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1015
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1016 MPV_common_end(s);
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1017 return 0;
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1018 }
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1019
2408
a6e4da1c28ee Disable encoders patch by (Gianluigi Tiesi <mplayer netfarm it>)
michael
parents: 2370
diff changeset
1020 #ifdef CONFIG_ENCODERS
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1021 AVCodec h261_encoder = {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1022 "h261",
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1023 CODEC_TYPE_VIDEO,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1024 CODEC_ID_H261,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1025 sizeof(H261Context),
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1026 MPV_encode_init,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1027 MPV_encode_picture,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1028 MPV_encode_end,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1029 };
2408
a6e4da1c28ee Disable encoders patch by (Gianluigi Tiesi <mplayer netfarm it>)
michael
parents: 2370
diff changeset
1030 #endif
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2291
diff changeset
1031
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1032 AVCodec h261_decoder = {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1033 "h261",
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1034 CODEC_TYPE_VIDEO,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1035 CODEC_ID_H261,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1036 sizeof(H261Context),
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1037 h261_decode_init,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1038 NULL,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1039 h261_decode_end,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1040 h261_decode_frame,
2356
def33a002b94 fix parser
michael
parents: 2345
diff changeset
1041 CODEC_CAP_DR1,
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1042 };
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1043
3455
cc4b4ea83e29 --enable/disable parsers. Warning: some combinations are broken.
mru
parents: 3317
diff changeset
1044 #ifdef CONFIG_H261_PARSER
2044
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1045 AVCodecParser h261_parser = {
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1046 { CODEC_ID_H261 },
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1047 sizeof(ParseContext),
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1048 NULL,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1049 h261_parse,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1050 ff_parse_close,
b6f2add2511e h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
diff changeset
1051 };
3455
cc4b4ea83e29 --enable/disable parsers. Warning: some combinations are broken.
mru
parents: 3317
diff changeset
1052 #endif