]> git.sesse.net Git - vlc/blobdiff - src/misc/es_format.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / misc / es_format.c
index d5eaa471f82ec94aca71863b0c710a8382366185..9864a0fb1a96055f9d855718b9ce886f9bf1354e 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <vlc_common.h>
 #include <vlc_es.h>
+#include <vlc_aout.h>
 
 
 /*****************************************************************************
@@ -128,7 +129,9 @@ void video_format_FixRgb( video_format_t *p_fmt )
                  p_fmt->i_bmask );
 }
 
-void video_format_Setup( video_format_t *p_fmt, vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect )
+void video_format_Setup( video_format_t *p_fmt, vlc_fourcc_t i_chroma,
+                         int i_width, int i_height,
+                         int i_sar_num, int i_sar_den )
 {
     p_fmt->i_chroma         = vlc_fourcc_GetCodec( VIDEO_ES, i_chroma );
     p_fmt->i_width          =
@@ -137,7 +140,8 @@ void video_format_Setup( video_format_t *p_fmt, vlc_fourcc_t i_chroma, int i_wid
     p_fmt->i_visible_height = i_height;
     p_fmt->i_x_offset       =
     p_fmt->i_y_offset       = 0;
-    p_fmt->i_aspect         = i_aspect;
+    vlc_ureduce( &p_fmt->i_sar_num, &p_fmt->i_sar_den,
+                 i_sar_num, i_sar_den, 0 );
 
     switch( p_fmt->i_chroma )
     {
@@ -166,6 +170,7 @@ void video_format_Setup( video_format_t *p_fmt, vlc_fourcc_t i_chroma, int i_wid
     case VLC_CODEC_J420:
         p_fmt->i_bits_per_pixel = 12;
         break;
+    case VLC_CODEC_YV9:
     case VLC_CODEC_I410:
         p_fmt->i_bits_per_pixel = 9;
         break;
@@ -201,6 +206,49 @@ void video_format_Setup( video_format_t *p_fmt, vlc_fourcc_t i_chroma, int i_wid
         break;
     }
 }
+bool video_format_IsSimilar( const video_format_t *p_fmt1, const video_format_t *p_fmt2 )
+{
+    video_format_t v1 = *p_fmt1;
+    video_format_t v2 = *p_fmt2;
+
+    if( v1.i_chroma != v2.i_chroma )
+        return false;
+
+    if( v1.i_width != v2.i_width || v1.i_height != v2.i_height ||
+        v1.i_visible_width != v2.i_visible_width ||
+        v1.i_visible_height != v2.i_visible_height ||
+        v1.i_x_offset != v2.i_x_offset || v1.i_y_offset != v2.i_y_offset )
+        return false;
+    if( v1.i_sar_num * v2.i_sar_den != v2.i_sar_num * v1.i_sar_den )
+        return false;
+
+    if( v1.i_chroma == VLC_CODEC_RGB15 ||
+        v1.i_chroma == VLC_CODEC_RGB16 ||
+        v1.i_chroma == VLC_CODEC_RGB24 ||
+        v1.i_chroma == VLC_CODEC_RGB32 )
+    {
+        video_format_FixRgb( &v1 );
+        video_format_FixRgb( &v2 );
+
+        if( v1.i_rmask != v2.i_rmask ||
+            v1.i_gmask != v2.i_gmask ||
+            v1.i_bmask != v2.i_bmask )
+            return false;
+    }
+    return true;
+}
+void video_format_Print( vlc_object_t *p_this,
+                         const char *psz_text, const video_format_t *fmt )
+{
+    msg_Dbg( p_this,
+             "%s sz %ix%i, of (%i,%i), vsz %ix%i, 4cc %4.4s, sar %i:%i, msk r0x%x g0x%x b0x%x",
+             psz_text,
+             fmt->i_width, fmt->i_height, fmt->i_x_offset, fmt->i_y_offset,
+             fmt->i_visible_width, fmt->i_visible_height,
+             (char*)&fmt->i_chroma,
+             fmt->i_sar_num, fmt->i_sar_den,
+             fmt->i_rmask, fmt->i_gmask, fmt->i_bmask );
+}
 
 void es_format_Init( es_format_t *fmt,
                      int i_cat, vlc_fourcc_t i_codec )
@@ -208,6 +256,8 @@ void es_format_Init( es_format_t *fmt,
     fmt->i_cat                  = i_cat;
     fmt->i_codec                = i_codec;
     fmt->i_original_fourcc      = 0;
+    fmt->i_profile              = -1;
+    fmt->i_level                = -1;
     fmt->i_id                   = -1;
     fmt->i_group                = 0;
     fmt->i_priority             = 0;
@@ -228,6 +278,12 @@ void es_format_Init( es_format_t *fmt,
     fmt->p_extra                = NULL;
 }
 
+void es_format_InitFromVideo( es_format_t *p_es, const video_format_t *p_fmt )
+{
+    es_format_Init( p_es, VIDEO_ES, p_fmt->i_chroma );
+    video_format_Copy( &p_es->video, p_fmt );
+}
+
 int es_format_Copy( es_format_t *dst, const es_format_t *src )
 {
     int i;
@@ -313,3 +369,43 @@ void es_format_Clean( es_format_t *fmt )
     memset( fmt, 0, sizeof(*fmt) );
 }
 
+bool es_format_IsSimilar( const es_format_t *p_fmt1, const es_format_t *p_fmt2 )
+{
+    if( p_fmt1->i_cat != p_fmt2->i_cat ||
+        vlc_fourcc_GetCodec( p_fmt1->i_cat, p_fmt1->i_codec ) !=
+        vlc_fourcc_GetCodec( p_fmt2->i_cat, p_fmt2->i_codec ) )
+        return false;
+
+    switch( p_fmt1->i_cat )
+    {
+    case AUDIO_ES:
+    {
+        audio_format_t a1 = p_fmt1->audio;
+        audio_format_t a2 = p_fmt2->audio;
+
+        if( a1.i_format && a2.i_format && a1.i_format != a2.i_format )
+            return false;
+        if( a1.i_rate != a2.i_rate ||
+            a1.i_physical_channels != a2.i_physical_channels ||
+            a1.i_original_channels != a2.i_original_channels )
+            return false;
+        return true;
+    }
+
+    case VIDEO_ES:
+    {
+        video_format_t v1 = p_fmt1->video;
+        video_format_t v2 = p_fmt2->video;
+        if( !v1.i_chroma )
+            v1.i_chroma = vlc_fourcc_GetCodec( p_fmt1->i_cat, p_fmt1->i_codec );
+        if( !v2.i_chroma )
+            v2.i_chroma = vlc_fourcc_GetCodec( p_fmt1->i_cat, p_fmt2->i_codec );
+        return video_format_IsSimilar( &p_fmt1->video, &p_fmt2->video );
+    }
+
+    case SPU_ES:
+    default:
+        return true;
+    }
+}
+