diff mbox

[FFmpeg-devel,2/3,v2] lavc: Add spherical packet side data API

Message ID 20161115165650.5720-2-vittorio.giovara@gmail.com
State Superseded
Headers show

Commit Message

Vittorio Giovara Nov. 15, 2016, 4:56 p.m. UTC
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
---
Updated to use int32 for rotation.
Please CC.
Vittorio

 ffprobe.c             | 18 ++++++++++++++++++
 libavcodec/avcodec.h  |  8 +++++++-
 libavcodec/avpacket.c |  1 +
 libavcodec/utils.c    |  1 +
 libavformat/dump.c    | 36 ++++++++++++++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 1 deletion(-)

Comments

James Almer Nov. 17, 2016, 2:26 a.m. UTC | #1
On 11/15/2016 1:56 PM, Vittorio Giovara wrote:
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> ---
> Updated to use int32 for rotation.
> Please CC.
> Vittorio
[...]

> diff --git a/libavformat/dump.c b/libavformat/dump.c
> index cd14625..2dd7a0a 100644
> --- a/libavformat/dump.c
> +++ b/libavformat/dump.c
> @@ -31,6 +31,7 @@
>  #include "libavutil/opt.h"
>  #include "libavutil/avstring.h"
>  #include "libavutil/replaygain.h"
> +#include "libavutil/spherical.h"
>  #include "libavutil/stereo3d.h"
>  
>  #include "avformat.h"
> @@ -342,6 +343,37 @@ static void dump_mastering_display_metadata(void *ctx, AVPacketSideData* sd) {
>             av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
>  }
>  
> +static void dump_spherical(void *ctx, AVPacketSideData *sd)
> +{
> +    AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
> +    double yaw, pitch, roll;
> +
> +    if (sd->size < sizeof(*spherical)) {

sizeof(AVSphericalMapping) is explicitly not part of the ABI, and this file is
in libavformat.

i know Stereo3D, Mastering Display, and probably other side data types are
doing the same, so maybe something like av_{stereo3d,spherical}_size() should
be added to all of them in order to solve this.

> +        av_log(ctx, AV_LOG_INFO, "invalid data");
> +        return;
> +    }
> +
> +    if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR)
> +        av_log(ctx, AV_LOG_INFO, "equirectangular ");
> +    else if (spherical->projection == AV_SPHERICAL_CUBEMAP)
> +        av_log(ctx, AV_LOG_INFO, "cubemap ");
> +    else {
> +        av_log(ctx, AV_LOG_WARNING, "unknown");
> +        return;
> +    }
> +
> +    yaw = ((double)spherical->yaw) / (1 << 16);
> +    pitch = ((double)spherical->pitch) / (1 << 16);
> +    roll = ((double)spherical->roll) / (1 << 16);
> +    av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
> +
> +    if (spherical->left_offset || spherical->top_offset ||
> +        spherical->right_offset || spherical->bottom_offset)
> +        av_log(ctx, AV_LOG_INFO, "[%d-%d-%d-%d] ",
> +               spherical->left_offset, spherical->top_offset,
> +               spherical->right_offset, spherical->bottom_offset);
> +}
> +
>  static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
>  {
>      int i;
> @@ -393,6 +425,10 @@ static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
>          case AV_PKT_DATA_MASTERING_DISPLAY_METADATA:
>              dump_mastering_display_metadata(ctx, &sd);
>              break;
> +        case AV_PKT_DATA_SPHERICAL:
> +            av_log(ctx, AV_LOG_INFO, "spherical: ");
> +            dump_spherical(ctx, &sd);
> +            break;
>          default:
>              av_log(ctx, AV_LOG_INFO,
>                     "unknown side data type %d (%d bytes)", sd.type, sd.size);
>
diff mbox

Patch

diff --git a/ffprobe.c b/ffprobe.c
index a2980b3..839963a 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -37,6 +37,7 @@ 
 #include "libavutil/hash.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/spherical.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/dict.h"
 #include "libavutil/intreadwrite.h"
@@ -1783,6 +1784,23 @@  static void print_pkt_side_data(WriterContext *w,
             const AVStereo3D *stereo = (AVStereo3D *)sd->data;
             print_str("type", av_stereo3d_type_name(stereo->type));
             print_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
+        } else if (sd->type == AV_PKT_DATA_SPHERICAL) {
+            const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
+            if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR)
+                print_str("projection", "equirectangular");
+            else if (spherical->projection == AV_SPHERICAL_CUBEMAP)
+                print_str("projection", "cubemap");
+            else
+                print_str("projection", "unknown");
+
+            print_int("yaw", ((double)spherical->yaw) / (1 << 16));
+            print_int("pitch", ((double)spherical->pitch) / (1 << 16));
+            print_int("roll", ((double)spherical->roll) / (1 << 16));
+
+            print_int("left", spherical->left_offset);
+            print_int("top", spherical->top_offset);
+            print_int("right", spherical->right_offset);
+            print_int("bottom", spherical->bottom_offset);
         }
         writer_print_section_footer(w);
     }
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 211112f..9497cc3 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1536,7 +1536,13 @@  enum AVPacketSideDataType {
      * should be associated with a video stream and containts data in the form
      * of the AVMasteringDisplayMetadata struct.
      */
-    AV_PKT_DATA_MASTERING_DISPLAY_METADATA
+    AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
+
+    /**
+     * This side data should be associated with a video stream and corresponds
+     * to the AVSphericalMapping structure.
+     */
+    AV_PKT_DATA_SPHERICAL,
 };
 
 #define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index c3f871c..a799610 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -371,6 +371,7 @@  const char *av_packet_side_data_name(enum AVPacketSideDataType type)
     case AV_PKT_DATA_METADATA_UPDATE:            return "Metadata Update";
     case AV_PKT_DATA_MPEGTS_STREAM_ID:           return "MPEGTS Stream ID";
     case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: return "Mastering display metadata";
