static int mov_read_sv3d(MOVContext *c, AVIOContext *pb, MOVAtom atom)

{

    AVStream *st;

    MOVStreamContext *sc;

    int size;

    int32_t yaw, pitch, roll;

    size_t l = 0, t = 0, r = 0, b = 0;

    size_t padding = 0;

    uint32_t tag;

    enum AVSphericalProjection projection;



    if (c->fc->nb_streams < 1)

        return 0;



    st = c->fc->streams[c->fc->nb_streams - 1];

    sc = st->priv_data;



    if (atom.size < 8) {

        av_log(c->fc, AV_LOG_ERROR, "Empty spherical video box\n");

        return AVERROR_INVALIDDATA;

    }



    size = avio_rb32(pb);

    if (size <= 12 || size > atom.size)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(pb);

    if (tag != MKTAG('s','v','h','d')) {

        av_log(c->fc, AV_LOG_ERROR, "Missing spherical video header\n");

        return 0;

    }

    avio_skip(pb, 4); /*  version + flags */

    avio_skip(pb, size - 12); /* metadata_source */



    size = avio_rb32(pb);

    if (size > atom.size)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(pb);

    if (tag != MKTAG('p','r','o','j')) {

        av_log(c->fc, AV_LOG_ERROR, "Missing projection box\n");

        return 0;

    }



    size = avio_rb32(pb);

    if (size > atom.size)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(pb);

    if (tag != MKTAG('p','r','h','d')) {

        av_log(c->fc, AV_LOG_ERROR, "Missing projection header box\n");

        return 0;

    }

    avio_skip(pb, 4); /*  version + flags */



    /* 16.16 fixed point */

    yaw   = avio_rb32(pb);

    pitch = avio_rb32(pb);

    roll  = avio_rb32(pb);



    size = avio_rb32(pb);

    if (size > atom.size)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(pb);

    avio_skip(pb, 4); /*  version + flags */

    switch (tag) {

    case MKTAG('c','b','m','p'):

        projection = AV_SPHERICAL_CUBEMAP;

        padding = avio_rb32(pb);

        break;

    case MKTAG('e','q','u','i'):

        t = avio_rb32(pb);

        b = avio_rb32(pb);

        l = avio_rb32(pb);

        r = avio_rb32(pb);



        if (b >= UINT_MAX - t || r >= UINT_MAX - l) {

            av_log(c->fc, AV_LOG_ERROR,

                   "Invalid bounding rectangle coordinates %"SIZE_SPECIFIER","

                   "%"SIZE_SPECIFIER",%"SIZE_SPECIFIER",%"SIZE_SPECIFIER"\n",

                   l, t, r, b);

            return AVERROR_INVALIDDATA;

        }



        if (l || t || r || b)

            projection = AV_SPHERICAL_EQUIRECTANGULAR_TILE;

        else

            projection = AV_SPHERICAL_EQUIRECTANGULAR;

        break;

    default:

        av_log(c->fc, AV_LOG_ERROR, "Unknown projection type\n");

        return 0;

    }



    sc->spherical = av_spherical_alloc(&sc->spherical_size);

    if (!sc->spherical)

        return AVERROR(ENOMEM);



    sc->spherical->projection = projection;



    sc->spherical->yaw   = yaw;

    sc->spherical->pitch = pitch;

    sc->spherical->roll  = roll;



    sc->spherical->padding = padding;



    sc->spherical->bound_left   = l;

    sc->spherical->bound_top    = t;

    sc->spherical->bound_right  = r;

    sc->spherical->bound_bottom = b;



    return 0;

}

static int mov_read_sv3d(MOVContext *c, AVIOContext *pb, MOVAtom atom)

