]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libspeexenc.c
hq_hqa: Fix table data for profile 17
[ffmpeg] / libavcodec / libspeexenc.c
index 5a5079b43cac1ff5fe8c2521e2b79dddc4e1b1fb..ec8882f93660fb811cb6f48bddbe3536885a2093 100644 (file)
  *     sometimes desirable to use multiple frames-per-packet to reduce the
  *     amount of container overhead.  This can be done by setting the
  *     'frames_per_packet' option to a value 1 to 8.
+ *
+ *
+ * Optional features
+ * Speex encoder supports several optional features, which can be useful
+ * for some conditions.
+ *
+ * Voice Activity Detection
+ *     When enabled, voice activity detection detects whether the audio
+ *     being encoded is speech or silence/background noise. VAD is always
+ *     implicitly activated when encoding in VBR, so the option is only useful
+ *     in non-VBR operation. In this case, Speex detects non-speech periods and
+ *     encodes them with just enough bits to reproduce the background noise.
+ *
+ * Discontinuous Transmission (DTX)
+ *     DTX is an addition to VAD/VBR operation, that allows to stop transmitting
+ *     completely when the background noise is stationary.
+ *     In file-based operation only 5 bits are used for such frames.
  */
 
 #include <speex/speex.h>
 #include <speex/speex_header.h>
 #include <speex/speex_stereo.h>
 
-#include "libavutil/audioconvert.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "internal.h"
 #include "audio_frame_queue.h"
 
-typedef struct {
+typedef struct LibSpeexEncContext {
     AVClass *class;             ///< AVClass for private options
     SpeexBits bits;             ///< libspeex bitwriter context
     SpeexHeader header;         ///< libspeex header struct
@@ -218,7 +235,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
     s->header.frames_per_packet = s->frames_per_packet;
 
     /* set encoding delay */
-    speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->delay);
+    speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->initial_padding);
     ff_af_queue_init(avctx, &s->afq);
 
     /* create header packet bytes from header struct */
@@ -234,16 +251,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR, "memory allocation error\n");
         return AVERROR(ENOMEM);
     }
-#if FF_API_OLD_ENCODE_AUDIO
-    avctx->coded_frame = avcodec_alloc_frame();
-    if (!avctx->coded_frame) {
-        av_freep(&avctx->extradata);
-        speex_header_free(header_data);
-        speex_encoder_destroy(s->enc_state);
-        av_log(avctx, AV_LOG_ERROR, "memory allocation error\n");
-        return AVERROR(ENOMEM);
-    }
-#endif
 
     /* copy header packet to extradata */
     memcpy(avctx->extradata, header_data, header_size);
@@ -270,7 +277,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
             speex_encode_stereo_int(samples, s->header.frame_size, &s->bits);
         speex_encode_int(s->enc_state, samples, &s->bits);
         s->pkt_frame_count++;
-        if ((ret = ff_af_queue_add(&s->afq, frame) < 0))
+        if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
             return ret;
     } else {
         /* handle end-of-stream */
@@ -312,9 +319,6 @@ static av_cold int encode_close(AVCodecContext *avctx)
     speex_encoder_destroy(s->enc_state);
 
     ff_af_queue_close(&s->afq);
-#if FF_API_OLD_ENCODE_AUDIO
-    av_freep(&avctx->coded_frame);
-#endif
     av_freep(&avctx->extradata);
 
     return 0;
@@ -346,6 +350,7 @@ static const AVCodecDefault defaults[] = {
 
 AVCodec ff_libspeex_encoder = {
     .name           = "libspeex",
+    .long_name      = NULL_IF_CONFIG_SMALL("libspeex Speex"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_SPEEX,
     .priv_data_size = sizeof(LibSpeexEncContext),
@@ -359,7 +364,6 @@ AVCodec ff_libspeex_encoder = {
                                            AV_CH_LAYOUT_STEREO,
                                            0 },
     .supported_samplerates = (const int[]){ 8000, 16000, 32000, 0 },
-    .long_name      = NULL_IF_CONFIG_SMALL("libspeex Speex"),
     .priv_class     = &class,
     .defaults       = defaults,
 };