OSDN Git Service

Added libhb and CLI support for Dolby Pro Logic II 5.0 matrix encoding. *NOT YET...
[handbrake-jp/handbrake-jp-git.git] / libhb / common.h
index 402ae7f..4934063 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef HB_COMMON_H
 #define HB_COMMON_H
 
+#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 typedef struct hb_handle_s hb_handle_t;
 typedef struct hb_list_s hb_list_t;
 typedef struct hb_rate_s hb_rate_t;
+typedef struct hb_mixdown_s hb_mixdown_t;
 typedef struct hb_job_s  hb_job_t;
 typedef struct hb_title_s hb_title_t;
 typedef struct hb_chapter_s hb_chapter_t;
 typedef struct hb_audio_s hb_audio_t;
 typedef struct hb_subtitle_s hb_subtitle_t;
 typedef struct hb_state_s hb_state_t;
+typedef union  hb_esconfig_u     hb_esconfig_t;
+typedef struct hb_work_private_s hb_work_private_t;
+typedef struct hb_work_object_s  hb_work_object_t;
+typedef struct hb_buffer_s hb_buffer_t;
+typedef struct hb_fifo_s hb_fifo_t;
+typedef struct hb_lock_s hb_lock_t;
 
 #include "ports.h"
 #ifdef __LIBHB__
@@ -49,6 +57,8 @@ void        hb_list_rem( hb_list_t *, void * );
 void      * hb_list_item( hb_list_t *, int );
 void        hb_list_close( hb_list_t ** );
 
+void hb_reduce( int *x, int *y, int num, int den );
+
 #define HB_KEEP_WIDTH  0
 #define HB_KEEP_HEIGHT 1
 void hb_fix_aspect( hb_job_t * job, int keep );
@@ -61,17 +71,26 @@ struct hb_rate_s
     int    rate;
 };
 
+struct hb_mixdown_s
+{
+    char * human_readable_name;
+    char * internal_name;
+    int    amixdown;
+};
+
 #define HB_ASPECT_BASE 9
 #define HB_VIDEO_RATE_BASE   27000000
 
-extern hb_rate_t hb_video_rates[];
-extern int       hb_video_rates_count;
-extern hb_rate_t hb_audio_rates[];
-extern int       hb_audio_rates_count;
-extern int       hb_audio_rates_default;
-extern hb_rate_t hb_audio_bitrates[];
-extern int       hb_audio_bitrates_count;
-extern int       hb_audio_bitrates_default;
+extern hb_rate_t    hb_video_rates[];
+extern int          hb_video_rates_count;
+extern hb_rate_t    hb_audio_rates[];
+extern int          hb_audio_rates_count;
+extern int          hb_audio_rates_default;
+extern hb_rate_t    hb_audio_bitrates[];
+extern int          hb_audio_bitrates_count;
+extern int          hb_audio_bitrates_default;
+extern hb_mixdown_t hb_audio_mixdowns[];
+extern int          hb_audio_mixdowns_count;
 
 /******************************************************************************
  * hb_job_t: settings to be filled by the UI
@@ -85,18 +104,33 @@ struct hb_job_s
     int             chapter_start;
     int             chapter_end;
 
+       /* Include chapter marker track in mp4? */
+    int             chapter_markers;
+
     /* Picture settings:
-         crop:        must be multiples of 2 (top/bottom/left/right)
-         deinterlace: 0 or 1
-         width:       must be a multiple of 16
-         height:      must be a multiple of 16
-         keep_ratio:  used by UIs */
+         crop:                must be multiples of 2 (top/bottom/left/right)
+         deinterlace:         0 or 1
+         width:               must be a multiple of 16
+         height:              must be a multiple of 16
+         keep_ratio:          used by UIs 
+         pixel_ratio:         store pixel aspect ratio in the video
+         pixel_aspect_width:  numerator for pixel aspect ratio
+         pixel_aspect_height: denominator for pixel aspect ratio
+                maxWidth:                        keep width below this
+                maxHeight:                       keep height below this */
+
     int             crop[4];
     int             deinterlace;
     int             width;
     int             height;
     int             keep_ratio;
     int             grayscale;
+    int             pixel_ratio;
+    int             pixel_aspect_width;
+    int             pixel_aspect_height;
+       int                             maxWidth;
+       int                             maxHeight;
+
 
     /* Video settings:
          vcodec:            output codec
@@ -104,11 +138,16 @@ struct hb_job_s
                             if < 0.0 or > 1.0, bitrate is used instead
          vbitrate:          output bitrate (kbps)
          pass:              0, 1 or 2
-         vrate, vrate_base: output framerate is vrate / vrate_base */
+         vrate, vrate_base: output framerate is vrate / vrate_base
+                h264_level:            boolean for whether or not we're encoding for iPod
+                crf:                           boolean for whether to use constant rate factor with x264
+                x264opts:                      string of extra x264 options 
+                areBframes:            boolean to note if b-frames are included in x264opts */
 #define HB_VCODEC_MASK   0x0000FF
 #define HB_VCODEC_FFMPEG 0x000001
 #define HB_VCODEC_XVID   0x000002
 #define HB_VCODEC_X264   0x000004
