1 /*
2 * RTP packetization for H.263 video
3 * Copyright (c) 2012 Martin Storsjo
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
26
35 };
36
42 };
43
45 const uint8_t *buf,
int len,
int ebits,
int m)
46 {
49
51 put_bits(&pb, 1, 0);
/* F - 0, mode A */
52 put_bits(&pb, 1, 0);
/* P - 0, normal I/P */
53 put_bits(&pb, 3, 0);
/* SBIT - 0 bits */
57 put_bits(&pb, 1,
info->u);
/* U - unrestricted motion vector */
58 put_bits(&pb, 1,
info->s);
/* S - syntax-baesd arithmetic coding */
60 put_bits(&pb, 4, 0);
/* R - reserved */
65 memcpy(
s->buf + 4, buf,
len);
66
68 }
69
72 int len,
int sbits,
int ebits,
int m)
73 {
76
78 put_bits(&pb, 1, 1);
/* F - 1, mode B */
79 put_bits(&pb, 1, 0);
/* P - 0, mode B */
80 put_bits(&pb, 3, sbits);
/* SBIT - 0 bits */
81 put_bits(&pb, 3, ebits);
/* EBIT - 0 bits */
83 put_bits(&pb, 5,
state->quant);
/* QUANT - quantizer for the first MB */
86 put_bits(&pb, 2, 0);
/* R - reserved */
88 put_bits(&pb, 1,
info->u);
/* U - unrestricted motion vector */
89 put_bits(&pb, 1,
info->s);
/* S - syntax-baesd arithmetic coding */
91 put_bits(&pb, 7,
state->hmv1);
/* HVM1 - horizontal motion vector 1 */
92 put_bits(&pb, 7,
state->vmv1);
/* VMV1 - vertical motion vector 1 */
93 put_bits(&pb, 7,
state->hmv2);
/* HVM2 - horizontal motion vector 2 */
94 put_bits(&pb, 7,
state->vmv2);
/* VMV2 - vertical motion vector 2 */
96 memcpy(
s->buf + 8, buf,
len);
97
99 }
100
102 const uint8_t *
mb_info,
int mb_info_size)
103 {
105 int len, sbits = 0, ebits = 0;
109 int mb_info_pos = 0, mb_info_count = mb_info_size / 12;
110 const uint8_t *buf_base = buf;
111
112 s->timestamp =
s->cur_timestamp;
113
115 if (
get_bits(&gb, 22) == 0x20) {
/* Picture Start Code */
117 skip_bits(&gb, 2);
/* PTYPE start, H.261 disambiguation */
118 skip_bits(&gb, 3);
/* Split screen, document camera, freeze picture release */
125 }
126
130
131 /* Look for a better place to split the frame into packets. */
136 if (
len ==
s->max_payload_size - 8) {
137 /* Skip mb info prior to the start of the current ptr */
138 while (mb_info_pos < mb_info_count) {
140 if (
pos >= buf - buf_base)
141 break;
142 mb_info_pos++;
143 }
144 /* Find the first mb info past the end pointer */
145 while (mb_info_pos + 1 < mb_info_count) {
147 if (
pos >= end - buf_base)
148 break;
149 mb_info_pos++;
150 }
151 if (mb_info_pos < mb_info_count) {
152 const uint8_t *ptr = &
mb_info[12*mb_info_pos];
153 /* get position in bits in the input packet at which the next info block should be used */
154 uint32_t bit_pos =
AV_RL32(ptr);
155 /* get position in bytes */
156 uint32_t pos_next_mb_info = (bit_pos + 7)/8;
157 /* check if data from the next MB info block should be used */
158 if (pos_next_mb_info <= end - buf_base) {
159 state.quant = ptr[4];
162 state.hmv1 = (int8_t) ptr[8];
163 state.vmv1 = (int8_t) ptr[9];
164 state.hmv2 = (int8_t) ptr[10];
165 state.vmv2 = (int8_t) ptr[11];
166 ebits = 8 * pos_next_mb_info - bit_pos;
167 len = pos_next_mb_info - (buf - buf_base);
168 mb_info_pos++;
169 }
170 } else {
172 "use -mb_info %d or -ps 1.\n",
173 s->max_payload_size - 8);
174 }
175 }
176 }
177
178 if (
size > 2 && !buf[0] && !buf[1])
180 else
183
184 if (ebits) {
185 sbits = 8 - ebits;
187 } else {
188 sbits = 0;
189 }
192 ebits = 0;
193 }
194 }