OSDN Git Service

Forgot a comma in common.c .
[handbrake-jp/handbrake-jp-git.git] / libhb / common.c
1 /* $Id: common.c,v 1.15 2005/03/17 19:22:47 titer Exp $
2
3    This file is part of the HandBrake source code.
4    Homepage: <http://handbrake.fr/>.
5    It may be used under the terms of the GNU General Public License. */
6
7 #include <stdarg.h>
8 #include <time.h>
9 #include <sys/time.h>
10
11 #include "common.h"
12
13 /**********************************************************************
14  * Global variables
15  *********************************************************************/
16 hb_rate_t hb_video_rates[] =
17 { { "5",  5400000 }, { "10",     2700000 }, { "12", 2250000 },
18   { "15", 1800000 }, { "23.976", 1126125 }, { "24", 1125000 },
19   { "25", 1080000 }, { "29.97",  900900  } };
20 int hb_video_rates_count = sizeof( hb_video_rates ) /
21                            sizeof( hb_rate_t );
22
23 hb_rate_t hb_audio_rates[] =
24 { { "22.05", 22050 }, { "24", 24000 }, { "32", 32000 },
25   { "44.1",  44100 }, { "48", 48000 } };
26 int hb_audio_rates_count   = sizeof( hb_audio_rates ) /
27                              sizeof( hb_rate_t );
28 int hb_audio_rates_default = 3; /* 44100 Hz */
29
30 hb_rate_t hb_audio_bitrates[] =
31 { {  "32",  32 }, {  "40",  40 }, {  "48",  48 }, {  "56",  56 },
32   {  "64",  64 }, {  "80",  80 }, {  "96",  96 }, { "112", 112 },
33   { "128", 128 }, { "160", 160 }, { "192", 192 }, { "224", 224 },
34   { "256", 256 }, { "320", 320 }, { "384", 384 }, { "448", 448 },
35   { "768", 768 } };
36 int hb_audio_bitrates_count = sizeof( hb_audio_bitrates ) /
37                               sizeof( hb_rate_t );
38 int hb_audio_bitrates_default = 8; /* 128 kbps */
39
40 static hb_error_handler_t *error_handler = NULL;
41
42 hb_mixdown_t hb_audio_mixdowns[] =
43 { { "Mono",               "HB_AMIXDOWN_MONO",      "mono",   HB_AMIXDOWN_MONO      },
44   { "Stereo",             "HB_AMIXDOWN_STEREO",    "stereo", HB_AMIXDOWN_STEREO    },
45   { "Dolby Surround",     "HB_AMIXDOWN_DOLBY",     "dpl1",   HB_AMIXDOWN_DOLBY     },
46   { "Dolby Pro Logic II", "HB_AMIXDOWN_DOLBYPLII", "dpl2",   HB_AMIXDOWN_DOLBYPLII },
47   { "6-channel discrete", "HB_AMIXDOWN_6CH",       "6ch",    HB_AMIXDOWN_6CH       }
48 };
49 int hb_audio_mixdowns_count = sizeof( hb_audio_mixdowns ) /
50                               sizeof( hb_mixdown_t );
51
52 int hb_mixdown_get_mixdown_from_short_name( const char * short_name )
53 {
54     int i;
55     for (i = 0; i < hb_audio_mixdowns_count; i++)
56     {
57         if (strcmp(hb_audio_mixdowns[i].short_name, short_name) == 0)
58         {
59             return hb_audio_mixdowns[i].amixdown;
60         }
61     }
62     return 0;
63 }
64
65 const char * hb_mixdown_get_short_name_from_mixdown( int amixdown )
66 {
67     int i;
68     for (i = 0; i < hb_audio_mixdowns_count; i++)
69     {
70         if (hb_audio_mixdowns[i].amixdown == amixdown)
71         {
72             return hb_audio_mixdowns[i].short_name;
73         }
74     }
75     return "";
76 }
77
78 /**********************************************************************
79  * hb_reduce
80  **********************************************************************
81  * Given a numerator (num) and a denominator (den), reduce them to an
82  * equivalent fraction and store the result in x and y.
83  *********************************************************************/
84 void hb_reduce( int *x, int *y, int num, int den )
85 {
86     // find the greatest common divisor of num & den by Euclid's algorithm
87     int n = num, d = den;
88     while ( d )
89     {
90         int t = d;
91         d = n % d;
92         n = t;
93     }
94
95     // at this point n is the gcd. if it's non-zero remove it from num
96     // and den. Otherwise just return the original values.
97     if ( n )
98     {
99         *x = num / n;
100         *y = den / n;
101     }
102     else
103     {
104         *x = num;
105         *y = den;
106     }
107 }
108
109 /**********************************************************************
110  * hb_fix_aspect
111  **********************************************************************
112  * Given the output width (if HB_KEEP_WIDTH) or height
113  * (HB_KEEP_HEIGHT) and the current crop values, calculates the
114  * correct height or width in order to respect the DVD aspect ratio
115  *********************************************************************/
116 void hb_fix_aspect( hb_job_t * job, int keep )
117 {
118     hb_title_t * title = job->title;
119     int          i;
120
121     /* don't do anything unless the title has complete size info */
122     if ( title->height == 0 || title->width == 0 || title->aspect == 0 )
123     {
124         hb_log( "hb_fix_aspect: incomplete info for title %d: "
125                 "height = %d, width = %d, aspect = %d",
126                 title->height, title->width, title->aspect );
127         return;
128     }
129
130     /* Sanity checks:
131        Widths and heights must be multiples of 16 and greater than or
132        equal to 16
133        Crop values must be multiples of 2, greater than or equal to 0
134        and less than half of the dimension */
135     job->width   = MULTIPLE_16( job->width );
136     job->height  = MULTIPLE_16( job->height );
137     job->width   = MAX( 16, job->width );
138     job->height  = MAX( 16, job->height );
139     for( i = 0; i < 4; i++ )
140     {
141         job->crop[i] = EVEN( job->crop[i] );
142         job->crop[i] = MAX( 0, job->crop[i] );
143         if( i < 2 )
144         {
145             /* Top, bottom */
146             job->crop[i] = MIN( job->crop[i], ( title->height / 2 ) - 2 );
147         }
148         else
149         {
150             /* Left, right */
151             job->crop[i] = MIN( job->crop[i], ( title->width / 2 ) - 2 );
152         }
153     }
154
155     double par = (double)title->width / ( (double)title->height * title->aspect );
156     double cropped_sar = (double)( title->height - job->crop[0] - job->crop[1] ) /
157                          (double)(title->width - job->crop[2] - job->crop[3] );
158     double ar = par * cropped_sar;
159     if( keep == HB_KEEP_WIDTH )
160     {
161         job->height = MULTIPLE_16( (uint64_t)( (double)job->width * ar ) );
162         job->height = MAX( 16, job->height );
163     }
164     else
165     {
166         job->width = MULTIPLE_16( (uint64_t)( (double)job->height / ar ) );
167         job->width = MAX( 16, job->width );
168     }
169 }
170
171 /**********************************************************************
172  * hb_calc_bitrate
173  **********************************************************************
174  * size: in megabytes
175  *********************************************************************/
176 int hb_calc_bitrate( hb_job_t * job, int size )
177 {
178     int64_t avail = (int64_t) size * 1024 * 1024;
179     int64_t length;
180     int     overhead;
181     int     samples_per_frame;
182     int     i;
183
184     hb_title_t   * title = job->title;
185     hb_chapter_t * chapter;
186     hb_audio_t   * audio;
187
188     /* How many overhead bytes are used for each frame
189        (quite guessed) */
190     switch( job->mux )
191     {
192        case HB_MUX_MP4:
193        case HB_MUX_PSP:
194                 case HB_MUX_IPOD:
195                 case HB_MUX_MKV:
196             overhead = 6;
197             break;
198         case HB_MUX_AVI:
199             overhead = 24;
200             break;
201         case HB_MUX_OGM:
202             overhead = 6;
203             break;
204         default:
205             return 0;
206     }
207
208     /* Get the duration in seconds */
209     length = 0;
210     for( i = job->chapter_start; i <= job->chapter_end; i++ )
211     {
212         chapter = hb_list_item( title->list_chapter, i - 1 );
213         length += chapter->duration;
214     }
215     length += 135000;
216     length /= 90000;
217
218     /* Video overhead */
219     avail -= length * job->vrate * overhead / job->vrate_base;
220
221     for( i = 0; i < hb_list_count(job->list_audio); i++ )
222     {
223         /* Audio data */
224         int abitrate;
225         audio = hb_list_item( job->list_audio, i);
226
227         /* How many audio samples we put in each frame */
228         switch( audio->config.out.codec )
229         {
230             case HB_ACODEC_FAAC:
231             case HB_ACODEC_CA_AAC:
232             case HB_ACODEC_VORBIS:
233                 samples_per_frame = 1024;
234                 break;
235             case HB_ACODEC_LAME:
236                 samples_per_frame = 1152;
237                 break;
238             case HB_ACODEC_AC3:
239             case HB_ACODEC_DCA:
240                 samples_per_frame = 1536;
241                 break;
242             default:
243                 return 0;
244         }
245
246         if( audio->config.out.codec == HB_ACODEC_AC3 ||
247             audio->config.out.codec == HB_ACODEC_DCA)
248         {
249             /*
250              * For pass through we take the bitrate from the input audio
251              * bitrate as we are simply passing it through.
252              */
253             abitrate = audio->config.in.bitrate / 8;
254         }
255         else
256         {
257             /*
258              * Where we are transcoding the audio we use the destination
259              * bitrate.
260              */
261             abitrate = audio->config.out.bitrate * 1000 / 8;
262         }
263         avail -= length * abitrate;
264
265         /* Audio overhead */
266         avail -= length * audio->config.out.samplerate * overhead / samples_per_frame;
267     }
268
269     if( avail < 0 )
270     {
271         return 0;
272     }
273
274     return ( avail / ( 125 * length ) );
275 }
276
277 /**********************************************************************
278  * hb_list implementation
279  **********************************************************************
280  * Basic and slow, but enough for what we need
281  *********************************************************************/
282
283 #define HB_LIST_DEFAULT_SIZE 20
284
285 struct hb_list_s
286 {
287     /* Pointers to items in the list */
288     void ** items;
289
290     /* How many (void *) allocated in 'items' */
291     int     items_alloc;
292
293     /* How many valid pointers in 'items' */
294     int     items_count;
295 };
296
297 /**********************************************************************
298  * hb_list_init
299  **********************************************************************
300  * Allocates an empty list ready for HB_LIST_DEFAULT_SIZE items
301  *********************************************************************/
302 hb_list_t * hb_list_init()
303 {
304     hb_list_t * l;
305
306     l              = calloc( sizeof( hb_list_t ), 1 );
307     l->items       = calloc( HB_LIST_DEFAULT_SIZE * sizeof( void * ), 1 );
308     l->items_alloc = HB_LIST_DEFAULT_SIZE;
309
310     return l;
311 }
312
313 /**********************************************************************
314  * hb_list_count
315  **********************************************************************
316  * Returns the number of items currently in the list
317  *********************************************************************/
318 int hb_list_count( hb_list_t * l )
319 {
320     return l->items_count;
321 }
322
323 /**********************************************************************
324  * hb_list_add
325  **********************************************************************
326  * Adds an item at the end of the list, making it bigger if necessary.
327  * Can safely be called with a NULL pointer to add, it will be ignored.
328  *********************************************************************/
329 void hb_list_add( hb_list_t * l, void * p )
330 {
331     if( !p )
332     {
333         return;
334     }
335
336     if( l->items_count == l->items_alloc )
337     {
338         /* We need a bigger boat */
339         l->items_alloc += HB_LIST_DEFAULT_SIZE;
340         l->items        = realloc( l->items,
341                                    l->items_alloc * sizeof( void * ) );
342     }
343
344     l->items[l->items_count] = p;
345     (l->items_count)++;
346 }
347
348 /**********************************************************************
349  * hb_list_rem
350  **********************************************************************
351  * Remove an item from the list. Bad things will happen if called
352  * with a NULL pointer or if the item is not in the list.
353  *********************************************************************/
354 void hb_list_rem( hb_list_t * l, void * p )
355 {
356     int i;
357
358     /* Find the item in the list */
359     for( i = 0; i < l->items_count; i++ )
360     {
361         if( l->items[i] == p )
362         {
363             break;
364         }
365     }
366
367     /* Shift all items after it sizeof( void * ) bytes earlier */
368     memmove( &l->items[i], &l->items[i+1],
369              ( l->items_count - i - 1 ) * sizeof( void * ) );
370
371     (l->items_count)--;
372 }
373
374 /**********************************************************************
375  * hb_list_item
376  **********************************************************************
377  * Returns item at position i, or NULL if there are not that many
378  * items in the list
379  *********************************************************************/
380 void * hb_list_item( hb_list_t * l, int i )
381 {
382     if( i < 0 || i >= l->items_count )
383     {
384         return NULL;
385     }
386
387     return l->items[i];
388 }
389
390 /**********************************************************************
391  * hb_list_bytes
392  **********************************************************************
393  * Assuming all items are of type hb_buffer_t, returns the total
394  * number of bytes in the list
395  *********************************************************************/
396 int hb_list_bytes( hb_list_t * l )
397 {
398     hb_buffer_t * buf;
399     int           ret;
400     int           i;
401
402     ret = 0;
403     for( i = 0; i < hb_list_count( l ); i++ )
404     {
405         buf  = hb_list_item( l, i );
406         ret += buf->size - buf->cur;
407     }
408
409     return ret;
410 }
411
412 /**********************************************************************
413  * hb_list_seebytes
414  **********************************************************************
415  * Assuming all items are of type hb_buffer_t, copy <size> bytes from
416  * the list to <dst>, keeping the list unmodified.
417  *********************************************************************/
418 void hb_list_seebytes( hb_list_t * l, uint8_t * dst, int size )
419 {
420     hb_buffer_t * buf;
421     int           copied;
422     int           copying;
423     int           i;
424
425     for( i = 0, copied = 0; copied < size; i++ )
426     {
427         buf     = hb_list_item( l, i );
428         copying = MIN( buf->size - buf->cur, size - copied );
429         memcpy( &dst[copied], &buf->data[buf->cur], copying );
430         copied += copying;
431     }
432 }
433
434 /**********************************************************************
435  * hb_list_getbytes
436  **********************************************************************
437  * Assuming all items are of type hb_buffer_t, copy <size> bytes from
438  * the list to <dst>. What's copied is removed from the list.
439  * The variable pointed by <pts> is set to the PTS of the buffer the
440  * first byte has been got from.
441  * The variable pointed by <pos> is set to the position of that byte
442  * in that buffer.
443  *********************************************************************/
444 void hb_list_getbytes( hb_list_t * l, uint8_t * dst, int size,
445                        uint64_t * pts, uint64_t * pos )
446 {
447     hb_buffer_t * buf;
448     int           copied;
449     int           copying;
450     uint8_t       has_pts;
451
452     /* So we won't have to deal with NULL pointers */
453      uint64_t dummy1, dummy2;
454
455     if( !pts ) pts = &dummy1;
456     if( !pos ) pos = &dummy2;
457
458     for( copied = 0, has_pts = 0; copied < size;  )
459     {
460         buf     = hb_list_item( l, 0 );
461         copying = MIN( buf->size - buf->cur, size - copied );
462         memcpy( &dst[copied], &buf->data[buf->cur], copying );
463
464         if( !has_pts )
465         {
466             *pts    = buf->start;
467             *pos    = buf->cur;
468             has_pts = 1;
469         }
470
471         buf->cur += copying;
472         if( buf->cur >= buf->size )
473         {
474             hb_list_rem( l, buf );
475             hb_buffer_close( &buf );
476         }
477
478         copied += copying;
479     }
480 }
481
482 /**********************************************************************
483  * hb_list_empty
484  **********************************************************************
485  * Assuming all items are of type hb_buffer_t, close them all and
486  * close the list.
487  *********************************************************************/
488 void hb_list_empty( hb_list_t ** _l )
489 {
490     hb_list_t * l = *_l;
491     hb_buffer_t * b;
492
493     while( ( b = hb_list_item( l, 0 ) ) )
494     {
495         hb_list_rem( l, b );
496         hb_buffer_close( &b );
497     }
498
499     hb_list_close( _l );
500 }
501
502 /**********************************************************************
503  * hb_list_close
504  **********************************************************************
505  * Free memory allocated by hb_list_init. Does NOT free contents of
506  * items still in the list.
507  *********************************************************************/
508 void hb_list_close( hb_list_t ** _l )
509 {
510     hb_list_t * l = *_l;
511
512     free( l->items );
513     free( l );
514
515     *_l = NULL;
516 }
517
518 /**********************************************************************
519  * hb_log
520  **********************************************************************
521  * If verbose mode is one, print message with timestamp. Messages
522  * longer than 180 characters are stripped ;p
523  *********************************************************************/
524 void hb_log( char * log, ... )
525 {
526     char        string[362]; /* 360 chars + \n + \0 */
527     time_t      _now;
528     struct tm * now;
529     va_list     args;
530
531     if( !getenv( "HB_DEBUG" ) )
532     {
533         /* We don't want to print it */
534         return;
535     }
536
537     /* Get the time */
538     _now = time( NULL );
539     now  = localtime( &_now );
540     sprintf( string, "[%02d:%02d:%02d] ",
541              now->tm_hour, now->tm_min, now->tm_sec );
542
543     /* Convert the message to a string */
544     va_start( args, log );
545     vsnprintf( string + 11, 349, log, args );
546     va_end( args );
547
548     /* Add the end of line */
549     strcat( string, "\n" );
550
551     /* Print it */
552     fprintf( stderr, "%s", string );
553 }
554
555 int global_verbosity_level; //Necessary for hb_deep_log
556 /**********************************************************************
557  * hb_deep_log
558  **********************************************************************
559  * If verbose mode is >= level, print message with timestamp. Messages
560  * longer than 360 characters are stripped ;p
561  *********************************************************************/
562 void hb_deep_log( hb_debug_level_t level, char * log, ... )
563 {
564     char        string[362]; /* 360 chars + \n + \0 */
565     time_t      _now;
566     struct tm * now;
567     va_list     args;
568
569     if( global_verbosity_level < level )
570     {
571         /* Hiding message */
572         return;
573     }
574
575     /* Get the time */
576     _now = time( NULL );
577     now  = localtime( &_now );
578     sprintf( string, "[%02d:%02d:%02d] ",
579              now->tm_hour, now->tm_min, now->tm_sec );
580
581     /* Convert the message to a string */
582     va_start( args, log );
583     vsnprintf( string + 11, 349, log, args );
584     va_end( args );
585
586     /* Add the end of line */
587     strcat( string, "\n" );
588
589     /* Print it */
590     fprintf( stderr, "%s", string );
591 }
592
593 /**********************************************************************
594  * hb_error
595  **********************************************************************
596  * Using whatever output is available display this error.
597  *********************************************************************/
598 void hb_error( char * log, ... )
599 {
600     char        string[181]; /* 180 chars + \0 */
601     va_list     args;
602
603     /* Convert the message to a string */
604     va_start( args, log );
605     vsnprintf( string, 180, log, args );
606     va_end( args );
607
608     /*
609      * Got the error in a single string, send it off to be dispatched.
610      */
611     if( error_handler )
612     {
613         error_handler( string );
614     } else {
615         hb_log( string );
616     }
617 }
618
619 void hb_register_error_handler( hb_error_handler_t * handler )
620 {
621     error_handler = handler;
622 }
623
624 /**********************************************************************
625  * hb_title_init
626  **********************************************************************
627  *
628  *********************************************************************/
629 hb_title_t * hb_title_init( char * dvd, int index )
630 {
631     hb_title_t * t;
632
633     t = calloc( sizeof( hb_title_t ), 1 );
634
635     t->index         = index;
636     t->list_audio    = hb_list_init();
637     t->list_chapter  = hb_list_init();
638     t->list_subtitle = hb_list_init();
639     strcat( t->dvd, dvd );
640     // default to decoding mpeg2
641     t->video_id      = 0xE0;
642     t->video_codec   = WORK_DECMPEG2;
643
644     return t;
645 }
646
647 /**********************************************************************
648  * hb_title_close
649  **********************************************************************
650  *
651  *********************************************************************/
652 void hb_title_close( hb_title_t ** _t )
653 {
654     hb_title_t * t = *_t;
655     hb_audio_t * audio;
656     hb_chapter_t * chapter;
657     hb_subtitle_t * subtitle;
658
659     while( ( audio = hb_list_item( t->list_audio, 0 ) ) )
660     {
661         hb_list_rem( t->list_audio, audio );
662         free( audio );
663     }
664     hb_list_close( &t->list_audio );
665
666     while( ( chapter = hb_list_item( t->list_chapter, 0 ) ) )
667     {
668         hb_list_rem( t->list_chapter, chapter );
669         free( chapter );
670     }
671     hb_list_close( &t->list_chapter );
672
673     while( ( subtitle = hb_list_item( t->list_subtitle, 0 ) ) )
674     {
675         hb_list_rem( t->list_subtitle, subtitle );
676         free( subtitle );
677     }
678     hb_list_close( &t->list_subtitle );
679
680     if( t->metadata )
681     {
682         if( t->metadata->coverart )
683         {
684             free( t->metadata->coverart );
685         }
686         free( t->metadata );
687     }
688
689     free( t );
690     *_t = NULL;
691 }
692
693 /**********************************************************************
694  * hb_filter_close
695  **********************************************************************
696  *
697  *********************************************************************/
698 void hb_filter_close( hb_filter_object_t ** _f )
699 {
700     hb_filter_object_t * f = *_f;
701
702     f->close( f->private_data );
703
704     if( f->name )
705         free( f->name );
706     if( f->settings )
707         free( f->settings );
708
709     free( f );
710     *_f = NULL;
711 }
712
713 /**********************************************************************
714  * hb_audio_copy
715  **********************************************************************
716  *
717  *********************************************************************/
718 hb_audio_t *hb_audio_copy(const hb_audio_t *src)
719 {
720     hb_audio_t *audio = NULL;
721
722     if( src )
723     {
724         audio = calloc(1, sizeof(*audio));
725         memcpy(audio, src, sizeof(*audio));
726     }
727     return audio;
728 }
729
730 /**********************************************************************
731  * hb_audio_new
732  **********************************************************************
733  *
734  *********************************************************************/
735 void hb_audio_config_init(hb_audio_config_t * audiocfg)
736 {
737     /* Set read only paramaters to invalid values */
738     audiocfg->in.codec = 0xDEADBEEF;
739     audiocfg->in.bitrate = -1;
740     audiocfg->in.samplerate = -1;
741     audiocfg->in.channel_layout = 0;
742     audiocfg->in.version = 0;
743     audiocfg->in.mode = 0;
744     audiocfg->flags.ac3 = 0;
745     audiocfg->lang.description[0] = 0;
746     audiocfg->lang.simple[0] = 0;
747     audiocfg->lang.iso639_2[0] = 0;
748
749     /* Initalize some sensable defaults */
750     audiocfg->in.track = audiocfg->out.track = 0;
751     audiocfg->out.codec = HB_ACODEC_FAAC;
752     audiocfg->out.bitrate = 128;
753     audiocfg->out.samplerate = 44100;
754     audiocfg->out.mixdown = HB_AMIXDOWN_DOLBYPLII;
755     audiocfg->out.dynamic_range_compression = 0;
756     audiocfg->out.name = NULL;
757 }
758
759 /**********************************************************************
760  * hb_audio_add
761  **********************************************************************
762  *
763  *********************************************************************/
764 int hb_audio_add(const hb_job_t * job, const hb_audio_config_t * audiocfg)
765 {
766     hb_title_t *title = job->title;
767     hb_audio_t *audio;
768
769     audio = hb_audio_copy( hb_list_item( title->list_audio, audiocfg->in.track ) );
770     if( audio == NULL )
771     {
772         /* We fail! */
773         return 0;
774     }
775
776     if( (audiocfg->in.bitrate != -1) && (audiocfg->in.codec != 0xDEADBEEF) )
777     {
778         /* This most likely means the client didn't call hb_audio_config_init
779          * so bail.
780          */
781         return 0;
782     }
783
784     /* Really shouldn't ignore the passed out track, but there is currently no
785      * way to handle duplicates or out-of-order track numbers.
786      */
787     audio->config.out.track = hb_list_count(job->list_audio) + 1;
788     audio->config.out.codec = audiocfg->out.codec;
789     if( audiocfg->out.codec == audio->config.in.codec )
790     {
791         /* Pass-through, copy from input. */
792         audio->config.out.samplerate = audio->config.in.samplerate;
793         audio->config.out.bitrate = audio->config.in.bitrate;
794         audio->config.out.dynamic_range_compression = 0;
795         audio->config.out.mixdown = 0;
796     }
797     else
798     {
799         /* Non pass-through, use what is given. */
800         audio->config.out.samplerate = audiocfg->out.samplerate;
801         audio->config.out.bitrate = audiocfg->out.bitrate;
802         audio->config.out.dynamic_range_compression = audiocfg->out.dynamic_range_compression;
803         audio->config.out.mixdown = audiocfg->out.mixdown;
804     }
805
806     hb_list_add(job->list_audio, audio);
807     return 1;
808 }
809
810 hb_audio_config_t * hb_list_audio_config_item(hb_list_t * list, int i)
811 {
812     hb_audio_t *audio = NULL;
813
814     if( (audio = hb_list_item(list, i)) )
815         return &(audio->config);
816
817     return NULL;
818 }