+
     int             vcodec;
     float           vquality;
     int             vbitrate;
@@ -116,11 +155,43 @@ struct hb_job_s
     int             vrate_base;
     int             pass;
     int             h264_13;
-
+       int                             h264_level;
+       int                             crf;
+       const char              *x264opts;
+       int                             areBframes;
+       
     /* Audio tracks:
-         Indexes in hb_title_t's audios list, starting from 0.
-         -1 indicates the end of the list */
+         audios:          Indexes in hb_title_t's audios list, starting from 0.
+                          -1 indicates the end of the list
+            audio_mixdowns:  The mixdown to be used for each audio track in audios[] */
+
+/* define some masks, used to extract the various information from the HB_AMIXDOWN_XXXX values */
+#define HB_AMIXDOWN_A52_FORMAT_MASK             0x00FF0000
+#define HB_AMIXDOWN_DISCRETE_CHANNEL_COUNT_MASK 0x0000F000
+#define HB_AMIXDOWN_FRONT_CHANNEL_COUNT_MASK    0x00000F00
+#define HB_AMIXDOWN_REAR_CHANNEL_COUNT_MASK     0x000000F0
+#define HB_AMIXDOWN_LFE_CHANNEL_COUNT_MASK      0x0000000F
+/* define the HB_AMIXDOWN_XXXX values */
+#define HB_AMIXDOWN_MONO                        0x01011100 // A52_FORMAT of A52_MONO                  = 1  = 0x01
+#define HB_AMIXDOWN_STEREO                      0x02022200 // A52_FORMAT of A52_STEREO                = 2  = 0x02
+#define HB_AMIXDOWN_DOLBY                       0x040A2310 // A52_FORMAT of A52_DOLBY                 = 10 = 0x0A
+#define HB_AMIXDOWN_DOLBYPLII                   0x084A2320 // A52_FORMAT of A52_DOLBY | A52_USE_DPLII = 74 = 0x4A
+#define HB_AMIXDOWN_6CH                         0x10176321 // A52_FORMAT of A52_3F2R | A52_LFE        = 23 = 0x17
+/* define some macros to extract the various information from the HB_AMIXDOWN_XXXX values */
+#define HB_AMIXDOWN_GET_A52_FORMAT( a ) ( ( a & HB_AMIXDOWN_A52_FORMAT_MASK ) >> 16 )
+#define HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT( a ) ( ( a & HB_AMIXDOWN_DISCRETE_CHANNEL_COUNT_MASK ) >> 12 )
+#define HB_AMIXDOWN_GET_FRONT_CHANNEL_COUNT( a ) ( ( a & HB_AMIXDOWN_FRONT_CHANNEL_COUNT_MASK ) >> 8 )
+#define HB_AMIXDOWN_GET_REAR_CHANNEL_COUNT( a ) ( ( a & HB_AMIXDOWN_REAR_CHANNEL_COUNT_MASK ) >> 4 )
+#define HB_AMIXDOWN_GET_LFE_CHANNEL_COUNT( a ) ( ( a & HB_AMIXDOWN_LFE_CHANNEL_COUNT_MASK ) )
+#define HB_AMIXDOWN_GET_NORMAL_CHANNEL_COUNT( a ) ( (( a & HB_AMIXDOWN_FRONT_CHANNEL_COUNT_MASK ) >> 8) + (( a & HB_AMIXDOWN_REAR_CHANNEL_COUNT_MASK ) >> 4) )
     int             audios[8];
+       int             audio_mixdowns[8];
+
+       /* this "surround" property will be removed shortly,
+       as soon as the AMIXDOWN code has been integrated into the Mac GUI
+       it's still included here to avoid breaking the Mac GUI short-term
+       however, it won't be applied in deca52.c etc. any more */
+       int             surround;
 
     /* Audio settings:
          acodec:   output codec
@@ -149,10 +220,13 @@ struct hb_job_s
          file: file path */
 #define HB_MUX_MASK 0xFF0000
 #define HB_MUX_MP4  0x010000
-#define HB_MUX_AVI  0x020000
-#define HB_MUX_OGM  0x040000
+#define HB_MUX_PSP  0x020000
+#define HB_MUX_AVI  0x040000
+#define HB_MUX_OGM  0x080000
+#define HB_MUX_IPOD 0x100000
+       
     int             mux;
