avcodec/pthread_frame: fix setting hwaccel with threads and get_format()
[ffmpeg.git] / libavcodec / libfdk-aacdec.c
index 201286f..624d579 100644 (file)
@@ -2,21 +2,19 @@
  * AAC decoder wrapper
  * Copyright (c) 2012 Martin Storsjo
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * Libav is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
 #include <fdk-aac/aacdecoder_lib.h>
@@ -28,7 +26,6 @@
 #include "internal.h"
 
 enum ConcealMethod {
-    CONCEAL_METHOD_DEFAULT              = -1,
     CONCEAL_METHOD_SPECTRAL_MUTING      =  0,
     CONCEAL_METHOD_NOISE_SUBSTITUTION   =  1,
     CONCEAL_METHOD_ENERGY_INTERPOLATION =  2,
@@ -45,8 +42,7 @@ typedef struct FDKAACDecContext {
 #define OFFSET(x) offsetof(FDKAACDecContext, x)
 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 static const AVOption fdk_aac_dec_options[] = {
-    { "conceal", "Error concealment method", OFFSET(conceal_method), AV_OPT_TYPE_INT, { .i64 = CONCEAL_METHOD_DEFAULT }, CONCEAL_METHOD_DEFAULT, CONCEAL_METHOD_NB - 1, AD, "conceal" },
-    { "default",  "Default",              0, AV_OPT_TYPE_CONST, { .i64 = CONCEAL_METHOD_DEFAULT },              INT_MIN, INT_MAX, AD, "conceal" },
+    { "conceal", "Error concealment method", OFFSET(conceal_method), AV_OPT_TYPE_INT, { .i64 = CONCEAL_METHOD_NOISE_SUBSTITUTION }, CONCEAL_METHOD_SPECTRAL_MUTING, CONCEAL_METHOD_NB - 1, AD, "conceal" },
     { "spectral", "Spectral muting",      0, AV_OPT_TYPE_CONST, { .i64 = CONCEAL_METHOD_SPECTRAL_MUTING },      INT_MIN, INT_MAX, AD, "conceal" },
     { "noise",    "Noise Substitution",   0, AV_OPT_TYPE_CONST, { .i64 = CONCEAL_METHOD_NOISE_SUBSTITUTION },   INT_MIN, INT_MAX, AD, "conceal" },
     { "energy",   "Energy Interpolation", 0, AV_OPT_TYPE_CONST, { .i64 = CONCEAL_METHOD_ENERGY_INTERPOLATION }, INT_MIN, INT_MAX, AD, "conceal" },
@@ -85,16 +81,18 @@ static int get_stream_info(AVCodecContext *avctx)
         }
         channel_counts[ctype]++;
     }
-    av_log(avctx, AV_LOG_DEBUG, "%d channels - front:%d side:%d back:%d lfe:%d top:%d\n",
+    av_log(avctx, AV_LOG_DEBUG,
+           "%d channels - front:%d side:%d back:%d lfe:%d top:%d\n",
            info->numChannels,
            channel_counts[ACT_FRONT], channel_counts[ACT_SIDE],
            channel_counts[ACT_BACK],  channel_counts[ACT_LFE],
            channel_counts[ACT_FRONT_TOP] + channel_counts[ACT_SIDE_TOP] +
-           channel_counts[ACT_BACK_TOP]  channel_counts[ACT_TOP]);
+           channel_counts[ACT_BACK_TOP]  + channel_counts[ACT_TOP]);
 
     switch (channel_counts[ACT_FRONT]) {
     case 4:
-        ch_layout |= AV_CH_LAYOUT_STEREO | AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER;
+        ch_layout |= AV_CH_LAYOUT_STEREO | AV_CH_FRONT_LEFT_OF_CENTER |
+                     AV_CH_FRONT_RIGHT_OF_CENTER;
         break;
     case 3:
         ch_layout |= AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER;
@@ -106,8 +104,9 @@ static int get_stream_info(AVCodecContext *avctx)
         ch_layout |= AV_CH_FRONT_CENTER;
         break;
     default:
-        av_log(avctx, AV_LOG_WARNING, "unsupported number of front channels: %d\n",
-                channel_counts[ACT_FRONT]);
+        av_log(avctx, AV_LOG_WARNING,
+               "unsupported number of front channels: %d\n",
+               channel_counts[ACT_FRONT]);
         ch_error = 1;
         break;
     }
@@ -115,7 +114,8 @@ static int get_stream_info(AVCodecContext *avctx)
         if (channel_counts[ACT_SIDE] == 2) {
             ch_layout |= AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT;
         } else {
-            av_log(avctx, AV_LOG_WARNING, "unsupported number of side channels: %d\n",
+            av_log(avctx, AV_LOG_WARNING,
+                   "unsupported number of side channels: %d\n",
                    channel_counts[ACT_SIDE]);
             ch_error = 1;
         }
@@ -132,8 +132,9 @@ static int get_stream_info(AVCodecContext *avctx)
             ch_layout |= AV_CH_BACK_CENTER;
             break;
         default:
-            av_log(avctx, AV_LOG_WARNING, "unsupported number of back channels: %d\n",
-                    channel_counts[ACT_BACK]);
+            av_log(avctx, AV_LOG_WARNING,
+                   "unsupported number of back channels: %d\n",
+                   channel_counts[ACT_BACK]);
             ch_error = 1;
             break;
         }
@@ -142,7 +143,8 @@ static int get_stream_info(AVCodecContext *avctx)
         if (channel_counts[ACT_LFE] == 1) {
             ch_layout |= AV_CH_LOW_FREQUENCY;
         } else {
-            av_log(avctx, AV_LOG_WARNING, "unsupported number of LFE channels: %d\n",
+            av_log(avctx, AV_LOG_WARNING,
+                   "unsupported number of LFE channels: %d\n",
                    channel_counts[ACT_LFE]);
             ch_error = 1;
         }
@@ -184,17 +186,17 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)
     }
 
     if (avctx->extradata_size) {
-        if ((err = aacDecoder_ConfigRaw(s->handle, &avctx->extradata, &avctx->extradata_size)) != AAC_DEC_OK) {
+        if ((err = aacDecoder_ConfigRaw(s->handle, &avctx->extradata,
+                                        &avctx->extradata_size)) != AAC_DEC_OK) {
             av_log(avctx, AV_LOG_ERROR, "Unable to set extradata\n");
             return AVERROR_INVALIDDATA;
         }
     }
 
-    if (s->conceal_method != CONCEAL_METHOD_DEFAULT) {
-        if ((err = aacDecoder_SetParam(s->handle, AAC_CONCEAL_METHOD, s->conceal_method)) != AAC_DEC_OK) {
-            av_log(avctx, AV_LOG_ERROR, "Unable to set error concealment method\n");
-            return AVERROR_UNKNOWN;
-        }
+    if ((err = aacDecoder_SetParam(s->handle, AAC_CONCEAL_METHOD,
+                                   s->conceal_method)) != AAC_DEC_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to set error concealment method\n");
+        return AVERROR_UNKNOWN;
     }
 
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
@@ -221,10 +223,8 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data,
 
     if (s->initialized) {
         frame->nb_samples = avctx->frame_size;
-        if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
-            av_log(avctx, AV_LOG_ERROR, "ff_get_buffer() failed\n");
+        if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
             return ret;
-        }
         buf = frame->extended_data[0];
         buf_size = avctx->channels * frame->nb_samples *
                    av_get_bytes_per_sample(avctx->sample_fmt);
@@ -241,7 +241,8 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data,
         goto end;
     }
     if (err != AAC_DEC_OK) {
-        av_log(avctx, AV_LOG_ERROR, "aacDecoder_DecodeFrame() failed: %x\n", err);
+        av_log(avctx, AV_LOG_ERROR,
+               "aacDecoder_DecodeFrame() failed: %x\n", err);
         ret = AVERROR_UNKNOWN;
         goto end;
     }
@@ -255,10 +256,8 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data,
 
     if (tmpptr) {
         frame->nb_samples = avctx->frame_size;
-        if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
-            av_log(avctx, AV_LOG_ERROR, "ff_get_buffer() failed\n");
+        if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
             goto end;
-        }
         memcpy(frame->extended_data[0], tmpptr,
                avctx->channels * avctx->frame_size *
                av_get_bytes_per_sample(avctx->sample_fmt));
@@ -280,7 +279,8 @@ static av_cold void fdk_aac_decode_flush(AVCodecContext *avctx)
     if (!s->handle)
         return;
 
-    if ((err = aacDecoder_SetParam(s->handle, AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
+    if ((err = aacDecoder_SetParam(s->handle,
+                                   AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
         av_log(avctx, AV_LOG_WARNING, "failed to clear buffer when flushing\n");
 }
 
@@ -294,6 +294,6 @@ AVCodec ff_libfdk_aac_decoder = {
     .decode         = fdk_aac_decode_frame,
     .close          = fdk_aac_decode_close,
     .flush          = fdk_aac_decode_flush,
-    .capabilities   = CODEC_CAP_DR1,
+    .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_CHANNEL_CONF,
     .priv_class     = &fdk_aac_dec_class,
 };