]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpegaudioenc.c
Lossless jpeg expects and uses BGRA not RGB32 (this probably caused a problem on
[ffmpeg] / libavcodec / mpegaudioenc.c
index 343aed61011ba941acdf39db7e5e8428c31e42d8..a1e2023ba1e96466afa549cfe294867b11010006 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * The simplest mpeg audio layer 2 encoder
- * Copyright (c) 2000, 2001 Fabrice Bellard.
+ * Copyright (c) 2000, 2001 Fabrice Bellard
  *
  * This file is part of FFmpeg.
  *
  */
 
 /**
- * @file mpegaudio.c
+ * @file libavcodec/mpegaudio.c
  * The simplest mpeg audio layer 2 encoder.
  */
 
 #include "avcodec.h"
-#include "bitstream.h"
+#include "put_bits.h"
+
+#undef  CONFIG_MPEGAUDIO_HP
+#define CONFIG_MPEGAUDIO_HP 0
 #include "mpegaudio.h"
 
 /* currently, cannot change these constants (need to modify
    quantization stage) */
 #define MUL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
-#define FIX(a)   ((int)((a) * (1 << FRAC_BITS)))
 
 #define SAMPLES_BUF_SIZE 4096
 
@@ -57,12 +59,12 @@ typedef struct MpegAudioContext {
 } MpegAudioContext;
 
 /* define it to use floats in quantization (I don't like floats !) */
-//#define USE_FLOATS
+#define USE_FLOATS
 
 #include "mpegaudiodata.h"
 #include "mpegaudiotab.h"
 
-static int MPA_encode_init(AVCodecContext *avctx)
+static av_cold int MPA_encode_init(AVCodecContext *avctx)
 {
     MpegAudioContext *s = avctx->priv_data;
     int freq = avctx->sample_rate;
@@ -124,10 +126,8 @@ static int MPA_encode_init(AVCodecContext *avctx)
     s->sblimit = ff_mpa_sblimit_table[table];
     s->alloc_table = ff_mpa_alloc_tables[table];
 
-#ifdef DEBUG
-    av_log(avctx, AV_LOG_DEBUG, "%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n",
-           bitrate, freq, s->frame_size, table, s->frame_frac_incr);
-#endif
+    dprintf(avctx, "%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n",
+            bitrate, freq, s->frame_size, table, s->frame_frac_incr);
 
     for(i=0;i<s->nb_channels;i++)
         s->samples_offset[i] = 0;
@@ -388,7 +388,7 @@ static void compute_scale_factors(unsigned char scale_code[SBLIMIT],
                     vmax = v;
             }
             /* compute the scale factor index using log 2 computations */
-            if (vmax > 0) {
+            if (vmax > 1) {
                 n = av_log2(vmax);
                 /* n is the position of the MSB of vmax. now
                    use at most 2 compares to find the index */
@@ -470,7 +470,7 @@ static void compute_scale_factors(unsigned char scale_code[SBLIMIT],
             sf[1] = sf[2] = sf[0];
             break;
         default:
-            assert(0); //cant happen
+            assert(0); //cannot happen
             code = 0;           /* kill warning */
         }
 
@@ -541,7 +541,7 @@ static void compute_bit_allocation(MpegAudioContext *s,
         /* look for the subband with the largest signal to mask ratio */
         max_sb = -1;
         max_ch = -1;
-        max_smr = 0x80000000;
+        max_smr = INT_MIN;
         for(ch=0;ch<s->nb_channels;ch++) {
             for(i=0;i<s->sblimit;i++) {
                 if (smr[ch][i] > max_smr && subband_status[ch][i] != SB_NOMORE) {
@@ -779,10 +779,10 @@ static int MPA_encode_frame(AVCodecContext *avctx,
     encode_frame(s, bit_alloc, padding);
 
     s->nb_samples += MPA_FRAME_SIZE;
-    return pbBufPtr(&s->pb) - s->pb.buf;
+    return put_bits_ptr(&s->pb) - s->pb.buf;
 }
 
-static int MPA_encode_close(AVCodecContext *avctx)
+static av_cold int MPA_encode_close(AVCodecContext *avctx)
 {
     av_freep(&avctx->coded_frame);
     return 0;
@@ -797,6 +797,8 @@ AVCodec mp2_encoder = {
     MPA_encode_frame,
     MPA_encode_close,
     NULL,
+    .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
+    .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
 };
 
 #undef FIX