-    char          * file;
+    const char          * file;
 
 #ifdef __LIBHB__
     /* Internal data */
@@ -172,27 +246,7 @@ struct hb_job_s
 
     hb_list_t     * list_work;
 
-    union
-    {
-        struct
-        {
-            uint8_t * config;
-            int       config_length;
-        } mpeg4;
-
-        struct
-        {
-            uint8_t * sps;
-            int       sps_length;
-            uint8_t * pps;
-            int       pps_length;
-        } h264;
-
-    } config;
-
-    /* MPEG-4 / AVC */
-    uint8_t       * es_config;
-    int             es_config_length;
+    hb_esconfig_t config;
 
     hb_mux_data_t * mux_data;
 #endif
@@ -202,10 +256,21 @@ struct hb_audio_s
 {
     int  id;
     char lang[1024];
+    char lang_simple[1024];
+    char iso639_2[4];
     int  codec;
     int  rate;
     int  bitrate;
-    int  channels;
+       /* src_discrete_front_channels: The # of discrete front channels in the source audio
+          src_discrete_rear_channels:  The # of discrete rear channels in the source audio
+          src_discrete_lfe_channels:   The # of discrete lfe channels in the source audio
+          src_encoded_front_channels:  The # of front channels encoded into the source audio
+          src_encoded_rear_channels:   The # of rear channels encoded into the source audio */
+    int src_discrete_front_channels;
+    int src_discrete_rear_channels;
+       int src_discrete_lfe_channels;
+    int src_encoded_front_channels;
+    int src_encoded_rear_channels;
 
 #ifdef __LIBHB__
     /* Internal data */
@@ -214,23 +279,12 @@ struct hb_audio_s
     hb_fifo_t * fifo_sync; /* Resampled, synced raw audio */
     hb_fifo_t * fifo_out;  /* MP3/AAC/Vorbis ES */
 
-    union
-    {
-        struct
-        {
-            uint8_t       * decinfo;
-            unsigned long   size;
-        } faac;
-
-        struct
-        {
-            uint8_t * headers[3];
-            int       sizes[3];
-        } vorbis;
+    hb_esconfig_t config;
+    hb_mux_data_t * mux_data;
 
-    } config;
+       /* amixdown is the mixdown format to be used for this audio track */
+       int amixdown;
 
-    hb_mux_data_t * mux_data;
 #endif
 };
 
@@ -256,6 +310,7 @@ struct hb_subtitle_s
 {
     int  id;
     char lang[1024];
+    char iso639_2[4];
 
 #ifdef __LIBHB__
     /* Internal data */
@@ -267,6 +322,7 @@ struct hb_subtitle_s
 struct hb_title_s
 {
     char        dvd[1024];
+    char        name[1024];
     int         index;
     int         vts;
     int         ttn;
@@ -310,6 +366,7 @@ struct hb_state_s
 #define HB_STATE_WORKING  8
 #define HB_STATE_PAUSED   16
 #define HB_STATE_WORKDONE 32
+#define HB_STATE_MUXING   64
     int state;
 
     union
@@ -343,7 +400,54 @@ struct hb_state_s
             int error;
         } workdone;
 
+        struct
+        {
+            /* HB_STATE_MUXING */
+            float progress;
+        } muxing;
     } param;
 };
 
+struct hb_work_object_s
+{
+    int                 id;
+    char              * name;
+
+#ifdef __LIBHB__
+    int              (* init)  ( hb_work_object_t *, hb_job_t * );
+    int              (* work)  ( hb_work_object_t *, hb_buffer_t **,
+                                 hb_buffer_t ** );
+    void             (* close) ( hb_work_object_t * );
+
+    hb_fifo_t         * fifo_in;
+    hb_fifo_t         * fifo_out;
+    hb_esconfig_t     * config;
+
+       /* amixdown is the mixdown format to be used if the work object is an audio track */
+       int               amixdown;
+
+    hb_work_private_t * private_data;
+
+    hb_thread_t       * thread;
+    volatile int      * done;
+
+    hb_work_object_t  * next;
+       int                               thread_sleep_interval;
+#endif
+};
+
+extern hb_work_object_t hb_sync;
+extern hb_work_object_t hb_decmpeg2;
+extern hb_work_object_t hb_decsub;
+extern hb_work_object_t hb_render;
+extern hb_work_object_t hb_encavcodec;
+extern hb_work_object_t hb_encxvid;
+extern hb_work_object_t hb_encx264;
+extern hb_work_object_t hb_deca52;
+extern hb_work_object_t hb_decavcodec;
+extern hb_work_object_t hb_declpcm;
+extern hb_work_object_t hb_encfaac;
+extern hb_work_object_t hb_enclame;
+extern hb_work_object_t hb_encvorbis;
+
 #endif