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
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 */
55 put_bits(&pb, 3, info->
src);
/* SRC - source format */
56 put_bits(&pb, 1, info->
i);
/* I - inter/intra */
57 put_bits(&pb, 1, info->
u);
/* U - unrestricted motion vector */
58 put_bits(&pb, 1, info->
s);
/* S - syntax-baesd arithmetic coding */
59 put_bits(&pb, 1, info->
a);
/* A - advanced prediction */
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 */
82 put_bits(&pb, 3, info->
src);
/* SRC - source format */
83 put_bits(&pb, 5, state->
quant);
/* QUANT - quantizer for the first MB */
85 put_bits(&pb, 9, state->
mba);
/* MBA - MB address */
86 put_bits(&pb, 2, 0);
/* R - reserved */
87 put_bits(&pb, 1, info->
i);
/* I - inter/intra */
88 put_bits(&pb, 1, info->
u);
/* U - unrestricted motion vector */
89 put_bits(&pb, 1, info->
s);
/* S - syntax-baesd arithmetic coding */
90 put_bits(&pb, 1, info->
a);
/* A - advanced prediction */
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;
111
113
115 if (
get_bits(&gb, 22) == 0x20) {
/* Picture Start Code */
117 skip_bits(&gb, 2);
/* PTYPE start, H261 disambiguation */
118 skip_bits(&gb, 3);
/* Split screen, document camera, freeze picture release */
125 }
126
127 while (size > 0) {
130
131 /* Look for a better place to split the frame into packets. */
132 if (len < size) {
134 buf + len);
137 /* Skip mb info prior to the start of the current ptr */
138 while (mb_info_pos < mb_info_count) {
139 uint32_t pos =
AV_RL32(&mb_info[12*mb_info_pos])/8;
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) {
146 uint32_t pos =
AV_RL32(&mb_info[12*(mb_info_pos + 1)])/8;
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 uint32_t bit_pos =
AV_RL32(ptr);
154 uint32_t pos = (bit_pos + 7)/8;
155 if (pos <= end - buf_base) {
156 state.
quant = ptr[4];
159 state.
hmv1 = (int8_t) ptr[8];
160 state.
vmv1 = (int8_t) ptr[9];
161 state.
hmv2 = (int8_t) ptr[10];
162 state.
vmv2 = (int8_t) ptr[11];
163 ebits = 8 * pos - bit_pos;
164 len = pos - (buf - buf_base);
165 mb_info_pos++;
166 } else {
168 "Unable to split H263 packet, use -mb_info %d "
170 }
171 } else {
173 "use -mb_info %d or -ps 1.\n",
175 }
176 }
177 }
178
179 if (size > 2 && !buf[0] && !buf[1])
180 send_mode_a(s1, &info, buf, len, ebits, len == size);
181 else
182 send_mode_b(s1, &info, &packet_start_state, buf, len, sbits,
183 ebits, len == size);
184
185 if (ebits) {
186 sbits = 8 - ebits;
187 len--;
188 } else {
189 sbits = 0;
190 }
193 ebits = 0;
194 }
195 }