Skip to content

Commit

Permalink
libhb: drop HB_INPUT_CH_LAYOUT_*
Browse files Browse the repository at this point in the history
AV_CH_LAYOUT_* works for us, and as its usage becomes more widespread in libhb, translating between the two formats gets increasingly tedious.



git-svn-id: svn://localhost/HandBrake/trunk@4754 b64f7644-9d1e-0410-96f1-a4d463321fa5
  • Loading branch information
Rodeo authored and Rodeo committed Jun 18, 2012
1 parent 93e698f commit b921399
Show file tree
Hide file tree
Showing 22 changed files with 267 additions and 340 deletions.
12 changes: 6 additions & 6 deletions gtk/configure.ac
Expand Up @@ -36,21 +36,21 @@ AC_ARG_WITH(hb,
if test $hb_PATHSET = 1 ; then
case ${with_hb} in
/*)
CXXFLAGS="$CXXFLAGS -I$with_hb/libhb"
CFLAGS="$CFLAGS -I$with_hb/libhb"
CXXFLAGS="$CXXFLAGS -I$with_hb/libhb -I$with_hb/contrib/include"
CFLAGS="$CFLAGS -I$with_hb/libhb -I$with_hb/contrib/include"
LDFLAGS="$LDFLAGS -L$with_hb/libhb -L$with_hb/contrib/lib"
AC_SUBST(HB_DIR, "$with_hb")
;;
*)
CXXFLAGS="$CXXFLAGS "'-I$(top_srcdir)/'"$with_hb/libhb"
CFLAGS="$CFLAGS "'-I$(top_srcdir)/'"$with_hb/libhb"
CXXFLAGS="$CXXFLAGS "'-I$(top_srcdir)/'"$with_hb/libhb "'-I$(top_srcdir)/'"$with_hb/contrib/include"
CFLAGS="$CXXFLAGS "'-I$(top_srcdir)/'"$with_hb/libhb "'-I$(top_srcdir)/'"$with_hb/contrib/include"
LDFLAGS="$LDFLAGS "'-L$(top_srcdir)/'"$with_hb/libhb "'-L$(top_srcdir)/'"$with_hb/contrib/lib"
AC_SUBST(HB_DIR, '$(top_srcdir)/'"$with_hb")
;;
esac
else
CXXFLAGS="$CXXFLAGS "'-I$(top_srcdir)/'"../libhb"
CFLAGS="$CFLAGS "'-I$(top_srcdir)/'"../libhb"
CXXFLAGS="$CXXFLAGS "'-I$(top_srcdir)/'"../libhb "'-I$(top_srcdir)/'"../contrib/include"
CFLAGS="$CXXFLAGS "'-I$(top_srcdir)/'"../libhb "'-I$(top_srcdir)/'"../contrib/include"
LDFLAGS="$LDFLAGS "'-L$(top_srcdir)/'"../libhb "'-L$(top_srcdir)/'"../contrib/lib"
AC_SUBST(HB_DIR, '$(top_srcdir)/'"..")
fi
Expand Down
11 changes: 5 additions & 6 deletions gtk/src/hb-backend.c
Expand Up @@ -1702,8 +1702,7 @@ gint
ghb_get_best_mix(hb_audio_config_t *aconfig, gint acodec, gint mix)
{
gint layout;
layout = aconfig ? aconfig->in.channel_layout :
HB_INPUT_CH_LAYOUT_3F2R | HB_INPUT_CH_LAYOUT_HAS_LFE;
layout = aconfig ? aconfig->in.channel_layout : AV_CH_LAYOUT_5POINT1;
return hb_get_best_mixdown( acodec, layout, mix );
}

Expand Down Expand Up @@ -2438,7 +2437,7 @@ ghb_find_audio_track(
if (used[ii])
continue;

channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
channels = av_get_channel_layout_nb_channels(
audio->in.channel_layout);
// Find a track that is not visually impaired or dirctor's
// commentary, and has the highest channel count.
Expand Down Expand Up @@ -2482,7 +2481,7 @@ ghb_find_audio_track(
if (passthru_used[ii])
continue;
}
channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
channels = av_get_channel_layout_nb_channels(
audio->in.channel_layout);
// Find a track that is not visually impaired or dirctor's commentary
if ((audio->lang.type < 2) &&
Expand Down Expand Up @@ -2519,7 +2518,7 @@ ghb_find_audio_track(
if (used[ii])
continue;

channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
channels = av_get_channel_layout_nb_channels(
audio->in.channel_layout);
// Find a track that is not visually impaired or dirctor's
// commentary, and has the highest channel count.
Expand Down Expand Up @@ -2554,7 +2553,7 @@ ghb_find_audio_track(
audio = (hb_audio_config_t*)hb_list_audio_config_item(
title->list_audio, ii );
passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
channels = av_get_channel_layout_nb_channels(
audio->in.channel_layout);
if (passthru_acodec && passthru)
{
Expand Down
30 changes: 14 additions & 16 deletions libhb/common.c
Expand Up @@ -720,37 +720,35 @@ int hb_get_best_mixdown( uint32_t codec, int layout, int mixdown )
// Audio pass-thru. No mixdown.
return HB_AMIXDOWN_NONE;
}
switch (layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK)
switch (layout & ~AV_CH_LOW_FREQUENCY)
{
// mono input
case HB_INPUT_CH_LAYOUT_MONO:
case AV_CH_LAYOUT_MONO:
best_mixdown = HB_AMIXDOWN_MONO;
break;

// Dolby Pro Logic (a.k.a. Dolby Surround), 4.0 channels (matrix-encoded)
// The A52 flags don't allow for a way to distinguish between DPL1 and
// DPL2 on a DVD so we always assume a DPL1 source for A52_DOLBY.
case HB_INPUT_CH_LAYOUT_DOLBY:
case AV_CH_LAYOUT_STEREO_DOWNMIX:
// 3 or 4 discrete channels
// case HB_INPUT_CH_LAYOUT_3F: // FIXME: can it be downmixed to Dolby?
// case HB_INPUT_CH_LAYOUT_2F1R: // FIXME: can it be downmixed to Dolby?
case HB_INPUT_CH_LAYOUT_2F2R:
case HB_INPUT_CH_LAYOUT_3F1R:
// a52dec and libdca can't upmix to 6ch,
// so we must downmix these.
// libdca only supports DPLII if the source is 3F2R to begin with
case AV_CH_LAYOUT_2_1:
case AV_CH_LAYOUT_2_2:
case AV_CH_LAYOUT_QUAD:
case AV_CH_LAYOUT_4POINT0:
case AV_CH_LAYOUT_SURROUND:
// a52dec and libdca can't upmix to 6ch, so we must downmix these.
// libdca only supports DPLII if the source is 3F2R to begin with.
best_mixdown = HB_AMIXDOWN_DOLBY;
break;

// 5 to 8 discrete channels
case HB_INPUT_CH_LAYOUT_4F2R:
case HB_INPUT_CH_LAYOUT_3F4R:
case HB_INPUT_CH_LAYOUT_3F2R:
if (!(layout & HB_INPUT_CH_LAYOUT_HAS_LFE))
case AV_CH_LAYOUT_5POINT0:
case AV_CH_LAYOUT_7POINT0:
if (!(layout & AV_CH_LOW_FREQUENCY))
{
// we don't do 5-channel discrete
// a52dec and libdca can't upmix to 6ch,
// so we must downmix this.
// a52dec and libdca can't upmix to 6ch, so we must downmix this.
best_mixdown = HB_AMIXDOWN_DOLBYPLII;
}
else
Expand Down
56 changes: 16 additions & 40 deletions libhb/common.h
Expand Up @@ -20,6 +20,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include "libavutil/audioconvert.h"

/*
* It seems WinXP doesn't align the stack of new threads to 16 bytes.
Expand Down Expand Up @@ -423,34 +424,6 @@ struct hb_job_s
#define HB_SUBSTREAM_BD_DTSHD 0x72
#define HB_SUBSTREAM_BD_DTS 0x71

/* Input Channel Layout */
/* define some masks, used to extract the various information from the HB_INPUT_CH_LAYOUT_* values */
#define HB_INPUT_CH_LAYOUT_DISCRETE_FRONT_MASK 0x00F0000
#define HB_INPUT_CH_LAYOUT_DISCRETE_REAR_MASK 0x000F000
#define HB_INPUT_CH_LAYOUT_DISCRETE_LFE_MASK 0x0000F00
#define HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK 0xFFFF0FF
#define HB_INPUT_CH_LAYOUT_ENCODED_FRONT_MASK 0x00000F0
#define HB_INPUT_CH_LAYOUT_ENCODED_REAR_MASK 0x000000F
/* define the input channel layouts used to describe the channel layout of this audio */
#define HB_INPUT_CH_LAYOUT_MONO 0x0110010
#define HB_INPUT_CH_LAYOUT_STEREO 0x0220020
#define HB_INPUT_CH_LAYOUT_DOLBY 0x0320031
#define HB_INPUT_CH_LAYOUT_3F 0x0430030
#define HB_INPUT_CH_LAYOUT_2F1R 0x0521021
#define HB_INPUT_CH_LAYOUT_3F1R 0x0631031
#define HB_INPUT_CH_LAYOUT_2F2R 0x0722022
#define HB_INPUT_CH_LAYOUT_3F2R 0x0832032
#define HB_INPUT_CH_LAYOUT_4F2R 0x0942042
#define HB_INPUT_CH_LAYOUT_3F4R 0x0a34034
#define HB_INPUT_CH_LAYOUT_HAS_LFE 0x0000100
/* define some macros to extract the various information from the HB_INPUT_CH_LAYOUT_* values */
#define HB_INPUT_CH_LAYOUT_GET_DISCRETE_FRONT_COUNT( a ) ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_FRONT_MASK ) >> 16 )
#define HB_INPUT_CH_LAYOUT_GET_DISCRETE_REAR_COUNT( a ) ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_REAR_MASK ) >> 12 )
#define HB_INPUT_CH_LAYOUT_GET_DISCRETE_LFE_COUNT( a ) ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_LFE_MASK ) >> 8 )
#define HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT( a ) ( ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_FRONT_MASK ) >> 16 ) + ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_REAR_MASK ) >> 12 ) + ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_LFE_MASK ) >> 8 ) )
#define HB_INPUT_CH_LAYOUT_GET_ENCODED_FRONT_COUNT( a ) ( ( a & HB_INPUT_CH_LAYOUT_ENCODED_FRONT_MASK ) >> 4 )
#define HB_INPUT_CH_LAYOUT_GET_ENCODED_REAR_COUNT( a ) ( ( a & HB_INPUT_CH_LAYOUT_ENCODED_REAR_MASK ) )

/* define an invalid VBR quality compatible with all VBR-capable codecs */
#define HB_INVALID_AUDIO_QUALITY (-3.)

Expand Down Expand Up @@ -495,7 +468,7 @@ struct hb_audio_config_s
PRIVATE int samplerate; /* Input sample rate (Hz) */
PRIVATE int samples_per_frame; /* Number of samples per frame */
PRIVATE int bitrate; /* Input bitrate (bps) */
PRIVATE int channel_layout; /* Source channel layout, set by the audio decoder */
PRIVATE uint64_t channel_layout; /* Source channel layout, set by the audio decoder */
PRIVATE hb_chan_map_t * channel_map; /* Source channel map, set by the audio decoder */
} in;

