]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vorbis_enc.c
Remove hack added to make "make checkheaders" pass, it is unneeded now
[ffmpeg] / libavcodec / vorbis_enc.c
index 636b0cfaec3f7a219c61706e837f69b4a67d15e1..0cb644b46b82d6edca4e747fa07bace12af73436 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /**
@@ -30,6 +30,9 @@
 #include "vorbis.h"
 #include "vorbis_enc_data.h"
 
+#define BITSTREAM_WRITER_LE
+#include "bitstream.h"
+
 #undef NDEBUG
 #include <assert.h>
 
@@ -118,53 +121,9 @@ typedef struct {
 
     int nmodes;
     vorbis_mode_t * modes;
-} venc_context_t;
-
-typedef struct {
-    int total;
-    int total_pos;
-    int pos;
-    uint8_t * buf_ptr;
-} PutBitContext;
-
-static inline void init_put_bits(PutBitContext * pb, uint8_t * buf, int buffer_len) {
-    pb->total = buffer_len * 8;
-    pb->total_pos = 0;
-    pb->pos = 0;
-    pb->buf_ptr = buf;
-}
-
-static void put_bits(PutBitContext * pb, int bits, uint64_t val) {
-    if ((pb->total_pos += bits) >= pb->total) return;
-    if (!bits) return;
-    if (pb->pos) {
-        if (pb->pos > bits) {
-            *pb->buf_ptr |= val << (8 - pb->pos);
-            pb->pos -= bits;
-            bits = 0;
-        } else {
-            *pb->buf_ptr++ |= (val << (8 - pb->pos)) & 0xFF;
-            val >>= pb->pos;
-            bits -= pb->pos;
-            pb->pos = 0;
-        }
-    }
-    for (; bits >= 8; bits -= 8) {
-        *pb->buf_ptr++ = val & 0xFF;
-        val >>= 8;
-    }
-    if (bits) {
-        *pb->buf_ptr = val;
-        pb->pos = 8 - bits;
-    }
-}
 
-static inline void flush_put_bits(PutBitContext * pb) {
-}
-
-static inline int put_bits_count(PutBitContext * pb) {
-    return pb->total_pos;
-}
+    int64_t sample_count;
+} venc_context_t;
 
 static inline void put_codeword(PutBitContext * pb, codebook_t * cb, int entry) {
     assert(entry >= 0);
@@ -254,7 +213,7 @@ static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccon
     venc->sample_rate = avccontext->sample_rate;
     venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
 
-    venc->ncodebooks = sizeof(cvectors)/sizeof(cvectors[0]);
+    venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
     venc->codebooks = av_malloc(sizeof(codebook_t) * venc->ncodebooks);
 
     // codebook 0..14 - floor1 book, values 0..255
@@ -756,7 +715,7 @@ static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb
                     int maxval = 1;
                     if (c->books[l] != -1)
                         maxval = venc->codebooks[c->books[l]].nentries;
-                    // coded could be -1, but this still works, cause thats 0
+                    // coded could be -1, but this still works, cause that is 0
                     if (coded[counter + k] < maxval) break;
                 }
                 assert(l != csub);
@@ -906,7 +865,7 @@ static int apply_window_and_mdct(venc_context_t * venc, signed short * audio, in
             float * offset = venc->samples + channel*window_len*2 + window_len;
             j = channel;
             for (i = 0; i < samples; i++, j += venc->channels)
-                offset[i] = audio[j] / 32768. / n * win[window_len - i - 1];
+                offset[i] = -audio[j] / 32768. / n * win[window_len - i - 1]; //FIXME find out why the sign has to be fliped
         }
     } else {
         for (channel = 0; channel < venc->channels; channel++) {
@@ -915,7 +874,7 @@ static int apply_window_and_mdct(venc_context_t * venc, signed short * audio, in
     }
 
     for (channel = 0; channel < venc->channels; channel++) {
-        ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel*window_len, venc->samples + channel*window_len*2, venc->floor/*tmp*/);
+        ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel*window_len, venc->samples + channel*window_len*2);
     }
 
     if (samples) {
@@ -923,7 +882,7 @@ static int apply_window_and_mdct(venc_context_t * venc, signed short * audio, in
             float * offset = venc->saved + channel*window_len;
             j = channel;
             for (i = 0; i < samples; i++, j += venc->channels)
-                offset[i] = audio[j] / 32768. / n * win[i];
+                offset[i] = -audio[j] / 32768. / n * win[i]; //FIXME find out why the sign has to be fliped
         }
         venc->have_saved = 1;
     } else {
@@ -932,7 +891,7 @@ static int apply_window_and_mdct(venc_context_t * venc, signed short * audio, in
     return 1;
 }
 
-static int vorbis_encode_init(AVCodecContext * avccontext)
+static av_cold int vorbis_encode_init(AVCodecContext * avccontext)
 {
     venc_context_t * venc = avccontext->priv_data;
 
@@ -1010,12 +969,14 @@ static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * pack
 
     residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], &pb, venc->coeffs, samples, venc->channels);
 
+    avccontext->coded_frame->pts = venc->sample_count;
+    venc->sample_count += avccontext->frame_size;
     flush_put_bits(&pb);
     return (put_bits_count(&pb) + 7) / 8;
 }
 
 
-static int vorbis_encode_close(AVCodecContext * avccontext)
+static av_cold int vorbis_encode_close(AVCodecContext * avccontext)
 {
     venc_context_t * venc = avccontext->priv_data;
     int i;
@@ -1084,4 +1045,6 @@ AVCodec vorbis_encoder = {
     vorbis_encode_frame,
     vorbis_encode_close,
     .capabilities= CODEC_CAP_DELAY,
+    .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
+    .long_name = NULL_IF_CONFIG_SMALL("Vorbis"),
 };