| 590 | } |
| 591 | |
| 592 | static int decode(AVCodecContext *avctx, AVSubtitle *sub, |
| 593 | int *got_sub_ptr, const AVPacket *avpkt) |
| 594 | { |
| 595 | const uint8_t *buf = avpkt->data; |
| 596 | int buf_size = avpkt->size; |
| 597 | |
| 598 | const uint8_t *buf_end; |
| 599 | uint8_t segment_type; |
| 600 | int segment_length; |
| 601 | int i, ret; |
| 602 | |
| 603 | ff_dlog(avctx, "PGS sub packet:\n"); |
| 604 | |
| 605 | for (i = 0; i < buf_size; i++) { |
| 606 | ff_dlog(avctx, "%02x ", buf[i]); |
| 607 | if (i % 16 == 15) |
| 608 | ff_dlog(avctx, "\n"); |
| 609 | } |
| 610 | |
| 611 | if (i & 15) |
| 612 | ff_dlog(avctx, "\n"); |
| 613 | |
| 614 | *got_sub_ptr = 0; |
| 615 | |
| 616 | /* Ensure that we have received at a least a segment code and segment length */ |
| 617 | if (buf_size < 3) |
| 618 | return -1; |
| 619 | |
| 620 | buf_end = buf + buf_size; |
| 621 | |
| 622 | /* Step through buffer to identify segments */ |
| 623 | while (buf < buf_end) { |
| 624 | segment_type = bytestream_get_byte(&buf); |
| 625 | segment_length = bytestream_get_be16(&buf); |
| 626 | |
| 627 | ff_dlog(avctx, "Segment Length %d, Segment Type %x\n", segment_length, segment_type); |
| 628 | |
| 629 | if (segment_type != DISPLAY_SEGMENT && segment_length > buf_end - buf) |
| 630 | break; |
| 631 | |
| 632 | ret = 0; |
| 633 | switch (segment_type) { |
| 634 | case PALETTE_SEGMENT: |
| 635 | ret = parse_palette_segment(avctx, buf, segment_length); |
| 636 | break; |
| 637 | case OBJECT_SEGMENT: |
| 638 | ret = parse_object_segment(avctx, buf, segment_length); |
| 639 | break; |
| 640 | case PRESENTATION_SEGMENT: |
| 641 | ret = parse_presentation_segment(avctx, buf, segment_length, sub->pts); |
| 642 | break; |
| 643 | case WINDOW_SEGMENT: |
| 644 | /* |
| 645 | * Window Segment Structure (No new information provided): |
| 646 | * 2 bytes: Unknown, |
| 647 | * 2 bytes: X position of subtitle, |
| 648 | * 2 bytes: Y position of subtitle, |
| 649 | * 2 bytes: Width of subtitle, |
nothing calls this directly
no test coverage detected