diff mbox

[FFmpeg-devel,1/3] avutil/spherical: add av_spherical_projection_name()

Message ID 20170329025557.952-1-jamrial@gmail.com
State Accepted
Headers show

Commit Message

James Almer March 29, 2017, 2:55 a.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 doc/APIchanges        |  3 +++
 libavutil/spherical.c | 15 +++++++++++++++
 libavutil/spherical.h |  9 +++++++++
 3 files changed, 27 insertions(+)

Comments

Benoit Fouet March 30, 2017, 7:14 a.m. UTC | #1
Hi,


On 29/03/2017 04:55, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  doc/APIchanges        |  3 +++
>  libavutil/spherical.c | 15 +++++++++++++++
>  libavutil/spherical.h |  9 +++++++++
>  3 files changed, 27 insertions(+)
>

[...]

> diff --git a/libavutil/spherical.c b/libavutil/spherical.c
> index f0b622128a..1d06e7c552 100644
> --- a/libavutil/spherical.c
> +++ b/libavutil/spherical.c
> @@ -50,3 +50,18 @@ void av_spherical_tile_bounds(const AVSphericalMapping *map,
>      *right  = orig_width  - width  - *left;
>      *bottom = orig_height - height - *top;
>  }
> +
> +static const char *spherical_projection_names[] = {
> +    [AV_SPHERICAL_EQUIRECTANGULAR]      = "equirectangular",
> +    [AV_SPHERICAL_CUBEMAP]              = "cubemap",
> +    [AV_SPHERICAL_EQUIRECTANGULAR_TILE] = "tiled equirectangular",
> +
> +};
> +
> +const char *av_spherical_projection_name(enum AVSphericalProjection projection)
> +{
> +    if (projection >= FF_ARRAY_ELEMS(spherical_projection_names))
> +        return "unknown";
> +

You should also check for projection to be negative, or cast it to
unsigned when checking.
James Almer March 30, 2017, 2:12 p.m. UTC | #2
On 3/30/2017 4:14 AM, Benoit Fouet wrote:
> Hi,
> 
> 
> On 29/03/2017 04:55, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  doc/APIchanges        |  3 +++
>>  libavutil/spherical.c | 15 +++++++++++++++
>>  libavutil/spherical.h |  9 +++++++++
>>  3 files changed, 27 insertions(+)
>>
> 
> [...]
> 
>> diff --git a/libavutil/spherical.c b/libavutil/spherical.c
>> index f0b622128a..1d06e7c552 100644
>> --- a/libavutil/spherical.c
>> +++ b/libavutil/spherical.c
>> @@ -50,3 +50,18 @@ void av_spherical_tile_bounds(const AVSphericalMapping *map,
>>      *right  = orig_width  - width  - *left;
>>      *bottom = orig_height - height - *top;
>>  }
>> +
>> +static const char *spherical_projection_names[] = {
>> +    [AV_SPHERICAL_EQUIRECTANGULAR]      = "equirectangular",
>> +    [AV_SPHERICAL_CUBEMAP]              = "cubemap",
>> +    [AV_SPHERICAL_EQUIRECTANGULAR_TILE] = "tiled equirectangular",
>> +
>> +};
>> +
>> +const char *av_spherical_projection_name(enum AVSphericalProjection projection)
>> +{
>> +    if (projection >= FF_ARRAY_ELEMS(spherical_projection_names))
>> +        return "unknown";
>> +
> 
> You should also check for projection to be negative, or cast it to
> unsigned when checking.

Changed locally, thanks.
Vittorio Giovara March 31, 2017, 8:42 a.m. UTC | #3
On Wed, Mar 29, 2017 at 4:55 AM, James Almer <jamrial@gmail.com> wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  doc/APIchanges        |  3 +++
>  libavutil/spherical.c | 15 +++++++++++++++
>  libavutil/spherical.h |  9 +++++++++
>  3 files changed, 27 insertions(+)

version bump

> diff --git a/doc/APIchanges b/doc/APIchanges
> index 2274543024..5f3c268d05 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil:     2015-08-28
>
>  API changes, most recent first:
>
> +2017-xx-xx - xxxxxxx - lavu 55.xx.xxx - spherical.h
> +  Add av_spherical_projection_name()

nit: full stop

> +
>  2017-03-xx - xxxxxxx - lavf 57.68.100 - avformat.h
>    Deprecate that demuxers export the stream rotation angle in AVStream.metadata
>    (via an entry named "rotate"). Use av_stream_get_side_data() with
> diff --git a/libavutil/spherical.h b/libavutil/spherical.h
> index a7952875af..2c8dd3cd97 100644
> --- a/libavutil/spherical.h
> +++ b/libavutil/spherical.h
> @@ -206,6 +206,15 @@ void av_spherical_tile_bounds(const AVSphericalMapping *map,
>                                size_t width, size_t height,
>                                size_t *left, size_t *top,
>                                size_t *right, size_t *bottom);
> +
> +/**
> + * Provide a human-readable name of a given AVSphericalProjection.
> + *
> + * @param projection The input AVSphericalProjection.
> + *
> + * @return The name of the AVSphericalProjection, or "unknown".
> + */
> +const char *av_spherical_projection_name(enum AVSphericalProjection projection);

./ffmpeg/libavutil/spherical.c:59:14: warning: comparison of
      constant 8 with expression of type 'enum AVSphericalProjection'
is always false
      [-Wtautological-constant-out-of-range-compare]
    if (type >= FF_ARRAY_ELEMS(spherical_projection_names))

you gotta use unsigned int as the first argument

not required but nice to have would be the opposite function so that
you can get the projection type from a string.
James Almer March 31, 2017, 5:15 p.m. UTC | #4
On 3/31/2017 5:42 AM, Vittorio Giovara wrote:
> On Wed, Mar 29, 2017 at 4:55 AM, James Almer <jamrial@gmail.com> wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  doc/APIchanges        |  3 +++
>>  libavutil/spherical.c | 15 +++++++++++++++
>>  libavutil/spherical.h |  9 +++++++++
>>  3 files changed, 27 insertions(+)
> 
> version bump
> 
>> diff --git a/doc/APIchanges b/doc/APIchanges
>> index 2274543024..5f3c268d05 100644
>> --- a/doc/APIchanges
>> +++ b/doc/APIchanges
>> @@ -15,6 +15,9 @@ libavutil:     2015-08-28
>>
>>  API changes, most recent first:
>>
>> +2017-xx-xx - xxxxxxx - lavu 55.xx.xxx - spherical.h
>> +  Add av_spherical_projection_name()
> 
> nit: full stop
> 
>> +
>>  2017-03-xx - xxxxxxx - lavf 57.68.100 - avformat.h
>>    Deprecate that demuxers export the stream rotation angle in AVStream.metadata
>>    (via an entry named "rotate"). Use av_stream_get_side_data() with
>> diff --git a/libavutil/spherical.h b/libavutil/spherical.h
>> index a7952875af..2c8dd3cd97 100644
>> --- a/libavutil/spherical.h
>> +++ b/libavutil/spherical.h
>> @@ -206,6 +206,15 @@ void av_spherical_tile_bounds(const AVSphericalMapping *map,
>>                                size_t width, size_t height,
>>                                size_t *left, size_t *top,
>>                                size_t *right, size_t *bottom);
>> +
>> +/**
>> + * Provide a human-readable name of a given AVSphericalProjection.
>> + *
>> + * @param projection The input AVSphericalProjection.
>> + *
>> + * @return The name of the AVSphericalProjection, or "unknown".
>> + */
>> +const char *av_spherical_projection_name(enum AVSphericalProjection projection);
> 
> ./ffmpeg/libavutil/spherical.c:59:14: warning: comparison of
>       constant 8 with expression of type 'enum AVSphericalProjection'
> is always false
>       [-Wtautological-constant-out-of-range-compare]
>     if (type >= FF_ARRAY_ELEMS(spherical_projection_names))
> 
> you gotta use unsigned int as the first argument

I went with Benoit's suggestion to cast projection to unsigned instead.
https://ffmpeg.org/pipermail/ffmpeg-devel/2017-March/209394.html

> 
> not required but nice to have would be the opposite function so that
> you can get the projection type from a string.

Sure, done and pushed. Thanks.
Vittorio Giovara April 3, 2017, 9:18 a.m. UTC | #5
On Fri, Mar 31, 2017 at 7:15 PM, James Almer <jamrial@gmail.com> wrote:
> On 3/31/2017 5:42 AM, Vittorio Giovara wrote:
>> On Wed, Mar 29, 2017 at 4:55 AM, James Almer <jamrial@gmail.com> wrote:
>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>> ---
>>>  doc/APIchanges        |  3 +++
>>>  libavutil/spherical.c | 15 +++++++++++++++
>>>  libavutil/spherical.h |  9 +++++++++
>>>  3 files changed, 27 insertions(+)
>>
>> version bump
>>
>>> diff --git a/doc/APIchanges b/doc/APIchanges
>>> index 2274543024..5f3c268d05 100644
>>> --- a/doc/APIchanges
>>> +++ b/doc/APIchanges
>>> @@ -15,6 +15,9 @@ libavutil:     2015-08-28
>>>
>>>  API changes, most recent first:
>>>
>>> +2017-xx-xx - xxxxxxx - lavu 55.xx.xxx - spherical.h
>>> +  Add av_spherical_projection_name()
>>
>> nit: full stop
>>
>>> +
>>>  2017-03-xx - xxxxxxx - lavf 57.68.100 - avformat.h
>>>    Deprecate that demuxers export the stream rotation angle in AVStream.metadata
>>>    (via an entry named "rotate"). Use av_stream_get_side_data() with
>>> diff --git a/libavutil/spherical.h b/libavutil/spherical.h
>>> index a7952875af..2c8dd3cd97 100644
>>> --- a/libavutil/spherical.h
>>> +++ b/libavutil/spherical.h
>>> @@ -206,6 +206,15 @@ void av_spherical_tile_bounds(const AVSphericalMapping *map,
>>>                                size_t width, size_t height,
>>>                                size_t *left, size_t *top,
>>>                                size_t *right, size_t *bottom);
>>> +
>>> +/**
>>> + * Provide a human-readable name of a given AVSphericalProjection.
>>> + *
>>> + * @param projection The input AVSphericalProjection.
>>> + *
>>> + * @return The name of the AVSphericalProjection, or "unknown".
>>> + */
>>> +const char *av_spherical_projection_name(enum AVSphericalProjection projection);
>>
>> ./ffmpeg/libavutil/spherical.c:59:14: warning: comparison of
>>       constant 8 with expression of type 'enum AVSphericalProjection'
>> is always false
>>       [-Wtautological-constant-out-of-range-compare]
>>     if (type >= FF_ARRAY_ELEMS(spherical_projection_names))
>>
>> you gotta use unsigned int as the first argument
>
> I went with Benoit's suggestion to cast projection to unsigned instead.
> https://ffmpeg.org/pipermail/ffmpeg-devel/2017-March/209394.html

That works too, in the code sometimes we use one way sometimes we use the other.

>> not required but nice to have would be the opposite function so that
>> you can get the projection type from a string.
>
> Sure, done and pushed. Thanks.

Looking forward to see the patches that keep API aligned across lavu providers.
diff mbox

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 2274543024..5f3c268d05 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@  libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2017-xx-xx - xxxxxxx - lavu 55.xx.xxx - spherical.h
+  Add av_spherical_projection_name()
+
 2017-03-xx - xxxxxxx - lavf 57.68.100 - avformat.h
   Deprecate that demuxers export the stream rotation angle in AVStream.metadata
   (via an entry named "rotate"). Use av_stream_get_side_data() with
diff --git a/libavutil/spherical.c b/libavutil/spherical.c
index f0b622128a..1d06e7c552 100644
--- a/libavutil/spherical.c
+++ b/libavutil/spherical.c
@@ -50,3 +50,18 @@  void av_spherical_tile_bounds(const AVSphericalMapping *map,
     *right  = orig_width  - width  - *left;
     *bottom = orig_height - height - *top;
 }
+
+static const char *spherical_projection_names[] = {
+    [AV_SPHERICAL_EQUIRECTANGULAR]      = "equirectangular",
+    [AV_SPHERICAL_CUBEMAP]              = "cubemap",
+    [AV_SPHERICAL_EQUIRECTANGULAR_TILE] = "tiled equirectangular",
+
+};
+
+const char *av_spherical_projection_name(enum AVSphericalProjection projection)
+{
+    if (projection >= FF_ARRAY_ELEMS(spherical_projection_names))
+        return "unknown";
+
+    return spherical_projection_names[projection];
+}
diff --git a/libavutil/spherical.h b/libavutil/spherical.h
index a7952875af..2c8dd3cd97 100644
--- a/libavutil/spherical.h
+++ b/libavutil/spherical.h
@@ -206,6 +206,15 @@  void av_spherical_tile_bounds(const AVSphericalMapping *map,
                               size_t width, size_t height,
                               size_t *left, size_t *top,
                               size_t *right, size_t *bottom);
+
+/**
+ * Provide a human-readable name of a given AVSphericalProjection.
+ *
+ * @param projection The input AVSphericalProjection.
+ *
+ * @return The name of the AVSphericalProjection, or "unknown".
+ */
+const char *av_spherical_projection_name(enum AVSphericalProjection projection);
 /**
  * @}
  * @}