MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / parse_object_segment

Function parse_object_segment

libavcodec/pgssubdec.c:232–315  ·  view source on GitHub ↗

* Parse the picture segment packet. * * The picture segment contains details on the sequence id, * width, height and Run Length Encoded (RLE) bitmap data. * * @param avctx contains the current codec context * @param buf pointer to the packet to process * @param buf_size size of packet to process */

Source from the content-addressed store, hash-verified

230 * @param buf_size size of packet to process
231 */
232static int parse_object_segment(AVCodecContext *avctx,
233 const uint8_t *buf, int buf_size)
234{
235 PGSSubContext *ctx = avctx->priv_data;
236 PGSSubObject *object;
237
238 uint8_t sequence_desc;
239 unsigned int rle_bitmap_len, width, height;
240 int id;
241
242 if (buf_size <= 4)
243 return AVERROR_INVALIDDATA;
244 buf_size -= 4;
245
246 id = bytestream_get_be16(&buf);
247 object = find_object(id, &ctx->objects);
248 if (!object) {
249 if (ctx->objects.count >= MAX_EPOCH_OBJECTS) {
250 av_log(avctx, AV_LOG_ERROR, "Too many objects in epoch\n");
251 return AVERROR_INVALIDDATA;
252 }
253 object = &ctx->objects.object[ctx->objects.count++];
254 object->id = id;
255 }
256
257 /* skip object version number */
258 buf += 1;
259
260 /* Read the Sequence Description to determine if start of RLE data or appended to previous RLE */
261 sequence_desc = bytestream_get_byte(&buf);
262
263 if (!(sequence_desc & 0x80)) {
264 /* Additional RLE data */
265 if (buf_size > object->rle_remaining_len)
266 return AVERROR_INVALIDDATA;
267
268 memcpy(object->rle + object->rle_data_len, buf, buf_size);
269 object->rle_data_len += buf_size;
270 object->rle_remaining_len -= buf_size;
271
272 return 0;
273 }
274
275 if (buf_size <= 7)
276 return AVERROR_INVALIDDATA;
277 buf_size -= 7;
278
279 /* Decode rle bitmap length, stored size includes width/height data */
280 rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
281
282 if (buf_size > rle_bitmap_len) {
283 av_log(avctx, AV_LOG_ERROR,
284 "Buffer dimension %d larger than the expected RLE data %d\n",
285 buf_size, rle_bitmap_len);
286 return AVERROR_INVALIDDATA;
287 }
288
289 /* Get bitmap dimensions from data */

Callers 1

decodeFunction · 0.85

Calls 3

find_objectFunction · 0.85
av_logFunction · 0.85
av_fast_padded_mallocFunction · 0.85

Tested by

no test coverage detected