OSDN Git Service

Fix a bus error if b-pyramid is given as an x264 option without specifying a value...
[handbrake-jp/handbrake-jp-git.git] / libhb / common.c
index e9d366f..560a839 100644 (file)
@@ -37,6 +37,29 @@ int hb_audio_bitrates_count = sizeof( hb_audio_bitrates ) /
 int hb_audio_bitrates_default = 8; /* 128 kbps */
 
 /**********************************************************************
+ * hb_reduce
+ **********************************************************************
+ * Given a numerator (num) and a denominator (den), reduce them to an
+ * equivalent fraction and store the result in x and y.
+ *********************************************************************/
+void hb_reduce( int *x, int *y, int num, int den )
+{
+    int lower = MIN( num, den );
+    int i;
+    *x = num;
+    *y = den;
+    for( i = lower - 1; i > 1; --i )
+    {
+        if( ( num % i == 0 ) && ( den % i == 0 ) )
+        {
+            *x = num / i;
+            *y = den / i;
+            break;
+        }
+    }
+}
+
+/**********************************************************************
  * hb_fix_aspect
  **********************************************************************
  * Given the output width (if HB_KEEP_WIDTH) or height
@@ -354,7 +377,7 @@ void hb_list_seebytes( hb_list_t * l, uint8_t * dst, int size )
  * in that buffer.
  *********************************************************************/
 void hb_list_getbytes( hb_list_t * l, uint8_t * dst, int size,
-                       uint64_t * pts, int * pos )
+                       uint64_t * pts, uint64_t * pos )
 {
     hb_buffer_t * buf;
     int           copied;
@@ -362,8 +385,8 @@ void hb_list_getbytes( hb_list_t * l, uint8_t * dst, int size,
     uint8_t       has_pts;
     
     /* So we won't have to deal with NULL pointers */
-    uint64_t dummy1;
-    int      dummy2;
+     uint64_t dummy1, dummy2;
+
     if( !pts ) pts = &dummy1;
     if( !pos ) pos = &dummy2;
 
@@ -492,11 +515,30 @@ hb_title_t * hb_title_init( char * dvd, int index )
 void hb_title_close( hb_title_t ** _t )
 {
     hb_title_t * t = *_t;
+    hb_audio_t * audio;
+    hb_chapter_t * chapter;
+    hb_subtitle_t * subtitle;
 
+    while( ( audio = hb_list_item( t->list_audio, 0 ) ) )
+    {
+        hb_list_rem( t->list_audio, audio );
+        free( audio );
+    }
     hb_list_close( &t->list_audio );
+    
+    while( ( chapter = hb_list_item( t->list_chapter, 0 ) ) )
+    {
+        hb_list_rem( t->list_chapter, chapter );
+        free( chapter );
+    }
     hb_list_close( &t->list_chapter );
+    
+    while( ( subtitle = hb_list_item( t->list_subtitle, 0 ) ) )
+    {
+        hb_list_rem( t->list_subtitle, subtitle );
+        free( subtitle );
+    }
     hb_list_close( &t->list_subtitle );
-    free( t->job );
 
     free( t );
     *_t = NULL;