libvlc: media: add projection in libvlc_video_track_t
[vlc.git] / lib / media.c
index 991a306..fdd2445 100644 (file)
@@ -106,6 +106,23 @@ static const libvlc_meta_t vlc_to_libvlc_meta[] =
     [vlc_meta_DiscTotal]    = libvlc_meta_DiscTotal
 };
 
+static_assert(
+    ORIENT_TOP_LEFT     == (int) libvlc_video_orient_top_left &&
+    ORIENT_TOP_RIGHT    == (int) libvlc_video_orient_top_right &&
+    ORIENT_BOTTOM_LEFT  == (int) libvlc_video_orient_bottom_left &&
+    ORIENT_BOTTOM_RIGHT == (int) libvlc_video_orient_bottom_right &&
+    ORIENT_LEFT_TOP     == (int) libvlc_video_orient_left_top &&
+    ORIENT_LEFT_BOTTOM  == (int) libvlc_video_orient_left_bottom &&
+    ORIENT_RIGHT_TOP    == (int) libvlc_video_orient_right_top &&
+    ORIENT_RIGHT_BOTTOM == (int) libvlc_video_orient_right_bottom,
+    "Mismatch between libvlc_video_orient_t and video_orientation_t" );
+
+static_assert(
+    PROJECTION_MODE_RECTANGULAR             == (int) libvlc_video_projection_rectangular &&
+    PROJECTION_MODE_EQUIRECTANGULAR         == (int) libvlc_video_projection_equirectangular &&
+    PROJECTION_MODE_CUBEMAP_LAYOUT_STANDARD == (int) libvlc_video_projection_cubemap_layout_standard,
+    "Mismatch between libvlc_video_projection_t and video_projection_mode_t" );
+
 static libvlc_media_list_t *media_get_subitems( libvlc_media_t * p_md,
                                                 bool b_create )
 {
@@ -275,6 +292,9 @@ static void input_item_preparse_ended( const vlc_event_t * p_event,
         case ITEM_PREPARSE_FAILED:
             new_status = libvlc_media_parsed_status_failed;
             break;
+        case ITEM_PREPARSE_TIMEOUT:
+            new_status = libvlc_media_parsed_status_timeout;
+            break;
         case ITEM_PREPARSE_DONE:
             new_status = libvlc_media_parsed_status_done;
             break;
@@ -478,6 +498,7 @@ libvlc_media_t * libvlc_media_new_as_node( libvlc_instance_t *p_instance,
     }
 
     p_md = libvlc_media_new_from_input_item( p_instance, p_input_item );
+    input_item_Release( p_input_item );
 
     p_subitems = media_get_subitems( p_md, true );
     if( p_subitems == NULL) {
@@ -528,6 +549,9 @@ void libvlc_media_release( libvlc_media_t *p_md )
 
     uninstall_input_item_observer( p_md );
 
+    /* Cancel asynchronous parsing (if any) */
+    libvlc_MetadataCancel( p_md->p_libvlc_instance->p_libvlc_int, p_md );
+
     if( p_md->p_subitems )
         libvlc_media_list_release( p_md->p_subitems );
 
@@ -731,7 +755,7 @@ libvlc_media_get_duration( libvlc_media_t * p_md )
 }
 
 static int media_parse(libvlc_media_t *media, bool b_async,
-                       libvlc_media_parse_flag_t parse_flag)
+                       libvlc_media_parse_flag_t parse_flag, int timeout)
 {
     bool needed;
 
@@ -764,7 +788,7 @@ static int media_parse(libvlc_media_t *media, bool b_async,
             parse_scope |= META_REQUEST_OPTION_SCOPE_NETWORK;
         if (parse_flag & libvlc_media_do_interact)
             parse_scope |= META_REQUEST_OPTION_DO_INTERACT;
-        ret = libvlc_MetadataRequest(libvlc, item, parse_scope, 0, NULL);
+        ret = libvlc_MetadataRequest(libvlc, item, parse_scope, timeout, media);
         if (ret != VLC_SUCCESS)
             return ret;
     }
@@ -787,7 +811,7 @@ static int media_parse(libvlc_media_t *media, bool b_async,
 void
 libvlc_media_parse(libvlc_media_t *media)
 {
-    media_parse( media, false, libvlc_media_fetch_local );
+    media_parse( media, false, libvlc_media_fetch_local, -1 );
 }
 
 /**************************************************************************
@@ -796,7 +820,7 @@ libvlc_media_parse(libvlc_media_t *media)
 void
 libvlc_media_parse_async(libvlc_media_t *media)
 {
-    media_parse( media, true, libvlc_media_fetch_local );
+    media_parse( media, true, libvlc_media_fetch_local, -1 );
 }
 
 /**************************************************************************
@@ -804,9 +828,16 @@ libvlc_media_parse_async(libvlc_media_t *media)
  **************************************************************************/
 int
 libvlc_media_parse_with_options( libvlc_media_t *media,
-                                 libvlc_media_parse_flag_t parse_flag )
+                                 libvlc_media_parse_flag_t parse_flag,
+                                 int timeout )
+{
+    return media_parse( media, true, parse_flag, timeout ) == VLC_SUCCESS ? 0 : -1;
+}
+
+void
+libvlc_media_parse_stop( libvlc_media_t *media )
 {
-    return media_parse( media, true, parse_flag ) == VLC_SUCCESS ? 0 : -1;
+    libvlc_MetadataCancel( media->p_libvlc_instance->p_libvlc_int, media );
 }
 
 /**************************************************************************
@@ -980,6 +1011,20 @@ libvlc_media_tracks_get( libvlc_media_t *p_md, libvlc_media_track_t *** pp_es )
             p_mes->video->i_sar_den = p_es->video.i_sar_den;
             p_mes->video->i_frame_rate_num = p_es->video.i_frame_rate;
             p_mes->video->i_frame_rate_den = p_es->video.i_frame_rate_base;
+
+            assert( p_es->video.orientation >= ORIENT_TOP_LEFT &&
+                    p_es->video.orientation <= ORIENT_RIGHT_BOTTOM );
+            p_mes->video->i_orientation = (int) p_es->video.orientation;
+
+            assert( ( p_es->video.projection_mode >= PROJECTION_MODE_RECTANGULAR &&
+                    p_es->video.projection_mode <= PROJECTION_MODE_EQUIRECTANGULAR ) ||
+                    ( p_es->video.projection_mode == PROJECTION_MODE_CUBEMAP_LAYOUT_STANDARD ) );
+            p_mes->video->i_projection = (int) p_es->video.projection_mode;
+
+            p_mes->video->pose.f_yaw_degrees = p_es->video.pose.f_yaw_degrees;
+            p_mes->video->pose.f_pitch_degrees = p_es->video.pose.f_pitch_degrees;
+            p_mes->video->pose.f_roll_degrees = p_es->video.pose.f_roll_degrees;
+            p_mes->video->pose.f_fov_degrees = p_es->video.pose.f_fov_degrees;
             break;
         case AUDIO_ES:
             p_mes->i_type = libvlc_track_audio;