diff options
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/bd.c | 5 | ||||
-rw-r--r-- | libhb/common.h | 2 | ||||
-rw-r--r-- | libhb/decdca.c | 432 | ||||
-rw-r--r-- | libhb/dvd.c | 1 | ||||
-rw-r--r-- | libhb/dvdnav.c | 1 | ||||
-rw-r--r-- | libhb/hb.c | 2 | ||||
-rw-r--r-- | libhb/internal.h | 1 | ||||
-rw-r--r-- | libhb/module.defs | 2 | ||||
-rw-r--r-- | libhb/scan.c | 1 | ||||
-rw-r--r-- | libhb/stream.c | 24 | ||||
-rw-r--r-- | libhb/work.c | 7 |
11 files changed, 19 insertions, 459 deletions
diff --git a/libhb/bd.c b/libhb/bd.c index a5dd53887..8ec0fcb49 100644 --- a/libhb/bd.c +++ b/libhb/bd.c @@ -426,7 +426,8 @@ hb_title_t * hb_bd_title_scan( hb_bd_t * d, int tt, uint64_t min_duration ) break; case BLURAY_STREAM_TYPE_AUDIO_DTS: - add_audio(ii, title->list_audio, bdaudio, 0, HB_ACODEC_DCA, 0); + add_audio(ii, title->list_audio, bdaudio, 0, HB_ACODEC_DCA, + CODEC_ID_DTS); break; case BLURAY_STREAM_TYPE_AUDIO_MPEG2: @@ -453,7 +454,7 @@ hb_title_t * hb_bd_title_scan( hb_bd_t * d, int tt, uint64_t min_duration ) case BLURAY_STREAM_TYPE_AUDIO_DTSHD: // Add 2 audio tracks. One for DTS-HD and one for DTS add_audio(ii, title->list_audio, bdaudio, HB_SUBSTREAM_BD_DTS, - HB_ACODEC_DCA, 0); + HB_ACODEC_DCA, CODEC_ID_DTS); // DTS-HD is special. The substreams must be concatinated // DTS-core followed by DTS-hd-extensions. Setting // a substream id of 0 says use all substreams. diff --git a/libhb/common.h b/libhb/common.h index 99aae30a1..eea705c1e 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -408,7 +408,7 @@ struct hb_job_s #define HB_ACODEC_DCA_HD 0x00040000 #define HB_ACODEC_MP3 0x00080000 #define HB_ACODEC_FFFLAC 0x00100000 -#define HB_ACODEC_FF_MASK 0x001f0000 +#define HB_ACODEC_FF_MASK 0x001f2000 #define HB_ACODEC_PASS_FLAG 0x40000000 #define HB_ACODEC_PASS_MASK (HB_ACODEC_MP3 | HB_ACODEC_FFAAC | HB_ACODEC_DCA_HD | HB_ACODEC_AC3 | HB_ACODEC_DCA) #define HB_ACODEC_AUTO_PASS (HB_ACODEC_PASS_MASK | HB_ACODEC_PASS_FLAG) diff --git a/libhb/decdca.c b/libhb/decdca.c deleted file mode 100644 index 17d0e7755..000000000 --- a/libhb/decdca.c +++ /dev/null @@ -1,432 +0,0 @@ -/* decdca.c - - Copyright (c) 2003-2012 HandBrake Team - This file is part of the HandBrake source code - Homepage: <http://handbrake.fr/>. - It may be used under the terms of the GNU General Public License v2. - For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html - */ - -#include "hb.h" -#include "audio_remap.h" - -#include "dca.h" - -struct hb_work_private_s -{ - hb_job_t * job; - - /* libdca handle */ - dca_state_t * state; - - double next_pts; - int64_t last_buf_pts; - int flags_in; - int flags_out; - int rate; - int bitrate; - int frame_length; - float level; - - int error; - int sync; - int size; - - /* max frame size of the 16 bits version is 16384 */ - /* max frame size of the 14 bits version is 18726 */ - uint8_t frame[18726]; - - hb_list_t * list; - - int out_discrete_channels; - -}; - -static int decdcaInit( hb_work_object_t *, hb_job_t * ); -static int decdcaWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** ); -static void decdcaClose( hb_work_object_t * ); -static int decdcaBSInfo( hb_work_object_t *, const hb_buffer_t *, - hb_work_info_t * ); - -hb_work_object_t hb_decdca = -{ - WORK_DECDCA, - "DCA decoder", - decdcaInit, - decdcaWork, - decdcaClose, - 0, - decdcaBSInfo -}; - -/*********************************************************************** - * Local prototypes - **********************************************************************/ -static hb_buffer_t * Decode( hb_work_object_t * w ); - -/*********************************************************************** - * hb_work_decdca_init - *********************************************************************** - * Allocate the work object, initialize libdca - **********************************************************************/ -static int decdcaInit( hb_work_object_t * w, hb_job_t * job ) -{ - hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) ); - hb_audio_t * audio = w->audio; - w->private_data = pv; - - pv->job = job; - - pv->list = hb_list_init(); - pv->state = dca_init( 0 ); - pv->level = 1.0; - - /* Decide what format we want out of libdca; - * work.c has already done some of this deduction for us in do_job(). - * Dolby Surround and Pro Logic II are a bit tricky. */ - int layout = (audio->config.in.channel_layout & ~AV_CH_LOW_FREQUENCY); - switch (audio->config.out.mixdown) - { - case HB_AMIXDOWN_6CH: - pv->flags_out = (DCA_3F2R|DCA_LFE); - break; - - case HB_AMIXDOWN_DOLBYPLII: - { - if (layout == AV_CH_LAYOUT_5POINT0) - { - // Dolby Pro Logic II output is supported - pv->flags_out = (DCA_3F2R|DCA_OUT_DPLII); - } - else if (layout == AV_CH_LAYOUT_4POINT0) - { - // Dolby Surround output and DCA_3F1R downmix are supported - pv->flags_out = (DCA_3F1R|DCA_OUT_DPLI); - } - else if (layout == AV_CH_LAYOUT_STEREO || - layout == AV_CH_LAYOUT_STEREO_DOWNMIX) - { - // Dolby Surround output not supported OR - // Dolby Surround input just gets passed through as is - pv->flags_out = DCA_STEREO; - } - else - { - // Dolby Surround output is supported, but DCA_3F1R downmix isn't - pv->flags_out = DCA_DOLBY; - } - } break; - - case HB_AMIXDOWN_DOLBY: - { - if (layout == AV_CH_LAYOUT_5POINT0 || layout == AV_CH_LAYOUT_4POINT0) - { - // Dolby Surround output and DCA_3F1R downmix are supported - pv->flags_out = (DCA_3F1R|DCA_OUT_DPLI); - } - else if (layout == AV_CH_LAYOUT_STEREO || - layout == AV_CH_LAYOUT_STEREO_DOWNMIX) - { - // Dolby Surround output not supported OR - // Dolby Surround input just gets passed through as is - pv->flags_out = DCA_STEREO; - } - else - { - // Dolby Surround output is supported, but DCA_3F1R downmix isn't - pv->flags_out = DCA_DOLBY; - } - } break; - - case HB_AMIXDOWN_MONO: - pv->flags_out = DCA_MONO; - break; - - default: - pv->flags_out = DCA_STEREO; - break; - } - - /* pass the number of channels used into the private work data */ - pv->out_discrete_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown ); - - return 0; -} - -/*********************************************************************** - * Close - *********************************************************************** - * Free memory - **********************************************************************/ -static void decdcaClose( hb_work_object_t * w ) -{ - hb_work_private_t * pv = w->private_data; - dca_free( pv->state ); - hb_list_empty( &pv->list ); - free( pv ); - w->private_data = NULL; -} - -/*********************************************************************** - * Work - *********************************************************************** - * Add the given buffer to the data we already have, and decode as much - * as we can - **********************************************************************/ -static int decdcaWork( hb_work_object_t * w, hb_buffer_t ** buf_in, - hb_buffer_t ** buf_out ) -{ - hb_work_private_t * pv = w->private_data; - hb_buffer_t * buf; - - if ( (*buf_in)->size <= 0 ) - { - /* EOF on input stream - send it downstream & say that we're done */ - *buf_out = *buf_in; - *buf_in = NULL; - return HB_WORK_DONE; - } - - if ( (*buf_in)->s.start < -1 && pv->next_pts == 0 ) - { - // discard buffers that start before video time 0 - *buf_out = NULL; - return HB_WORK_OK; - } - - hb_list_add( pv->list, *buf_in ); - *buf_in = NULL; - - /* If we got more than a frame, chain raw buffers */ - *buf_out = buf = Decode( w ); - while( buf ) - { - buf->next = Decode( w ); - buf = buf->next; - } - - return HB_WORK_OK; -} - -/*********************************************************************** - * Decode - *********************************************************************** - * - **********************************************************************/ -static hb_buffer_t * Decode( hb_work_object_t * w ) -{ - hb_work_private_t * pv = w->private_data; - hb_buffer_t * buf; - hb_audio_t * audio = w->audio; - int i, j, k; - int64_t pts; - uint64_t upts, upos; - int num_blocks; - - /* Get a frame header if don't have one yet */ - if( !pv->sync ) - { - while( hb_list_bytes( pv->list ) >= 14 ) - { - /* We have 14 bytes, check if this is a correct header */ - hb_list_seebytes( pv->list, pv->frame, 14 ); - pv->size = dca_syncinfo( pv->state, pv->frame, &pv->flags_in, &pv->rate, - &pv->bitrate, &pv->frame_length ); - if( pv->size ) - { - /* It is. W00t. */ - if( pv->error ) - { - hb_log( "dca_syncinfo ok" ); - } - pv->error = 0; - pv->sync = 1; - break; - } - - /* It is not */ - if( !pv->error ) - { - hb_log( "dca_syncinfo failed" ); - pv->error = 1; - } - - /* Try one byte later */ - hb_list_getbytes( pv->list, pv->frame, 1, NULL, NULL ); - } - } - - if( !pv->sync || hb_list_bytes( pv->list ) < pv->size ) - { - /* Need more data */ - return NULL; - } - - /* Get the whole frame */ - hb_list_getbytes( pv->list, pv->frame, pv->size, &upts, &upos ); - pts = (int64_t)upts; - - if ( pts != pv->last_buf_pts ) - { - pv->last_buf_pts = pts; - } - else - { - // spec says that the PTS is the start time of the first frame - // that starts in the PES frame so we only use the PTS once then - // get the following frames' PTS from the frame length. - pts = -1; - } - - // mkv files typically use a 1ms timebase which results in a lot of - // truncation error in their timestamps. Also, TSMuxer or something - // in the m2ts-to-mkv toolchain seems to take a very casual attitude - // about time - timestamps seem to randomly offset by ~40ms for a few - // seconds then recover. So, if the pts we got is within 50ms of the - // pts computed from the data stream, use the data stream pts. - if ( pts == -1 || ( pv->next_pts && fabs( pts - pv->next_pts ) < 50.*90. ) ) - { - pts = pv->next_pts; - } - - double frame_dur = (double)(pv->frame_length & ~0xFF) / (double)pv->rate * 90000.; - - /* DCA passthrough: don't decode the DCA frame */ - if( audio->config.out.codec == HB_ACODEC_DCA_PASS ) - { - buf = hb_buffer_init( pv->size ); - memcpy( buf->data, pv->frame, pv->size ); - buf->s.start = pts; - buf->s.duration = frame_dur; - pv->next_pts = pts + frame_dur; - buf->s.stop = pv->next_pts; - pv->sync = 0; - return buf; - } - - /* Feed libdca */ - dca_frame( pv->state, pv->frame, &pv->flags_out, &pv->level, 0 ); - - /* find out how many blocks are in this frame */ - num_blocks = dca_blocks_num( pv->state ); - - /* num_blocks blocks per frame, 256 samples per block, channelsused channels */ - int nsamp = num_blocks * 256; - frame_dur = (double)nsamp / (double)pv->rate * 90000.; - buf = hb_buffer_init( nsamp * pv->out_discrete_channels * sizeof( float ) ); - - buf->s.start = pts; - buf->s.duration = frame_dur; - pv->next_pts = pts + frame_dur; - buf->s.stop = pv->next_pts; - - for( i = 0; i < num_blocks; i++ ) - { - dca_sample_t * samples_in; - float * samples_out; - - dca_block( pv->state ); - samples_in = dca_samples( pv->state ); - samples_out = ((float *) buf->data) + 256 * pv->out_discrete_channels * i; - - /* Interleave */ - for( j = 0; j < 256; j++ ) - { - for ( k = 0; k < pv->out_discrete_channels; k++ ) - { - samples_out[(pv->out_discrete_channels*j)+k] = samples_in[(256*k)+j]; - } - } - - } - - pv->sync = 0; - return buf; -} - - -static int decdcaBSInfo( hb_work_object_t *w, const hb_buffer_t *b, - hb_work_info_t *info ) -{ - int i, flags, rate, bitrate, frame_length; - dca_state_t * state = dca_init( 0 ); - - memset( info, 0, sizeof(*info) ); - - /* since DCA frames don't line up with MPEG ES frames scan the - * entire frame for an DCA sync pattern. */ - for ( i = 0; i < b->size - 7; ++i ) - { - if( dca_syncinfo( state, &b->data[i], &flags, &rate, &bitrate, - &frame_length ) ) - { - break; - } - } - if ( i >= b->size - 7 ) - { - /* didn't find DCA sync */ - dca_free( state ); - return 0; - } - - info->name = "DCA"; - info->rate = rate; - info->rate_base = 1; - info->bitrate = bitrate; - info->flags = flags; - info->samples_per_frame = frame_length; - - switch( flags & DCA_CHANNEL_MASK ) - { - /* mono sources */ - case DCA_MONO: - info->channel_layout = AV_CH_LAYOUT_MONO; - break; - /* stereo input */ - case DCA_CHANNEL: - case DCA_STEREO: - case DCA_STEREO_SUMDIFF: - case DCA_STEREO_TOTAL: - info->channel_layout = AV_CH_LAYOUT_STEREO; - break; - /* Dolby Pro Logic (a.k.a. Dolby Surround), 4.0 channels (matrix-encoded) */ - case DCA_DOLBY: - info->channel_layout = AV_CH_LAYOUT_STEREO_DOWNMIX; - break; - /* 3F/2R input */ - case DCA_3F2R: - info->channel_layout = AV_CH_LAYOUT_5POINT0; - break; - /* 3F/1R input */ - case DCA_3F1R: - info->channel_layout = AV_CH_LAYOUT_4POINT0; - break; - /* other inputs */ - case DCA_3F: - info->channel_layout = AV_CH_LAYOUT_SURROUND; - break; - case DCA_2F1R: - info->channel_layout = AV_CH_LAYOUT_2_1; - break; - case DCA_2F2R: - info->channel_layout = AV_CH_LAYOUT_2_2; - break; - case DCA_4F2R: - info->channel_layout = AV_CH_LAYOUT_2_2|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER; - break; - /* unknown */ - default: - info->channel_layout = AV_CH_LAYOUT_STEREO; - } - - if (flags & DCA_LFE) - { - info->channel_layout |= AV_CH_LOW_FREQUENCY; - } - - info->channel_map = &hb_libdca_chan_map; - - dca_free( state ); - return 1; -} diff --git a/libhb/dvd.c b/libhb/dvd.c index 6af2e7908..df0fd1829 100644 --- a/libhb/dvd.c +++ b/libhb/dvd.c @@ -376,6 +376,7 @@ static hb_title_t * hb_dvdread_title_scan( hb_dvd_t * e, int t, uint64_t min_dur case 0x06: audio->id = ( ( 0x88 + position ) << 8 ) | 0xbd; audio->config.in.codec = HB_ACODEC_DCA; + audio->config.in.codec_param = CODEC_ID_DTS; codec_name = "DTS"; break; diff --git a/libhb/dvdnav.c b/libhb/dvdnav.c index d6e97c1a5..436147a4d 100644 --- a/libhb/dvdnav.c +++ b/libhb/dvdnav.c @@ -525,6 +525,7 @@ static hb_title_t * hb_dvdnav_title_scan( hb_dvd_t * e, int t, uint64_t min_dura case 0x06: audio->id = ( ( 0x88 + position ) << 8 ) | 0xbd; audio->config.in.codec = HB_ACODEC_DCA; + audio->config.in.codec_param = CODEC_ID_DTS; codec_name = "DTS"; break; diff --git a/libhb/hb.c b/libhb/hb.c index c6b569caf..ef3f15edf 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -448,7 +448,6 @@ hb_handle_t * hb_init( int verbose, int update_check ) hb_register( &hb_encx264 ); hb_register( &hb_enctheora ); hb_register( &hb_deca52 ); - hb_register( &hb_decdca ); hb_register( &hb_decavcodeca ); hb_register( &hb_decavcodecv ); hb_register( &hb_declpcm ); @@ -547,7 +546,6 @@ hb_handle_t * hb_init_dl( int verbose, int update_check ) hb_register( &hb_encx264 ); hb_register( &hb_enctheora ); hb_register( &hb_deca52 ); - hb_register( &hb_decdca ); hb_register( &hb_decavcodeca ); hb_register( &hb_decavcodecv ); hb_register( &hb_declpcm ); diff --git a/libhb/internal.h b/libhb/internal.h index 577f6671e..9ca207d60 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -406,7 +406,6 @@ enum WORK_ENCX264, WORK_ENCTHEORA, WORK_DECA52, - WORK_DECDCA, WORK_DECAVCODEC, WORK_DECAVCODECV, WORK_DECLPCM, diff --git a/libhb/module.defs b/libhb/module.defs index 63acb9b9d..022d30621 100644 --- a/libhb/module.defs +++ b/libhb/module.defs @@ -92,7 +92,7 @@ LIBHB.dll = $(LIBHB.build/)hb.dll LIBHB.lib = $(LIBHB.build/)hb.lib LIBHB.dll.libs = $(foreach n, \ - a52 ass avcodec avformat avutil avresample dca dvdnav dvdread faac fontconfig freetype mkv mpeg2 mp3lame mp4v2 \ + a52 ass avcodec avformat avutil avresample dvdnav dvdread faac fontconfig freetype mkv mpeg2 mp3lame mp4v2 \ ogg samplerate swscale theora vorbis vorbisenc x264 xml2 bluray, \ $(CONTRIB.build/)lib/lib$(n).a ) diff --git a/libhb/scan.c b/libhb/scan.c index 4776e08c4..10ed35391 100644 --- a/libhb/scan.c +++ b/libhb/scan.c @@ -10,7 +10,6 @@ #include "hb.h" #include "hbffmpeg.h" #include "a52dec/a52.h" -#include "dca.h" typedef struct { diff --git a/libhb/stream.c b/libhb/stream.c index 4c9cb347c..27e753f0f 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -73,7 +73,7 @@ static const stream2codec_t st2codec[256] = { st(0x80, U, HB_ACODEC_FFMPEG, CODEC_ID_PCM_BLURAY, "Digicipher II Video"), st(0x81, A, HB_ACODEC_AC3, 0, "AC3"), - st(0x82, A, HB_ACODEC_DCA, 0, "DTS"), + st(0x82, A, HB_ACODEC_DCA, CODEC_ID_DTS, "DTS"), // 0x83 can be LPCM or BD TrueHD. Set to 'unknown' till we know more. st(0x83, U, HB_ACODEC_LPCM, 0, "LPCM"), // BD E-AC3 Primary audio @@ -83,7 +83,7 @@ static const stream2codec_t st2codec[256] = { st(0x86, U, HB_ACODEC_DCA_HD, CODEC_ID_DTS, "DTS-HD MA"), st(0x87, A, HB_ACODEC_FFMPEG, CODEC_ID_EAC3, "E-AC3"), - st(0x8a, A, HB_ACODEC_DCA, 0, "DTS"), + st(0x8a, A, HB_ACODEC_DCA, CODEC_ID_DTS, "DTS"), st(0x90, S, WORK_DECPGSSUB, 0, "PGS Subtitle"), // 0x91 can be AC3 or BD Interactive Graphics Stream. @@ -4067,8 +4067,6 @@ static int probe_dts_profile( hb_pes_stream_t *pes ) } switch (info.profile) { - /* When we improve handling of channels > 5.1, we should move - * DTS_ES down to use libav for decode */ case FF_PROFILE_DTS: case FF_PROFILE_DTS_ES: case FF_PROFILE_DTS_96_24: @@ -4306,6 +4304,7 @@ static void hb_ts_resolve_pid_types(hb_stream_t *stream) update_ts_streams( stream, pid, HB_SUBSTREAM_BD_DTS, stype, A, &pes_idx ); stream->pes.list[pes_idx].codec = HB_ACODEC_DCA; + stream->pes.list[pes_idx].codec_param = CODEC_ID_DTS; update_ts_streams( stream, pid, 0, stype, A, &pes_idx ); stream->pes.list[pes_idx].codec = HB_ACODEC_DCA_HD; @@ -4320,6 +4319,7 @@ static void hb_ts_resolve_pid_types(hb_stream_t *stream) update_ts_streams( stream, pid, HB_SUBSTREAM_BD_DTS, stype, A, &pes_idx ); stream->pes.list[pes_idx].codec = HB_ACODEC_DCA; + stream->pes.list[pes_idx].codec_param = CODEC_ID_DTS; update_ts_streams( stream, pid, 0, stype, A, &pes_idx ); stream->pes.list[pes_idx].codec = HB_ACODEC_DCA_HD; @@ -5116,18 +5116,16 @@ static void add_ffmpeg_audio( hb_title_t *title, hb_stream_t *stream, int id ) { audio->config.in.codec = HB_ACODEC_AC3; } - /* When we improve handling of channels > 5.1, we should move - * DTS_ES down to use libav for decode */ - else if ( codec->codec_id == CODEC_ID_DTS && - ( codec->profile == FF_PROFILE_DTS || - codec->profile == FF_PROFILE_DTS_ES || - codec->profile == FF_PROFILE_DTS_96_24 ) ) - { - audio->config.in.codec = HB_ACODEC_DCA; - } else { if ( codec->codec_id == CODEC_ID_DTS && + ( codec->profile == FF_PROFILE_DTS || + codec->profile == FF_PROFILE_DTS_ES || + codec->profile == FF_PROFILE_DTS_96_24 ) ) + { + audio->config.in.codec = HB_ACODEC_DCA; + } + else if ( codec->codec_id == CODEC_ID_DTS && ( codec->profile == FF_PROFILE_DTS_HD_MA || codec->profile == FF_PROFILE_DTS_HD_HRA ) ) { diff --git a/libhb/work.c b/libhb/work.c index 62d63ee3b..f0e128b92 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -9,7 +9,6 @@ #include "hb.h" #include "a52dec/a52.h" -#include "dca.h" #include "libavformat/avformat.h" typedef struct @@ -117,7 +116,6 @@ hb_work_object_t * hb_codec_decoder( int codec ) switch( codec ) { case HB_ACODEC_AC3: return hb_get_work( WORK_DECA52 ); - case HB_ACODEC_DCA: return hb_get_work( WORK_DECDCA ); case HB_ACODEC_LPCM: return hb_get_work( WORK_DECLPCM ); default: if ( codec & HB_ACODEC_FF_MASK ) @@ -438,10 +436,7 @@ void hb_display_job_info( hb_job_t * job ) hb_log( " + decoder: %s (track %d, id 0x%x)", audio->config.lang.description, audio->config.in.track + 1, audio->id ); - if( ( audio->config.in.codec == HB_ACODEC_AC3 ) || ( audio->config.in.codec == HB_ACODEC_DCA) ) - { - hb_log( " + bitrate: %d kbps, samplerate: %d Hz", audio->config.in.bitrate / 1000, audio->config.in.samplerate ); - } + hb_log( " + bitrate: %d kbps, samplerate: %d Hz", audio->config.in.bitrate / 1000, audio->config.in.samplerate ); if( audio->config.out.codec & HB_ACODEC_PASS_FLAG ) { |