1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2011-2014 L-SMASH project
6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *****************************************************************************/
21 /* This file is available under an ISC license. */
23 #include "common/internal.h" /* must be placed first */
27 #define LSMASH_IMPORTER_INTERNAL
30 /***************************************************************************
32 ETSI TS 102 366 V1.2.1 (2008-08)
33 ***************************************************************************/
34 #include "codecs/a52.h"
36 #define AC3_SAMPLE_DURATION 1536 /* 256 (samples per audio block) * 6 (audio blocks) */
41 uint64_t next_frame_pos
;
43 uint8_t buffer
[AC3_MAX_SYNCFRAME_LENGTH
];
47 static void remove_ac3_importer( ac3_importer_t
*ac3_imp
)
51 lsmash_bits_cleanup( ac3_imp
->info
.bits
);
52 lsmash_free( ac3_imp
);
55 static ac3_importer_t
*create_ac3_importer( importer_t
*importer
)
57 ac3_importer_t
*ac3_imp
= (ac3_importer_t
*)lsmash_malloc_zero( sizeof(ac3_importer_t
) );
60 ac3_imp
->info
.bits
= lsmash_bits_create( importer
->bs
);
61 if( !ac3_imp
->info
.bits
)
63 lsmash_free( ac3_imp
);
69 static void ac3_importer_cleanup( importer_t
*importer
)
71 debug_if( importer
&& importer
->info
)
72 remove_ac3_importer( importer
->info
);
75 static const uint32_t ac3_frame_size_table
[19][3] =
99 static lsmash_audio_summary_t
*ac3_create_summary( ac3_info_t
*info
)
101 lsmash_audio_summary_t
*summary
= (lsmash_audio_summary_t
*)lsmash_create_summary( LSMASH_SUMMARY_TYPE_AUDIO
);
104 lsmash_ac3_specific_parameters_t
*param
= &info
->dac3_param
;
105 lsmash_codec_specific_t
*cs
= lsmash_create_codec_specific_data( LSMASH_CODEC_SPECIFIC_DATA_TYPE_ISOM_AUDIO_AC_3
,
106 LSMASH_CODEC_SPECIFIC_FORMAT_UNSTRUCTURED
);
107 cs
->data
.unstructured
= lsmash_create_ac3_specific_info( &info
->dac3_param
, &cs
->size
);
108 if( !cs
->data
.unstructured
109 || lsmash_add_entry( &summary
->opaque
->list
, cs
) < 0 )
111 lsmash_cleanup_summary( (lsmash_summary_t
*)summary
);
112 lsmash_destroy_codec_specific_data( cs
);
115 summary
->sample_type
= ISOM_CODEC_TYPE_AC_3_AUDIO
;
116 summary
->max_au_length
= AC3_MAX_SYNCFRAME_LENGTH
;
117 summary
->aot
= MP4A_AUDIO_OBJECT_TYPE_NULL
; /* no effect */
118 summary
->frequency
= ac3_get_sample_rate( param
);
119 summary
->channels
= ac3_get_channel_count( param
);
120 summary
->sample_size
= 16; /* no effect */
121 summary
->samples_in_frame
= AC3_SAMPLE_DURATION
;
122 summary
->sbr_mode
= MP4A_AAC_SBR_NOT_SPECIFIED
; /* no effect */
126 static int ac3_compare_specific_param( lsmash_ac3_specific_parameters_t
*a
, lsmash_ac3_specific_parameters_t
*b
)
128 return (a
->fscod
!= b
->fscod
)
129 || (a
->bsid
!= b
->bsid
)
130 || (a
->bsmod
!= b
->bsmod
)
131 || (a
->acmod
!= b
->acmod
)
132 || (a
->lfeon
!= b
->lfeon
)
133 || ((a
->frmsizecod
>> 1) != (b
->frmsizecod
>> 1));
136 static int ac3_buffer_frame( uint8_t *buffer
, lsmash_bs_t
*bs
)
138 uint64_t remain_size
= lsmash_bs_get_remaining_buffer_size( bs
);
139 if( remain_size
< AC3_MAX_SYNCFRAME_LENGTH
)
141 int err
= lsmash_bs_read( bs
, bs
->buffer
.max_size
);
144 remain_size
= lsmash_bs_get_remaining_buffer_size( bs
);
146 uint64_t copy_size
= LSMASH_MIN( remain_size
, AC3_MAX_SYNCFRAME_LENGTH
);
147 memcpy( buffer
, lsmash_bs_get_buffer_data( bs
), copy_size
);
151 static int ac3_importer_get_accessunit( importer_t
*importer
, uint32_t track_number
, lsmash_sample_t
**p_sample
)
153 if( !importer
->info
)
154 return LSMASH_ERR_NAMELESS
;
155 if( track_number
!= 1 )
156 return LSMASH_ERR_FUNCTION_PARAM
;
157 lsmash_audio_summary_t
*summary
= (lsmash_audio_summary_t
*)lsmash_get_entry_data( importer
->summaries
, track_number
);
159 return LSMASH_ERR_NAMELESS
;
160 ac3_importer_t
*ac3_imp
= (ac3_importer_t
*)importer
->info
;
161 ac3_info_t
*info
= &ac3_imp
->info
;
162 importer_status current_status
= importer
->status
;
163 if( current_status
== IMPORTER_ERROR
)
164 return LSMASH_ERR_NAMELESS
;
165 if( current_status
== IMPORTER_EOF
)
167 lsmash_ac3_specific_parameters_t
*param
= &info
->dac3_param
;
168 uint32_t frame_size
= ac3_frame_size_table
[ param
->frmsizecod
>> 1 ][ param
->fscod
];
169 if( param
->fscod
== 0x1 && param
->frmsizecod
& 0x1 )
171 if( current_status
== IMPORTER_CHANGE
)
173 lsmash_codec_specific_t
*cs
= isom_get_codec_specific( summary
->opaque
, LSMASH_CODEC_SPECIFIC_DATA_TYPE_ISOM_AUDIO_AC_3
);
176 cs
->destruct( cs
->data
.unstructured
);
177 cs
->data
.unstructured
= ac3_imp
->next_dac3
;
179 summary
->frequency
= ac3_get_sample_rate( param
);
180 summary
->channels
= ac3_get_channel_count( param
);
181 //summary->layout_tag = ac3_channel_layout_table[ param->acmod ][ param->lfeon ];
183 lsmash_sample_t
*sample
= lsmash_create_sample( frame_size
);
185 return LSMASH_ERR_MEMORY_ALLOC
;
187 memcpy( sample
->data
, ac3_imp
->buffer
, frame_size
);
188 sample
->length
= frame_size
;
189 sample
->dts
= ac3_imp
->au_number
++ * summary
->samples_in_frame
;
190 sample
->cts
= sample
->dts
;
191 sample
->prop
.ra_flags
= ISOM_SAMPLE_RANDOM_ACCESS_FLAG_SYNC
;
192 sample
->prop
.pre_roll
.distance
= 1; /* MDCT */
193 lsmash_bs_t
*bs
= info
->bits
->bs
;
194 ac3_imp
->next_frame_pos
+= frame_size
;
195 lsmash_bs_read_seek( bs
, ac3_imp
->next_frame_pos
, SEEK_SET
);
196 uint8_t syncword
[2] =
198 lsmash_bs_show_byte( bs
, 0 ),
199 lsmash_bs_show_byte( bs
, 1 )
201 if( bs
->eob
|| (bs
->eof
&& 0 == lsmash_bs_get_remaining_buffer_size( bs
)) )
202 importer
->status
= IMPORTER_EOF
;
205 /* Parse the next syncframe header. */
206 if( syncword
[0] != 0x0b
207 || syncword
[1] != 0x77
208 || ac3_buffer_frame( ac3_imp
->buffer
, bs
) < 0 )
210 importer
->status
= IMPORTER_ERROR
;
211 return current_status
;
213 lsmash_ac3_specific_parameters_t current_param
= info
->dac3_param
;
214 ac3_parse_syncframe_header( info
);
215 if( ac3_compare_specific_param( ¤t_param
, &info
->dac3_param
) )
218 uint8_t *dac3
= lsmash_create_ac3_specific_info( &info
->dac3_param
, &dummy
);
221 importer
->status
= IMPORTER_ERROR
;
222 return current_status
;
224 ac3_imp
->next_dac3
= dac3
;
225 importer
->status
= IMPORTER_CHANGE
;
228 importer
->status
= IMPORTER_OK
;
230 return current_status
;
233 static int ac3_importer_probe( importer_t
*importer
)
235 ac3_importer_t
*ac3_imp
= create_ac3_importer( importer
);
237 return LSMASH_ERR_MEMORY_ALLOC
;
238 lsmash_bits_t
*bits
= ac3_imp
->info
.bits
;
239 lsmash_bs_t
*bs
= bits
->bs
;
240 bs
->buffer
.max_size
= AC3_MAX_SYNCFRAME_LENGTH
;
241 /* Check the syncword and parse the syncframe header */
243 if( lsmash_bs_show_byte( bs
, 0 ) != 0x0b
244 || lsmash_bs_show_byte( bs
, 1 ) != 0x77 )
246 err
= LSMASH_ERR_INVALID_DATA
;
249 if( (err
= ac3_buffer_frame( ac3_imp
->buffer
, bs
)) < 0
250 || (err
= ac3_parse_syncframe_header( &ac3_imp
->info
)) < 0 )
252 lsmash_audio_summary_t
*summary
= ac3_create_summary( &ac3_imp
->info
);
255 err
= LSMASH_ERR_NAMELESS
;
258 if( lsmash_add_entry( importer
->summaries
, summary
) < 0 )
260 lsmash_cleanup_summary( (lsmash_summary_t
*)summary
);
261 err
= LSMASH_ERR_MEMORY_ALLOC
;
264 ac3_imp
->au_number
= 0;
265 importer
->info
= ac3_imp
;
266 importer
->status
= IMPORTER_OK
;
269 remove_ac3_importer( ac3_imp
);
273 static uint32_t ac3_importer_get_last_delta( importer_t
*importer
, uint32_t track_number
)
275 debug_if( !importer
|| !importer
->info
)
277 ac3_importer_t
*ac3_imp
= (ac3_importer_t
*)importer
->info
;
278 if( !ac3_imp
|| track_number
!= 1 || importer
->status
!= IMPORTER_EOF
)
280 return AC3_SAMPLE_DURATION
;
283 const importer_functions ac3_importer
=
288 ac3_importer_get_accessunit
,
289 ac3_importer_get_last_delta
,
293 /***************************************************************************
294 Enhanced AC-3 importer
295 ETSI TS 102 366 V1.2.1 (2008-08)
296 ***************************************************************************/
297 #define EAC3_MIN_SAMPLE_DURATION 256
302 uint64_t next_frame_pos
;
303 uint32_t next_dec3_length
;
305 uint8_t current_fscod2
;
306 uint8_t buffer
[EAC3_MAX_SYNCFRAME_LENGTH
];
307 lsmash_multiple_buffers_t
*au_buffers
;
309 uint8_t *incomplete_au
;
311 uint32_t incomplete_au_length
;
313 uint32_t syncframe_count_in_au
;
316 static void remove_eac3_importer( eac3_importer_t
*eac3_imp
)
320 lsmash_destroy_multiple_buffers( eac3_imp
->au_buffers
);
321 lsmash_bits_cleanup( eac3_imp
->info
.bits
);
322 lsmash_free( eac3_imp
);
325 static eac3_importer_t
*create_eac3_importer( importer_t
*importer
)
327 eac3_importer_t
*eac3_imp
= (eac3_importer_t
*)lsmash_malloc_zero( sizeof(eac3_importer_t
) );
330 eac3_info_t
*info
= &eac3_imp
->info
;
331 info
->bits
= lsmash_bits_create( importer
->bs
);
334 lsmash_free( eac3_imp
);
337 eac3_imp
->au_buffers
= lsmash_create_multiple_buffers( 2, EAC3_MAX_SYNCFRAME_LENGTH
);
338 if( !eac3_imp
->au_buffers
)
340 lsmash_bits_cleanup( info
->bits
);
341 lsmash_free( eac3_imp
);
344 eac3_imp
->au
= lsmash_withdraw_buffer( eac3_imp
->au_buffers
, 1 );
345 eac3_imp
->incomplete_au
= lsmash_withdraw_buffer( eac3_imp
->au_buffers
, 2 );
349 static void eac3_importer_cleanup( importer_t
*importer
)
351 debug_if( importer
&& importer
->info
)
352 remove_eac3_importer( importer
->info
);
355 static int eac3_importer_get_next_accessunit_internal( importer_t
*importer
)
357 int au_completed
= 0;
358 eac3_importer_t
*eac3_imp
= (eac3_importer_t
*)importer
->info
;
359 eac3_info_t
*info
= &eac3_imp
->info
;
360 lsmash_bs_t
*bs
= info
->bits
->bs
;
361 while( !au_completed
)
363 /* Read data from the stream if needed. */
364 eac3_imp
->next_frame_pos
+= info
->frame_size
;
365 lsmash_bs_read_seek( bs
, eac3_imp
->next_frame_pos
, SEEK_SET
);
366 uint64_t remain_size
= lsmash_bs_get_remaining_buffer_size( bs
);
367 if( remain_size
< EAC3_MAX_SYNCFRAME_LENGTH
)
369 int err
= lsmash_bs_read( bs
, bs
->buffer
.max_size
);
372 lsmash_log( importer
, LSMASH_LOG_ERROR
, "failed to read data from the stream.\n" );
375 remain_size
= lsmash_bs_get_remaining_buffer_size( bs
);
377 uint64_t copy_size
= LSMASH_MIN( remain_size
, EAC3_MAX_SYNCFRAME_LENGTH
);
378 memcpy( eac3_imp
->buffer
, lsmash_bs_get_buffer_data( bs
), copy_size
);
379 /* Check the remainder length of the buffer.
380 * If there is enough length, then parse the syncframe in it.
381 * The length 5 is the required byte length to get frame size. */
382 if( bs
->eob
|| (bs
->eof
&& remain_size
< 5) )
384 /* Reached the end of stream.
385 * According to ETSI TS 102 366 V1.2.1 (2008-08),
386 * one access unit consists of 6 audio blocks and begins with independent substream 0.
387 * The specification doesn't mention the case where a enhanced AC-3 stream ends at non-mod6 audio blocks.
388 * At the end of the stream, therefore, we might make an access unit which has less than 6 audio blocks anyway. */
389 importer
->status
= IMPORTER_EOF
;
390 au_completed
= !!eac3_imp
->incomplete_au_length
;
393 /* No more access units in the stream. */
394 if( lsmash_bs_get_remaining_buffer_size( bs
) )
396 lsmash_log( importer
, LSMASH_LOG_WARNING
, "the stream is truncated at the end.\n" );
397 return LSMASH_ERR_INVALID_DATA
;
401 if( !info
->dec3_param_initialized
)
402 eac3_update_specific_param( info
);
406 /* Check the syncword. */
407 if( lsmash_bs_show_byte( bs
, 0 ) != 0x0b
408 || lsmash_bs_show_byte( bs
, 1 ) != 0x77 )
410 lsmash_log( importer
, LSMASH_LOG_ERROR
, "a syncword is not found.\n" );
411 return LSMASH_ERR_INVALID_DATA
;
413 /* Parse syncframe. */
414 info
->frame_size
= 0;
415 int err
= eac3_parse_syncframe( info
);
418 lsmash_log( importer
, LSMASH_LOG_ERROR
, "failed to parse syncframe.\n" );
421 if( remain_size
< info
->frame_size
)
423 lsmash_log( importer
, LSMASH_LOG_ERROR
, "a frame is truncated.\n" );
424 return LSMASH_ERR_INVALID_DATA
;
426 int independent
= info
->strmtyp
!= 0x1;
427 if( independent
&& info
->substreamid
== 0x0 )
429 if( info
->number_of_audio_blocks
== 6 )
431 /* Encountered the first syncframe of the next access unit. */
432 info
->number_of_audio_blocks
= 0;
435 else if( info
->number_of_audio_blocks
> 6 )
437 lsmash_log( importer
, LSMASH_LOG_ERROR
, "greater than 6 consecutive independent substreams.\n" );
438 return LSMASH_ERR_INVALID_DATA
;
440 info
->number_of_audio_blocks
+= eac3_audio_block_table
[ info
->numblkscod
];
441 info
->number_of_independent_substreams
= 0;
442 eac3_imp
->current_fscod2
= info
->fscod2
;
444 else if( info
->syncframe_count
== 0 )
446 /* The first syncframe in an AU must be independent and assigned substream ID 0. */
447 lsmash_log( importer
, LSMASH_LOG_ERROR
, "the first syncframe is NOT an independent substream.\n" );
448 return LSMASH_ERR_INVALID_DATA
;
451 info
->independent_info
[info
->number_of_independent_substreams
++].num_dep_sub
= 0;
453 ++ info
->independent_info
[info
->number_of_independent_substreams
- 1].num_dep_sub
;
457 memcpy( eac3_imp
->au
, eac3_imp
->incomplete_au
, eac3_imp
->incomplete_au_length
);
458 eac3_imp
->au_length
= eac3_imp
->incomplete_au_length
;
459 eac3_imp
->incomplete_au_length
= 0;
460 eac3_imp
->syncframe_count_in_au
= info
->syncframe_count
;
461 info
->syncframe_count
= 0;
462 if( importer
->status
== IMPORTER_EOF
)
465 /* Increase buffer size to store AU if short. */
466 if( eac3_imp
->incomplete_au_length
+ info
->frame_size
> eac3_imp
->au_buffers
->buffer_size
)
468 lsmash_multiple_buffers_t
*temp
= lsmash_resize_multiple_buffers( eac3_imp
->au_buffers
,
469 eac3_imp
->au_buffers
->buffer_size
+ EAC3_MAX_SYNCFRAME_LENGTH
);
471 return LSMASH_ERR_MEMORY_ALLOC
;
472 eac3_imp
->au_buffers
= temp
;
473 eac3_imp
->au
= lsmash_withdraw_buffer( eac3_imp
->au_buffers
, 1 );
474 eac3_imp
->incomplete_au
= lsmash_withdraw_buffer( eac3_imp
->au_buffers
, 2 );
476 /* Append syncframe data. */
477 memcpy( eac3_imp
->incomplete_au
+ eac3_imp
->incomplete_au_length
, eac3_imp
->buffer
, info
->frame_size
);
478 eac3_imp
->incomplete_au_length
+= info
->frame_size
;
479 ++ info
->syncframe_count
;
481 return bs
->error
? LSMASH_ERR_NAMELESS
: 0;
484 static int eac3_importer_get_accessunit( importer_t
*importer
, uint32_t track_number
, lsmash_sample_t
**p_sample
)
486 if( !importer
->info
)
487 return LSMASH_ERR_NAMELESS
;
488 if( track_number
!= 1 )
489 return LSMASH_ERR_FUNCTION_PARAM
;
490 lsmash_audio_summary_t
*summary
= (lsmash_audio_summary_t
*)lsmash_get_entry_data( importer
->summaries
, track_number
);
492 return LSMASH_ERR_NAMELESS
;
493 eac3_importer_t
*eac3_imp
= (eac3_importer_t
*)importer
->info
;
494 eac3_info_t
*info
= &eac3_imp
->info
;
495 importer_status current_status
= importer
->status
;
496 if( current_status
== IMPORTER_ERROR
)
497 return LSMASH_ERR_NAMELESS
;
498 if( current_status
== IMPORTER_EOF
&& eac3_imp
->au_length
== 0 )
500 if( current_status
== IMPORTER_CHANGE
)
502 lsmash_codec_specific_t
*cs
= isom_get_codec_specific( summary
->opaque
, LSMASH_CODEC_SPECIFIC_DATA_TYPE_ISOM_AUDIO_EC_3
);
505 cs
->destruct( cs
->data
.unstructured
);
506 cs
->data
.unstructured
= eac3_imp
->next_dec3
;
507 cs
->size
= eac3_imp
->next_dec3_length
;
509 summary
->max_au_length
= eac3_imp
->syncframe_count_in_au
* EAC3_MAX_SYNCFRAME_LENGTH
;
510 eac3_update_sample_rate( &summary
->frequency
, &info
->dec3_param
, &eac3_imp
->current_fscod2
);
511 eac3_update_channel_count( &summary
->channels
, &info
->dec3_param
);
513 lsmash_sample_t
*sample
= lsmash_create_sample( eac3_imp
->au_length
);
515 return LSMASH_ERR_MEMORY_ALLOC
;
517 memcpy( sample
->data
, eac3_imp
->au
, eac3_imp
->au_length
);
518 sample
->length
= eac3_imp
->au_length
;
519 sample
->dts
= eac3_imp
->au_number
++ * summary
->samples_in_frame
;
520 sample
->cts
= sample
->dts
;
521 sample
->prop
.ra_flags
= ISOM_SAMPLE_RANDOM_ACCESS_FLAG_SYNC
;
522 sample
->prop
.pre_roll
.distance
= 1; /* MDCT */
523 if( importer
->status
== IMPORTER_EOF
)
525 eac3_imp
->au_length
= 0;
528 uint32_t old_syncframe_count_in_au
= eac3_imp
->syncframe_count_in_au
;
529 if( eac3_importer_get_next_accessunit_internal( importer
) < 0 )
531 importer
->status
= IMPORTER_ERROR
;
532 return current_status
;
534 if( eac3_imp
->syncframe_count_in_au
)
536 /* Check sample description change. */
538 uint8_t *dec3
= lsmash_create_eac3_specific_info( &info
->dec3_param
, &new_length
);
541 importer
->status
= IMPORTER_ERROR
;
542 return current_status
;
544 lsmash_codec_specific_t
*cs
= isom_get_codec_specific( summary
->opaque
, LSMASH_CODEC_SPECIFIC_DATA_TYPE_ISOM_AUDIO_EC_3
);
545 if( (eac3_imp
->syncframe_count_in_au
> old_syncframe_count_in_au
)
546 || (cs
&& (new_length
!= cs
->size
|| memcmp( dec3
, cs
->data
.unstructured
, cs
->size
))) )
548 importer
->status
= IMPORTER_CHANGE
;
549 eac3_imp
->next_dec3
= dec3
;
550 eac3_imp
->next_dec3_length
= new_length
;
554 if( importer
->status
!= IMPORTER_EOF
)
555 importer
->status
= IMPORTER_OK
;
559 return current_status
;
562 static lsmash_audio_summary_t
*eac3_create_summary( eac3_importer_t
*eac3_imp
)
564 lsmash_audio_summary_t
*summary
= (lsmash_audio_summary_t
*)lsmash_create_summary( LSMASH_SUMMARY_TYPE_AUDIO
);
567 eac3_info_t
*info
= &eac3_imp
->info
;
568 lsmash_codec_specific_t
*cs
= lsmash_create_codec_specific_data( LSMASH_CODEC_SPECIFIC_DATA_TYPE_ISOM_AUDIO_EC_3
,
569 LSMASH_CODEC_SPECIFIC_FORMAT_UNSTRUCTURED
);
570 cs
->data
.unstructured
= lsmash_create_eac3_specific_info( &info
->dec3_param
, &cs
->size
);
571 if( !cs
->data
.unstructured
572 || lsmash_add_entry( &summary
->opaque
->list
, cs
) < 0 )
574 lsmash_cleanup_summary( (lsmash_summary_t
*)summary
);
575 lsmash_destroy_codec_specific_data( cs
);
578 summary
->sample_type
= ISOM_CODEC_TYPE_EC_3_AUDIO
;
579 summary
->max_au_length
= eac3_imp
->syncframe_count_in_au
* EAC3_MAX_SYNCFRAME_LENGTH
;
580 summary
->aot
= MP4A_AUDIO_OBJECT_TYPE_NULL
; /* no effect */
581 summary
->sample_size
= 16; /* no effect */
582 summary
->samples_in_frame
= EAC3_MIN_SAMPLE_DURATION
* 6; /* 256 (samples per audio block) * 6 (audio blocks) */
583 summary
->sbr_mode
= MP4A_AAC_SBR_NOT_SPECIFIED
; /* no effect */
584 eac3_update_sample_rate( &summary
->frequency
, &info
->dec3_param
, &eac3_imp
->current_fscod2
);
585 eac3_update_channel_count( &summary
->channels
, &info
->dec3_param
);
589 static int eac3_importer_probe( importer_t
*importer
)
591 eac3_importer_t
*eac3_imp
= create_eac3_importer( importer
);
593 return LSMASH_ERR_MEMORY_ALLOC
;
594 lsmash_bits_t
*bits
= eac3_imp
->info
.bits
;
595 lsmash_bs_t
*bs
= bits
->bs
;
596 bs
->buffer
.max_size
= EAC3_MAX_SYNCFRAME_LENGTH
;
597 importer
->info
= eac3_imp
;
598 int err
= eac3_importer_get_next_accessunit_internal( importer
);
601 lsmash_audio_summary_t
*summary
= eac3_create_summary( eac3_imp
);
604 err
= LSMASH_ERR_NAMELESS
;
607 if( importer
->status
!= IMPORTER_EOF
)
608 importer
->status
= IMPORTER_OK
;
609 eac3_imp
->au_number
= 0;
610 if( lsmash_add_entry( importer
->summaries
, summary
) < 0 )
612 lsmash_cleanup_summary( (lsmash_summary_t
*)summary
);
613 err
= LSMASH_ERR_MEMORY_ALLOC
;
618 remove_eac3_importer( eac3_imp
);
619 importer
->info
= NULL
;
623 static uint32_t eac3_importer_get_last_delta( importer_t
*importer
, uint32_t track_number
)
625 debug_if( !importer
|| !importer
->info
)
627 eac3_importer_t
*eac3_imp
= (eac3_importer_t
*)importer
->info
;
628 if( !eac3_imp
|| track_number
!= 1 || importer
->status
!= IMPORTER_EOF
|| eac3_imp
->au_length
)
630 return EAC3_MIN_SAMPLE_DURATION
* eac3_imp
->info
.number_of_audio_blocks
;
633 const importer_functions eac3_importer
=
635 { "Enhanced AC-3", offsetof( importer_t
, log_level
) },
638 eac3_importer_get_accessunit
,
639 eac3_importer_get_last_delta
,
640 eac3_importer_cleanup