On 2/10/2017 6:37 PM, James Almer wrote:
> On 2/10/2017 6:08 PM, Vittorio Giovara wrote:
>> ---
>>  libavformat/matroskadec.c | 34 +++++++++++++++++++++++++++++++++-
>>  1 file changed, 33 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
>> index a44ceeb..ebfd414 100644
>> --- a/libavformat/matroskadec.c
>> +++ b/libavformat/matroskadec.c
>> @@ -1601,17 +1601,34 @@ static int mkv_parse_video_projection(AVStream *st, 
>> const MatroskaTrack *track)
>>      AVSphericalMapping *spherical;
>>      enum AVSphericalProjection projection;
>>      size_t spherical_size;
>> +    size_t l, t, r, b;
>> +    size_t padding = 0;
>>      int ret;
>> +    GetByteContext gb;
>> +
>> +    bytestream2_init(&gb, track->video.projection.private.data,
>> +                     track->video.projection.private.size);
>>  
>>      switch (track->video.projection.type) {
>>      case MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR:
>> -        projection = AV_SPHERICAL_EQUIRECTANGULAR;
>> +        if (track->video.projection.private.size == 0)
>> +            projection = AV_SPHERICAL_EQUIRECTANGULAR;
>> +        else {
>> +            projection = AV_SPHERICAL_EQUIRECTANGULAR_TILE;
>> +            bytestream2_skip(&gb, 4); // version + flags
> 
> Since now we care about the contents of ProjectPrivate, better check
> that version == 0 and track->video.projection.private.size == 20, and
> abort warning about unsupported version or invalid data otherwise.
> 
>> +            t = bytestream2_get_be32(&gb);
>> +            b = bytestream2_get_be32(&gb);
>> +            l = bytestream2_get_be32(&gb);
>> +            r = bytestream2_get_be32(&gb);

I forgot. t, b, l and r may be zero, so you must check for that like
you did with the mov demuxer. If they are, then this is a non tiled
equi projection created by a muxer that didn't know/care it could skip
this element for such projection.

>> +        }
>>          break;
>>      case MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP:
>>          if (track->video.projection.private.size < 4) {
>>              av_log(NULL, AV_LOG_ERROR, "Missing projection private 
>> properties\n");
>>              return AVERROR_INVALIDDATA;
>>          }
>> +        bytestream2_skip(&gb, 4); // layout
> 
> First 4 bytes are version + flags. And like with equi, make sure
> version == 0 and size == 12, and abort otherwise.
> 
>> +        padding = bytestream2_get_be32(&gb);
>>          projection = AV_SPHERICAL_CUBEMAP;
>>          break;
>>      default:
>> @@ -1627,6 +1644,21 @@ static int mkv_parse_video_projection(AVStream *st, 
>> const MatroskaTrack *track)
>>      spherical->pitch = (int32_t)(track->video.projection.pitch * (1 << 16));
>>      spherical->roll  = (int32_t)(track->video.projection.roll  * (1 << 16));
>>  
>> +    spherical->padding = padding;
>> +
>> +    if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
>> +        /* conversion from 0.32 coordinates to pixels */
>> +        uint32_t max_coord = (uint32_t) -1;
> 
> UINT32_MAX?
> 
>> +        size_t orig_width  = (size_t) track->video.pixel_width  * max_coord 
>> / (max_coord - r - l);
>> +        size_t orig_height = (size_t) track->video.pixel_height * max_coord 
>> / (max_coord - b - t);
>> +
>> +        /* add a (max_coord - 1) to round up integer division */
>> +        spherical->left_bound   = (orig_width  * l + max_coord - 1) / 
>> max_coord;
>> +        spherical->top_bound    = (orig_height * t + max_coord - 1) / 
>> max_coord;
>> +        spherical->right_bound  = orig_width  - track->video.pixel_width  - 
>> spherical->left_bound;
>> +        spherical->bottom_bound = orig_height - track->video.pixel_height - 
>> spherical->top_bound;
>> +    }
>> +
>>      ret = av_stream_add_side_data(st, AV_PKT_DATA_SPHERICAL, (uint8_t 
>> *)spherical,
>>                                    spherical_size);
>>      if (ret < 0)
>>
> 

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to