]> 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 8e7e54f79813d1f98ab76c1247ca0145cbd7f0eb..0cb644b46b82d6edca4e747fa07bace12af73436 100644 (file)
@@ -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
@@ -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) {
@@ -1010,6 +969,8 @@ 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;
 }
@@ -1075,7 +1036,7 @@ static av_cold int vorbis_encode_close(AVCodecContext * avccontext)
     return 0 ;
 }
 
-const AVCodec vorbis_encoder = {
+AVCodec vorbis_encoder = {
     "vorbis",
     CODEC_TYPE_AUDIO,
     CODEC_ID_VORBIS,
@@ -1084,5 +1045,6 @@ const 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"),
 };