Re: [libav-devel] [PATCH] dcadec: remove extra indirection

2017-03-29 Thread Luca Barbato
On 29/03/2017 12:36, Luca Barbato wrote:
> On 29/03/2017 12:04, Vittorio Giovara wrote:
>> From: Anton Khirnov 
>>
>> num_core_channels is always equal to s->audio_header.prim_channels,
>> neither one of those variables ever get changed.
>> ---
>>  libavcodec/dcadec.c | 20 
>>  1 file changed, 8 insertions(+), 12 deletions(-)
>>
>> diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
>> index fa2a2400fe..85bb7ed1a8 100644
>> --- a/libavcodec/dcadec.c
>> +++ b/libavcodec/dcadec.c
>> @@ -1263,7 +1263,7 @@ static int scan_for_extensions(AVCodecContext *avctx)
>>  return ret;
>>  }
>>  
>> -static int set_channel_layout(AVCodecContext *avctx, int channels, int 
>> num_core_channels)
>> +static int set_channel_layout(AVCodecContext *avctx, int channels)
>>  {
>>  DCAContext *s = avctx->priv_data;
> 
> put here int num_core_channels and set it to
> s->audio_header.prim_channels to reduce the changes and make certain
> compiler possibly happier?
> 
>>  int i;
>> @@ -1290,7 +1290,7 @@ static int set_channel_layout(AVCodecContext *avctx, 
>> int channels, int num_core_
>>  s->channel_order_tab = 
>> ff_dca_channel_reorder_nolfe_xch[s->amode];
>>  }
>>  } else {
>> -channels   = num_core_channels + !!s->lfe;
>> +channels   = s->audio_header.prim_channels + !!s->lfe;
>>  s->xch_present = 0; /* disable further xch processing */
>>  if (s->lfe) {
>>  avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
>> @@ -1306,7 +1306,7 @@ static int set_channel_layout(AVCodecContext *avctx, 
>> int channels, int num_core_
>>  s->channel_order_tab[channels - 1 - !!s->lfe] < 0)
>>  return AVERROR_INVALIDDATA;
>>  
>> -if (num_core_channels + !!s->lfe > 2 &&
>> +if (s->audio_header.prim_channels + !!s->lfe > 2 &&
>>  avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
>>  channels  = 2;
>>  s->output = s->audio_header.prim_channels == 2 ? 
>> s->amode : DCA_STEREO;
>> @@ -1319,7 +1319,7 @@ static int set_channel_layout(AVCodecContext *avctx, 
>> int channels, int num_core_
>>   */
>>  if (s->core_downmix && (s->core_downmix_amode == DCA_STEREO ||
>>  s->core_downmix_amode == 
>> DCA_STEREO_TOTAL)) {
>> -for (i = 0; i < num_core_channels + !!s->lfe; i++) {
>> +for (i = 0; i < s->audio_header.prim_channels + !!s->lfe; 
>> i++) {
>>  /* Range checked earlier */
>>  s->downmix_coef[i][0] = 
>> dca_dmix_code(s->core_downmix_codes[i][0]);
>>  s->downmix_coef[i][1] = 
>> dca_dmix_code(s->core_downmix_codes[i][1]);
>> @@ -1332,19 +1332,19 @@ static int set_channel_layout(AVCodecContext *avctx, 
>> int channels, int num_core_
>> "Invalid channel mode %d\n", am);
>>  return AVERROR_INVALIDDATA;
>>  }
>> -if (num_core_channels + !!s->lfe >
>> +if (s->audio_header.prim_channels + !!s->lfe >
>>  FF_ARRAY_ELEMS(ff_dca_default_coeffs[0])) {
>>  avpriv_request_sample(s->avctx, "Downmixing %d 
>> channels",
>>s->audio_header.prim_channels + 
>> !!s->lfe);
>>  return AVERROR_PATCHWELCOME;
>>  }
>> -for (i = 0; i < num_core_channels + !!s->lfe; i++) {
>> +for (i = 0; i < s->audio_header.prim_channels + !!s->lfe; 
>> i++) {
>>  s->downmix_coef[i][0] = ff_dca_default_coeffs[am][i][0];
>>  s->downmix_coef[i][1] = ff_dca_default_coeffs[am][i][1];
>>  }
>>  }
>>  ff_dlog(s->avctx, "Stereo downmix coeffs:\n");
>> -for (i = 0; i < num_core_channels + !!s->lfe; i++) {
>> +for (i = 0; i < s->audio_header.prim_channels + !!s->lfe; i++) {
>>  ff_dlog(s->avctx, "L, input channel %d = %f\n", i,
>>  s->downmix_coef[i][0]);
>>  ff_dlog(s->avctx, "R, input channel %d = %f\n", i,
>> @@ -1372,7 +1372,6 @@ static int dca_decode_frame(AVCodecContext *avctx, 
>> void *data,
>>  int buf_size   = avpkt->size;
>>  
>>  int lfe_samples;
>> -int num_core_channels = 0;
>>  int i, ret;
>>  float  **samples_flt;
>>  DCAContext *s = avctx->priv_data;
>> @@ -1406,9 +1405,6 @@ static int dca_decode_frame(AVCodecContext *avctx, 
>> void *data,
>>  }
>>  }
>>  
> 
> Below it is ok.
> 
>> -/* record number of core channels incase less than max channels are 
>> requested */
>> -num_core_channels = s->audio_header.prim_channels;
>> -
>>  if (s->ext_coding)
>>  s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr];
>>  

Re: [libav-devel] [PATCH] dcadec: remove extra indirection

2017-03-29 Thread Luca Barbato
On 29/03/2017 12:04, Vittorio Giovara wrote:
> From: Anton Khirnov 
> 
> num_core_channels is always equal to s->audio_header.prim_channels,
> neither one of those variables ever get changed.
> ---
>  libavcodec/dcadec.c | 20 
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
> index fa2a2400fe..85bb7ed1a8 100644
> --- a/libavcodec/dcadec.c
> +++ b/libavcodec/dcadec.c
> @@ -1263,7 +1263,7 @@ static int scan_for_extensions(AVCodecContext *avctx)
>  return ret;
>  }
>  
> -static int set_channel_layout(AVCodecContext *avctx, int channels, int 
> num_core_channels)
> +static int set_channel_layout(AVCodecContext *avctx, int channels)
>  {
>  DCAContext *s = avctx->priv_data;

put here int num_core_channels and set it to
s->audio_header.prim_channels to reduce the changes and make certain
compiler possibly happier?

>  int i;
> @@ -1290,7 +1290,7 @@ static int set_channel_layout(AVCodecContext *avctx, 
> int channels, int num_core_
>  s->channel_order_tab = 
> ff_dca_channel_reorder_nolfe_xch[s->amode];
>  }
>  } else {
> -channels   = num_core_channels + !!s->lfe;
> +channels   = s->audio_header.prim_channels + !!s->lfe;
>  s->xch_present = 0; /* disable further xch processing */
>  if (s->lfe) {
>  avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
> @@ -1306,7 +1306,7 @@ static int set_channel_layout(AVCodecContext *avctx, 
> int channels, int num_core_
>  s->channel_order_tab[channels - 1 - !!s->lfe] < 0)
>  return AVERROR_INVALIDDATA;
>  
> -if (num_core_channels + !!s->lfe > 2 &&
> +if (s->audio_header.prim_channels + !!s->lfe > 2 &&
>  avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
>  channels  = 2;
>  s->output = s->audio_header.prim_channels == 2 ? 
> s->amode : DCA_STEREO;
> @@ -1319,7 +1319,7 @@ static int set_channel_layout(AVCodecContext *avctx, 
> int channels, int num_core_
>   */
>  if (s->core_downmix && (s->core_downmix_amode == DCA_STEREO ||
>  s->core_downmix_amode == 
> DCA_STEREO_TOTAL)) {
> -for (i = 0; i < num_core_channels + !!s->lfe; i++) {
> +for (i = 0; i < s->audio_header.prim_channels + !!s->lfe; 
> i++) {
>  /* Range checked earlier */
>  s->downmix_coef[i][0] = 
> dca_dmix_code(s->core_downmix_codes[i][0]);
>  s->downmix_coef[i][1] = 
> dca_dmix_code(s->core_downmix_codes[i][1]);
> @@ -1332,19 +1332,19 @@ static int set_channel_layout(AVCodecContext *avctx, 
> int channels, int num_core_
> "Invalid channel mode %d\n", am);
>  return AVERROR_INVALIDDATA;
>  }
> -if (num_core_channels + !!s->lfe >
> +if (s->audio_header.prim_channels + !!s->lfe >
>  FF_ARRAY_ELEMS(ff_dca_default_coeffs[0])) {
>  avpriv_request_sample(s->avctx, "Downmixing %d channels",
>s->audio_header.prim_channels + 
> !!s->lfe);
>  return AVERROR_PATCHWELCOME;
>  }
> -for (i = 0; i < num_core_channels + !!s->lfe; i++) {
> +for (i = 0; i < s->audio_header.prim_channels + !!s->lfe; 
> i++) {
>  s->downmix_coef[i][0] = ff_dca_default_coeffs[am][i][0];
>  s->downmix_coef[i][1] = ff_dca_default_coeffs[am][i][1];
>  }
>  }
>  ff_dlog(s->avctx, "Stereo downmix coeffs:\n");
> -for (i = 0; i < num_core_channels + !!s->lfe; i++) {
> +for (i = 0; i < s->audio_header.prim_channels + !!s->lfe; i++) {
>  ff_dlog(s->avctx, "L, input channel %d = %f\n", i,
>  s->downmix_coef[i][0]);
>  ff_dlog(s->avctx, "R, input channel %d = %f\n", i,
> @@ -1372,7 +1372,6 @@ static int dca_decode_frame(AVCodecContext *avctx, void 
> *data,
>  int buf_size   = avpkt->size;
>  
>  int lfe_samples;
> -int num_core_channels = 0;
>  int i, ret;
>  float  **samples_flt;
>  DCAContext *s = avctx->priv_data;
> @@ -1406,9 +1405,6 @@ static int dca_decode_frame(AVCodecContext *avctx, void 
> *data,
>  }
>  }
>  

Below it is ok.

> -/* record number of core channels incase less than max channels are 
> requested */
> -num_core_channels = s->audio_header.prim_channels;
> -
>  if (s->ext_coding)
>  s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr];
>  else
> @@ -1420,7 +1416,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void 
> *data,
>  
>  full_channels = channels = s->audio_header.prim_channels + 

[libav-devel] [PATCH] dcadec: remove extra indirection

2017-03-29 Thread Vittorio Giovara
From: Anton Khirnov 

num_core_channels is always equal to s->audio_header.prim_channels,
neither one of those variables ever get changed.
---
 libavcodec/dcadec.c | 20 
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index fa2a2400fe..85bb7ed1a8 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -1263,7 +1263,7 @@ static int scan_for_extensions(AVCodecContext *avctx)
 return ret;
 }
 
-static int set_channel_layout(AVCodecContext *avctx, int channels, int 
num_core_channels)
+static int set_channel_layout(AVCodecContext *avctx, int channels)
 {
 DCAContext *s = avctx->priv_data;
 int i;
@@ -1290,7 +1290,7 @@ static int set_channel_layout(AVCodecContext *avctx, int 
channels, int num_core_
 s->channel_order_tab = 
ff_dca_channel_reorder_nolfe_xch[s->amode];
 }
 } else {
-channels   = num_core_channels + !!s->lfe;
+channels   = s->audio_header.prim_channels + !!s->lfe;
 s->xch_present = 0; /* disable further xch processing */
 if (s->lfe) {
 avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
@@ -1306,7 +1306,7 @@ static int set_channel_layout(AVCodecContext *avctx, int 
channels, int num_core_
 s->channel_order_tab[channels - 1 - !!s->lfe] < 0)
 return AVERROR_INVALIDDATA;
 
-if (num_core_channels + !!s->lfe > 2 &&
+if (s->audio_header.prim_channels + !!s->lfe > 2 &&
 avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
 channels  = 2;
 s->output = s->audio_header.prim_channels == 2 ? 
s->amode : DCA_STEREO;
@@ -1319,7 +1319,7 @@ static int set_channel_layout(AVCodecContext *avctx, int 
channels, int num_core_
  */
 if (s->core_downmix && (s->core_downmix_amode == DCA_STEREO ||
 s->core_downmix_amode == 
DCA_STEREO_TOTAL)) {
-for (i = 0; i < num_core_channels + !!s->lfe; i++) {
+for (i = 0; i < s->audio_header.prim_channels + !!s->lfe; i++) 
{
 /* Range checked earlier */
 s->downmix_coef[i][0] = 
dca_dmix_code(s->core_downmix_codes[i][0]);
 s->downmix_coef[i][1] = 
dca_dmix_code(s->core_downmix_codes[i][1]);
@@ -1332,19 +1332,19 @@ static int set_channel_layout(AVCodecContext *avctx, 
int channels, int num_core_
"Invalid channel mode %d\n", am);
 return AVERROR_INVALIDDATA;
 }
-if (num_core_channels + !!s->lfe >
+if (s->audio_header.prim_channels + !!s->lfe >
 FF_ARRAY_ELEMS(ff_dca_default_coeffs[0])) {
 avpriv_request_sample(s->avctx, "Downmixing %d channels",
   s->audio_header.prim_channels + 
!!s->lfe);
 return AVERROR_PATCHWELCOME;
 }
-for (i = 0; i < num_core_channels + !!s->lfe; i++) {
+for (i = 0; i < s->audio_header.prim_channels + !!s->lfe; i++) 
{
 s->downmix_coef[i][0] = ff_dca_default_coeffs[am][i][0];
 s->downmix_coef[i][1] = ff_dca_default_coeffs[am][i][1];
 }
 }
 ff_dlog(s->avctx, "Stereo downmix coeffs:\n");
-for (i = 0; i < num_core_channels + !!s->lfe; i++) {
+for (i = 0; i < s->audio_header.prim_channels + !!s->lfe; i++) {
 ff_dlog(s->avctx, "L, input channel %d = %f\n", i,
 s->downmix_coef[i][0]);
 ff_dlog(s->avctx, "R, input channel %d = %f\n", i,
@@ -1372,7 +1372,6 @@ static int dca_decode_frame(AVCodecContext *avctx, void 
*data,
 int buf_size   = avpkt->size;
 
 int lfe_samples;
-int num_core_channels = 0;
 int i, ret;
 float  **samples_flt;
 DCAContext *s = avctx->priv_data;
@@ -1406,9 +1405,6 @@ static int dca_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 }
 
-/* record number of core channels incase less than max channels are 
requested */
-num_core_channels = s->audio_header.prim_channels;
-
 if (s->ext_coding)
 s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr];
 else
@@ -1420,7 +1416,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void 
*data,
 
 full_channels = channels = s->audio_header.prim_channels + !!s->lfe;
 
-ret = set_channel_layout(avctx, channels, num_core_channels);
+ret = set_channel_layout(avctx, channels);
 if (ret < 0)
 return ret;
 avctx->channels = channels;
-- 
2.12.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel