* Parse the presentation segment packet. * * The presentation segment contains details on the video * width, video height, x & y subtitle position. * * @param avctx contains the current codec context * @param buf pointer to the packet to process * @param buf_size size of packet to process * @todo TODO: Implement cropping */
| 387 | * @todo TODO: Implement cropping |
| 388 | */ |
| 389 | static int parse_presentation_segment(AVCodecContext *avctx, |
| 390 | const uint8_t *buf, int buf_size, |
| 391 | int64_t pts) |
| 392 | { |
| 393 | PGSSubContext *ctx = avctx->priv_data; |
| 394 | int i, state, ret; |
| 395 | const uint8_t *buf_end = buf + buf_size; |
| 396 | |
| 397 | // Video descriptor |
| 398 | int w = bytestream_get_be16(&buf); |
| 399 | int h = bytestream_get_be16(&buf); |
| 400 | |
| 401 | ctx->presentation.pts = pts; |
| 402 | |
| 403 | ff_dlog(avctx, "Video Dimensions %dx%d\n", |
| 404 | w, h); |
| 405 | ret = ff_set_dimensions(avctx, w, h); |
| 406 | if (ret < 0) |
| 407 | return ret; |
| 408 | |
| 409 | /* Skip 1 bytes of unknown, frame rate */ |
| 410 | buf++; |
| 411 | |
| 412 | // Composition descriptor |
| 413 | ctx->presentation.id_number = bytestream_get_be16(&buf); |
| 414 | /* |
| 415 | * state is a 2 bit field that defines pgs epoch boundaries |
| 416 | * 00 - Normal, previously defined objects and palettes are still valid |
| 417 | * 01 - Acquisition point, previous objects and palettes can be released |
| 418 | * 10 - Epoch start, previous objects and palettes can be released |
| 419 | * 11 - Epoch continue, previous objects and palettes can be released |
| 420 | * |
| 421 | * reserved 6 bits discarded |
| 422 | */ |
| 423 | state = bytestream_get_byte(&buf) >> 6; |
| 424 | if (state != 0) { |
| 425 | flush_cache(avctx); |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * skip palette_update_flag (0x80), |
| 430 | */ |
| 431 | buf += 1; |
| 432 | ctx->presentation.palette_id = bytestream_get_byte(&buf); |
| 433 | ctx->presentation.object_count = bytestream_get_byte(&buf); |
| 434 | if (ctx->presentation.object_count > MAX_OBJECT_REFS) { |
| 435 | av_log(avctx, AV_LOG_ERROR, |
| 436 | "Invalid number of presentation objects %d\n", |
| 437 | ctx->presentation.object_count); |
| 438 | ctx->presentation.object_count = 2; |
| 439 | if (avctx->err_recognition & AV_EF_EXPLODE) { |
| 440 | return AVERROR_INVALIDDATA; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | |
| 445 | for (i = 0; i < ctx->presentation.object_count; i++) |
| 446 | { |
no test coverage detected