{

    AVStream *st;

    MOVStreamContext *sc;

    int size;

    int32_t yaw, pitch, roll;

    size_t l = 0, t = 0, r = 0, b = 0;

    size_t padding = 0;

    uint32_t tag;

    enum AVSphericalProjection projection;



    if (c->fc->nb_streams < 1)

        return 0;



    st = c->fc->streams[c->fc->nb_streams - 1];

    sc = st->priv_data;



    if (atom.size < 8) {

        av_log(c->fc, AV_LOG_ERROR, "Empty spherical video box\n");

        return AVERROR_INVALIDDATA;

    }



    size = avio_rb32(pb);

    if (size <= 12 || size > atom.size)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(pb);

    if (tag != MKTAG('s','v','h','d')) {

        av_log(c->fc, AV_LOG_ERROR, "Missing spherical video header\n");

        return 0;

    }

    avio_skip(pb, 4); 

    avio_skip(pb, size - 12); 



    size = avio_rb32(pb);

    if (size > atom.size)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(pb);

    if (tag != MKTAG('p','r','o','j')) {

        av_log(c->fc, AV_LOG_ERROR, "Missing projection box\n");

        return 0;

    }



    size = avio_rb32(pb);

    if (size > atom.size)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(pb);

    if (tag != MKTAG('p','r','h','d')) {

        av_log(c->fc, AV_LOG_ERROR, "Missing projection header box\n");

        return 0;

    }

    avio_skip(pb, 4); 



    

    yaw   = avio_rb32(pb);

    pitch = avio_rb32(pb);

    roll  = avio_rb32(pb);



    size = avio_rb32(pb);

    if (size > atom.size)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(pb);

    avio_skip(pb, 4); 

    switch (tag) {

    case MKTAG('c','b','m','p'):

        projection = AV_SPHERICAL_CUBEMAP;

        padding = avio_rb32(pb);

        break;

    case MKTAG('e','q','u','i'):

        t = avio_rb32(pb);

        b = avio_rb32(pb);

        l = avio_rb32(pb);

        r = avio_rb32(pb);



        if (b >= UINT_MAX - t || r >= UINT_MAX - l) {

            av_log(c->fc, AV_LOG_ERROR,

                   "Invalid bounding rectangle coordinates %"SIZE_SPECIFIER","

                   "%"SIZE_SPECIFIER",%"SIZE_SPECIFIER",%"SIZE_SPECIFIER"\n",

                   l, t, r, b);

            return AVERROR_INVALIDDATA;

        }



        if (l || t || r || b)

            projection = AV_SPHERICAL_EQUIRECTANGULAR_TILE;

        else

            projection = AV_SPHERICAL_EQUIRECTANGULAR;

        break;

    default:

        av_log(c->fc, AV_LOG_ERROR, "Unknown projection type\n");

        return 0;

    }



    sc->spherical = av_spherical_alloc(&sc->spherical_size);

    if (!sc->spherical)

        return AVERROR(ENOMEM);



    sc->spherical->projection = projection;



    sc->spherical->yaw   = yaw;

    sc->spherical->pitch = pitch;

    sc->spherical->roll  = roll;



    sc->spherical->padding = padding;



    sc->spherical->bound_left   = l;

    sc->spherical->bound_top    = t;

    sc->spherical->bound_right  = r;

    sc->spherical->bound_bottom = b;



    return 0;

}

static int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, MOVAtom VAR_2)

{

    AVStream *st;

    MOVStreamContext *sc;

    int VAR_3;

    int32_t yaw, pitch, roll;

    size_t l = 0, t = 0, r = 0, b = 0;

    size_t padding = 0;

    uint32_t tag;

    enum AVSphericalProjection VAR_4;



    if (VAR_0->fc->nb_streams < 1)

        return 0;



    st = VAR_0->fc->streams[VAR_0->fc->nb_streams - 1];

    sc = st->priv_data;



    if (VAR_2.VAR_3 < 8) {

        av_log(VAR_0->fc, AV_LOG_ERROR, "Empty spherical video box\n");

        return AVERROR_INVALIDDATA;

    }



    VAR_3 = avio_rb32(VAR_1);

    if (VAR_3 <= 12 || VAR_3 > VAR_2.VAR_3)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(VAR_1);

    if (tag != MKTAG('s','v','h','d')) {

        av_log(VAR_0->fc, AV_LOG_ERROR, "Missing spherical video header\n");

        return 0;

    }

    avio_skip(VAR_1, 4); 

    avio_skip(VAR_1, VAR_3 - 12); 



    VAR_3 = avio_rb32(VAR_1);

    if (VAR_3 > VAR_2.VAR_3)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(VAR_1);

    if (tag != MKTAG('p','r','o','j')) {

        av_log(VAR_0->fc, AV_LOG_ERROR, "Missing VAR_4 box\n");

        return 0;

    }



    VAR_3 = avio_rb32(VAR_1);

    if (VAR_3 > VAR_2.VAR_3)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(VAR_1);

    if (tag != MKTAG('p','r','h','d')) {

        av_log(VAR_0->fc, AV_LOG_ERROR, "Missing VAR_4 header box\n");

        return 0;

    }

    avio_skip(VAR_1, 4); 



    

    yaw   = avio_rb32(VAR_1);

    pitch = avio_rb32(VAR_1);

    roll  = avio_rb32(VAR_1);



    VAR_3 = avio_rb32(VAR_1);

    if (VAR_3 > VAR_2.VAR_3)

        return AVERROR_INVALIDDATA;



    tag = avio_rl32(VAR_1);

    avio_skip(VAR_1, 4); 

    switch (tag) {

    case MKTAG('VAR_0','b','m','p'):

        VAR_4 = AV_SPHERICAL_CUBEMAP;

        padding = avio_rb32(VAR_1);

        break;

    case MKTAG('e','q','u','i'):

        t = avio_rb32(VAR_1);

        b = avio_rb32(VAR_1);

        l = avio_rb32(VAR_1);

        r = avio_rb32(VAR_1);



        if (b >= UINT_MAX - t || r >= UINT_MAX - l) {

            av_log(VAR_0->fc, AV_LOG_ERROR,

                   "Invalid bounding rectangle coordinates %"SIZE_SPECIFIER","

                   "%"SIZE_SPECIFIER",%"SIZE_SPECIFIER",%"SIZE_SPECIFIER"\n",

                   l, t, r, b);

            return AVERROR_INVALIDDATA;

        }



        if (l || t || r || b)

            VAR_4 = AV_SPHERICAL_EQUIRECTANGULAR_TILE;

        else

            VAR_4 = AV_SPHERICAL_EQUIRECTANGULAR;

        break;

    default:

        av_log(VAR_0->fc, AV_LOG_ERROR, "Unknown VAR_4 type\n");

        return 0;

    }



    sc->spherical = av_spherical_alloc(&sc->spherical_size);

    if (!sc->spherical)

        return AVERROR(ENOMEM);



    sc->spherical->VAR_4 = VAR_4;



    sc->spherical->yaw   = yaw;

    sc->spherical->pitch = pitch;

    sc->spherical->roll  = roll;



    sc->spherical->padding = padding;



    sc->spherical->bound_left   = l;

    sc->spherical->bound_top    = t;

    sc->spherical->bound_right  = r;

    sc->spherical->bound_bottom = b;



    return 0;

}