Expand Down Expand Up @@ -778,18 +751,21 @@ typedef struct hb_work_info_s
uint32_t version;
uint32_t flags;
uint32_t mode;
union {
struct { // info only valid for video decoders
int width;
int height;
int pixel_aspect_width;
int pixel_aspect_height;
int color_prim;
int color_transfer;
int color_matrix;
union
{
struct
{ // info only valid for video decoders
int width;
int height;
int pixel_aspect_width;
int pixel_aspect_height;
int color_prim;
int color_transfer;
int color_matrix;
};
struct { // info only valid for audio decoders
int channel_layout;
struct
{ // info only valid for audio decoders
uint64_t channel_layout;
hb_chan_map_t * channel_map;
int samples_per_frame;
};
Expand Down
24 changes: 12 additions & 12 deletions libhb/deca52.c
Expand Up @@ -108,11 +108,11 @@ static int deca52Init( hb_work_object_t * w, hb_job_t * job )
switch( audio->config.out.mixdown )
{
case HB_AMIXDOWN_6CH:
pv->flags_out = ( A52_3F2R | A52_LFE );
pv->flags_out = (A52_3F2R|A52_LFE);
break;

case HB_AMIXDOWN_DOLBYPLII:
pv->flags_out = ( A52_DOLBY | A52_USE_DPLII );
pv->flags_out = (A52_DOLBY|A52_USE_DPLII);
break;

case HB_AMIXDOWN_DOLBY:
Expand Down Expand Up @@ -445,43 +445,43 @@ static int deca52BSInfo( hb_work_object_t *w, const hb_buffer_t *b,
case A52_MONO:
case A52_CHANNEL1:
case A52_CHANNEL2:
info->channel_layout = HB_INPUT_CH_LAYOUT_MONO;
info->channel_layout = AV_CH_LAYOUT_MONO;
break;
/* stereo input */
case A52_CHANNEL:
case A52_STEREO:
info->channel_layout = HB_INPUT_CH_LAYOUT_STEREO;
info->channel_layout = AV_CH_LAYOUT_STEREO;
break;
/* Dolby Pro Logic (a.k.a. Dolby Surround), 4.0 channels (matrix-encoded) */
case A52_DOLBY:
info->channel_layout = HB_INPUT_CH_LAYOUT_DOLBY;
info->channel_layout = AV_CH_LAYOUT_STEREO_DOWNMIX;
break;
/* 3F/2R input */
case A52_3F2R:
info->channel_layout = HB_INPUT_CH_LAYOUT_3F2R;
info->channel_layout = AV_CH_LAYOUT_5POINT0;
break;
/* 3F/1R input */
case A52_3F1R:
info->channel_layout = HB_INPUT_CH_LAYOUT_3F1R;
info->channel_layout = AV_CH_LAYOUT_4POINT0;
break;
/* other inputs */
case A52_3F:
info->channel_layout = HB_INPUT_CH_LAYOUT_3F;
info->channel_layout = AV_CH_LAYOUT_SURROUND;
break;
case A52_2F1R:
info->channel_layout = HB_INPUT_CH_LAYOUT_2F1R;
info->channel_layout = AV_CH_LAYOUT_2_1;
break;
case A52_2F2R:
info->channel_layout = HB_INPUT_CH_LAYOUT_2F2R;
info->channel_layout = AV_CH_LAYOUT_2_2;
break;
/* unknown */
default:
info->channel_layout = HB_INPUT_CH_LAYOUT_STEREO;
info->channel_layout = AV_CH_LAYOUT_STEREO;
}

if (flags & A52_LFE)
{
info->channel_layout |= HB_INPUT_CH_LAYOUT_HAS_LFE;
info->channel_layout |= AV_CH_LOW_FREQUENCY;
}

info->channel_map = &hb_ac3_chan_map;
Expand Down
18 changes: 8 additions & 10 deletions libhb/decavcodec.c
Expand Up @@ -212,24 +212,22 @@ static int decavcodecaInit( hb_work_object_t * w, hb_job_t * job )
}

// DTS: work around lack of 6.0/6.1 support in libhb
if( hb_ff_dts_disable_xch( pv->context ) )
if (hb_ff_dts_disable_xch(pv->context))
{
hb_deep_log( 2, "decavcodecaInit: found DTS-ES, requesting DTS core" );
hb_deep_log(2, "decavcodecaInit: found DTS-ES, requesting DTS core");
}
else if( ( !pv->context->channels || !pv->context->channel_layout ) &&
( w->audio->config.in.codec == HB_ACODEC_DCA_HD ) &&
( ( w->audio->config.in.channel_layout & ~HB_INPUT_CH_LAYOUT_HAS_LFE ) == HB_INPUT_CH_LAYOUT_3F2R ) )
else if ((!pv->context->channels || !pv->context->channel_layout) &&
(w->audio->config.in.codec == HB_ACODEC_DCA_HD) &&
((w->audio->config.in.channel_layout & ~AV_CH_LOW_FREQUENCY) == AV_CH_LAYOUT_5POINT0))
{
/* XXX: when we are demuxing the stream ourselves, it seems we have no
* channel count/layout info in the context until we decode audio for
* the first time. If the scan info says the source is 5.0 or 5.1,
* make sure XCh processing is disabled in Libav before decoding. */
pv->context->request_channels = pv->context->channels =
HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT( w->audio->config.in.channel_layout );
pv->context->channel_layout = AV_CH_LAYOUT_5POINT0;
if( w->audio->config.in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE )
pv->context->channel_layout |= AV_CH_LOW_FREQUENCY;
hb_deep_log( 2, "decavcodecaInit: scan detected DTS 5.0/5.1, disabling XCh processing" );
av_get_channel_layout_nb_channels(w->audio->config.in.channel_layout);
pv->context->channel_layout = w->audio->config.in.channel_layout;
hb_deep_log(2, "decavcodecaInit: scan detected DTS 5.0/5.1, disabling XCh processing");
}

if ( w->audio != NULL )
Expand Down

0 comments on commit b921399

Please sign in to comment.