static int parse_presentation_segment(AVCodecContext *avctx,

                                      const uint8_t *buf, int buf_size,

                                      int64_t pts)

{

    PGSSubContext *ctx = avctx->priv_data;



    int x, y, ret;



    int w = bytestream_get_be16(&buf);

    int h = bytestream_get_be16(&buf);



    ctx->presentation.pts = pts;



    av_dlog(avctx, "Video Dimensions %dx%d\n",

            w, h);

    ret = ff_set_dimensions(avctx, w, h);

    if (ret < 0)

        return ret;



    /* Skip 1 bytes of unknown, frame rate? */

    buf++;



    ctx->presentation.id_number = bytestream_get_be16(&buf);



    /*

     * Skip 3 bytes of unknown:

     *     state

     *     palette_update_flag (0x80),

     *     palette_id_to_use,

     */

    buf += 3;



    ctx->presentation.object_number = bytestream_get_byte(&buf);

    ctx->presentation.composition_flag = 0;

    if (!ctx->presentation.object_number)

        return 0;



    /*

     * Skip 3 bytes of unknown:

     *     object_id_ref (2 bytes),

     *     window_id_ref,

     */

    buf += 3;

    ctx->presentation.composition_flag = bytestream_get_byte(&buf);



    x = bytestream_get_be16(&buf);

    y = bytestream_get_be16(&buf);



    /* TODO If cropping, cropping_x, cropping_y, cropping_width, cropping_height (all 2 bytes).*/



    av_dlog(avctx, "Subtitle Placement x=%d, y=%d\n", x, y);



    if (x > avctx->width || y > avctx->height) {

        av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",

               x, y, avctx->width, avctx->height);

        x = 0; y = 0;

    }



    /* Fill in dimensions */

    ctx->presentation.x = x;

    ctx->presentation.y = y;



    return 0;

}

static int parse_presentation_segment(AVCodecContext *avctx,

                                      const uint8_t *buf, int buf_size,

                                      int64_t pts)

{

    PGSSubContext *ctx = avctx->priv_data;



    int x, y, ret;



    int w = bytestream_get_be16(&buf);

    int h = bytestream_get_be16(&buf);



    ctx->presentation.pts = pts;



    av_dlog(avctx, "Video Dimensions %dx%d\n",

            w, h);

    ret = ff_set_dimensions(avctx, w, h);

    if (ret < 0)

        return ret;



    

    buf++;



    ctx->presentation.id_number = bytestream_get_be16(&buf);



    











    buf += 3;



    ctx->presentation.object_number = bytestream_get_byte(&buf);

    ctx->presentation.composition_flag = 0;

    if (!ctx->presentation.object_number)

        return 0;



    









    buf += 3;

    ctx->presentation.composition_flag = bytestream_get_byte(&buf);



    x = bytestream_get_be16(&buf);

    y = bytestream_get_be16(&buf);



    



    av_dlog(avctx, "Subtitle Placement x=%d, y=%d\n", x, y);



    if (x > avctx->width || y > avctx->height) {

        av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",

               x, y, avctx->width, avctx->height);

        x = 0; y = 0;

    }



    

    ctx->presentation.x = x;

    ctx->presentation.y = y;



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0,

                                      const uint8_t *VAR_1, int VAR_2,

                                      int64_t VAR_3)

{

    PGSSubContext *ctx = VAR_0->priv_data;



    int VAR_4, VAR_5, VAR_6;



    int VAR_7 = bytestream_get_be16(&VAR_1);

    int VAR_8 = bytestream_get_be16(&VAR_1);



    ctx->presentation.VAR_3 = VAR_3;



    av_dlog(VAR_0, "Video Dimensions %dx%d\n",

            VAR_7, VAR_8);

    VAR_6 = ff_set_dimensions(VAR_0, VAR_7, VAR_8);

    if (VAR_6 < 0)

        return VAR_6;



    

    VAR_1++;



    ctx->presentation.id_number = bytestream_get_be16(&VAR_1);



    











    VAR_1 += 3;



    ctx->presentation.object_number = bytestream_get_byte(&VAR_1);

    ctx->presentation.composition_flag = 0;

    if (!ctx->presentation.object_number)

        return 0;



    









    VAR_1 += 3;

    ctx->presentation.composition_flag = bytestream_get_byte(&VAR_1);



    VAR_4 = bytestream_get_be16(&VAR_1);

    VAR_5 = bytestream_get_be16(&VAR_1);



    



    av_dlog(VAR_0, "Subtitle Placement VAR_4=%d, VAR_5=%d\n", VAR_4, VAR_5);



    if (VAR_4 > VAR_0->width || VAR_5 > VAR_0->height) {

        av_log(VAR_0, AV_LOG_ERROR, "Subtitle out of video bounds. VAR_4 = %d, VAR_5 = %d, video width = %d, video height = %d.\n",

               VAR_4, VAR_5, VAR_0->width, VAR_0->height);

        VAR_4 = 0; VAR_5 = 0;

    }



    

    ctx->presentation.VAR_4 = VAR_4;

    ctx->presentation.VAR_5 = VAR_5;



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0,
const uint8_t *VAR_1, int VAR_2,
int64_t VAR_3)
{ PGSSubContext *ctx = VAR_0->priv_data; int VAR_4, VAR_5, VAR_6; int VAR_7 = bytestream_get_be16(&VAR_1); int VAR_8 = bytestream_get_be16(&VAR_1); ctx->presentation.VAR_3 = VAR_3; av_dlog(VAR_0, "Video Dimensions %dx%d\n",
VAR_7, VAR_8); VAR_6 = ff_set_dimensions(VAR_0, VAR_7, VAR_8); if (VAR_6 < 0)
return VAR_6; VAR_1++; ctx->presentation.id_number = bytestream_get_be16(&VAR_1); VAR_1 += 3; ctx->presentation.object_number = bytestream_get_byte(&VAR_1); ctx->presentation.composition_flag = 0; if (!ctx->presentation.object_number)
return 0; VAR_1 += 3; ctx->presentation.composition_flag = bytestream_get_byte(&VAR_1); VAR_4 = bytestream_get_be16(&VAR_1); VAR_5 = bytestream_get_be16(&VAR_1); av_dlog(VAR_0, "Subtitle Placement VAR_4=%d, VAR_5=%d\n", VAR_4, VAR_5); if (VAR_4 > VAR_0->width || VAR_5 > VAR_0->height) { av_log(VAR_0, AV_LOG_ERROR, "Subtitle out of video bounds. VAR_4 = %d, VAR_5 = %d, video width = %d, video height = %d.\n",
VAR_4, VAR_5, VAR_0->width, VAR_0->height); VAR_4 = 0; VAR_5 = 0; } ctx->presentation.VAR_4 = VAR_4; ctx->presentation.VAR_5 = VAR_5; return 0; }