static int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, MOVAtom VAR_2)
{ AVStream *st; MOVStreamContext *sc; int VAR_3; int32_t yaw, pitch, roll; size_t l = 0, t = 0, r = 0, b = 0; size_t padding = 0; uint32_t tag; enum AVSphericalProjection VAR_4; if (VAR_0->fc->nb_streams < 1)
return 0; st = VAR_0->fc->streams[VAR_0->fc->nb_streams - 1]; sc = st->priv_data; if (VAR_2.VAR_3 < 8) { av_log(VAR_0->fc, AV_LOG_ERROR, "Empty spherical video box\n"); return AVERROR_INVALIDDATA; } VAR_3 = avio_rb32(VAR_1); if (VAR_3 <= 12 || VAR_3 > VAR_2.VAR_3)
return AVERROR_INVALIDDATA; tag = avio_rl32(VAR_1); if (tag != MKTAG('s','v','h','d')) { av_log(VAR_0->fc, AV_LOG_ERROR, "Missing spherical video header\n"); return 0; } avio_skip(VAR_1, 4); avio_skip(VAR_1, VAR_3 - 12); VAR_3 = avio_rb32(VAR_1); if (VAR_3 > VAR_2.VAR_3)
return AVERROR_INVALIDDATA; tag = avio_rl32(VAR_1); if (tag != MKTAG('p','r','o','j')) { av_log(VAR_0->fc, AV_LOG_ERROR, "Missing VAR_4 box\n"); return 0; } VAR_3 = avio_rb32(VAR_1); if (VAR_3 > VAR_2.VAR_3)
return AVERROR_INVALIDDATA; tag = avio_rl32(VAR_1); if (tag != MKTAG('p','r','h','d')) { av_log(VAR_0->fc, AV_LOG_ERROR, "Missing VAR_4 header box\n"); return 0; } avio_skip(VAR_1, 4); yaw   = avio_rb32(VAR_1); pitch = avio_rb32(VAR_1); roll  = avio_rb32(VAR_1); VAR_3 = avio_rb32(VAR_1); if (VAR_3 > VAR_2.VAR_3)
return AVERROR_INVALIDDATA; tag = avio_rl32(VAR_1); avio_skip(VAR_1, 4); switch (tag) { case MKTAG('VAR_0','b','m','p'):
VAR_4 = AV_SPHERICAL_CUBEMAP; padding = avio_rb32(VAR_1); break; case MKTAG('e','q','u','i'):
t = avio_rb32(VAR_1); b = avio_rb32(VAR_1); l = avio_rb32(VAR_1); r = avio_rb32(VAR_1); if (b >= UINT_MAX - t || r >= UINT_MAX - l) { av_log(VAR_0->fc, AV_LOG_ERROR,
"Invalid bounding rectangle coordinates %"SIZE_SPECIFIER","
"%"SIZE_SPECIFIER",%"SIZE_SPECIFIER",%"SIZE_SPECIFIER"\n",
l, t, r, b); return AVERROR_INVALIDDATA; } if (l || t || r || b)
VAR_4 = AV_SPHERICAL_EQUIRECTANGULAR_TILE; else
VAR_4 = AV_SPHERICAL_EQUIRECTANGULAR; break; default:
av_log(VAR_0->fc, AV_LOG_ERROR, "Unknown VAR_4 type\n"); return 0; } sc->spherical = av_spherical_alloc(&sc->spherical_size); if (!sc->spherical)
return AVERROR(ENOMEM); sc->spherical->VAR_4 = VAR_4; sc->spherical->yaw   = yaw; sc->spherical->pitch = pitch; sc->spherical->roll  = roll; sc->spherical->padding = padding; sc->spherical->bound_left   = l; sc->spherical->bound_top    = t; sc->spherical->bound_right  = r; sc->spherical->bound_bottom = b; return 0; }