+    case AV_PKT_DATA_SPHERICAL:                  return "Spherical mapping";
     }
     return NULL;
 }
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index d6dca18..89a12c6 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -762,6 +762,7 @@  int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
     } sd[] = {
         { AV_PKT_DATA_REPLAYGAIN ,                AV_FRAME_DATA_REPLAYGAIN },
         { AV_PKT_DATA_DISPLAYMATRIX,              AV_FRAME_DATA_DISPLAYMATRIX },
+        { AV_PKT_DATA_SPHERICAL,                  AV_FRAME_DATA_SPHERICAL },
         { AV_PKT_DATA_STEREO3D,                   AV_FRAME_DATA_STEREO3D },
         { AV_PKT_DATA_AUDIO_SERVICE_TYPE,         AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
         { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
diff --git a/libavformat/dump.c b/libavformat/dump.c
index cd14625..2dd7a0a 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -31,6 +31,7 @@ 
 #include "libavutil/opt.h"
 #include "libavutil/avstring.h"
 #include "libavutil/replaygain.h"
+#include "libavutil/spherical.h"
 #include "libavutil/stereo3d.h"
 
 #include "avformat.h"
@@ -342,6 +343,37 @@  static void dump_mastering_display_metadata(void *ctx, AVPacketSideData* sd) {
            av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
 }
 
+static void dump_spherical(void *ctx, AVPacketSideData *sd)
+{
+    AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
+    double yaw, pitch, roll;
+
+    if (sd->size < sizeof(*spherical)) {
+        av_log(ctx, AV_LOG_INFO, "invalid data");
+        return;
+    }
+
+    if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR)
+        av_log(ctx, AV_LOG_INFO, "equirectangular ");
+    else if (spherical->projection == AV_SPHERICAL_CUBEMAP)
+        av_log(ctx, AV_LOG_INFO, "cubemap ");
+    else {
+        av_log(ctx, AV_LOG_WARNING, "unknown");
+        return;
+    }
+
+    yaw = ((double)spherical->yaw) / (1 << 16);
+    pitch = ((double)spherical->pitch) / (1 << 16);
+    roll = ((double)spherical->roll) / (1 << 16);
+    av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
+
+    if (spherical->left_offset || spherical->top_offset ||
+        spherical->right_offset || spherical->bottom_offset)
+        av_log(ctx, AV_LOG_INFO, "[%d-%d-%d-%d] ",
+               spherical->left_offset, spherical->top_offset,
+               spherical->right_offset, spherical->bottom_offset);
+}
+
 static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
 {
     int i;
@@ -393,6 +425,10 @@  static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
         case AV_PKT_DATA_MASTERING_DISPLAY_METADATA:
             dump_mastering_display_metadata(ctx, &sd);
             break;
+        case AV_PKT_DATA_SPHERICAL:
+            av_log(ctx, AV_LOG_INFO, "spherical: ");
+            dump_spherical(ctx, &sd);
+            break;
         default:
             av_log(ctx, AV_LOG_INFO,
                    "unknown side data type %d (%d bytes)", sd.type, sd.size);