]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libtheoraenc.c
mpegaudiodec: move imdct and windowing function to mpegaudiodsp
[ffmpeg] / libavcodec / libtheoraenc.c
index fd4a9ec4152dc88d93570b1a8e5d6c7bef1907ba..ecceceaa12432aa10a8ed2403480844e3cdd8518 100644 (file)
@@ -1,27 +1,27 @@
 /*
  * Copyright (c) 2006 Paul Richards <paul.richards@gmail.com>
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * 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.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * 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 FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*!
- * \file libtheoraenc.c
- * \brief Theora encoder using libtheora.
- * \author Paul Richards <paul.richards@gmail.com>
+/**
+ * @file
+ * @brief Theora encoder using libtheora.
+ * @author Paul Richards <paul.richards@gmail.com>
  *
  * A lot of this is copy / paste from other output codecs in
  * libavcodec or pure guesswork (or both).
@@ -30,7 +30,7 @@
  * and o_ prefixes on variables which are libogg types.
  */
 
-/* FFmpeg includes */
+/* Libav includes */
 #include "libavutil/intreadwrite.h"
 #include "libavutil/log.h"
 #include "libavutil/base64.h"
@@ -46,11 +46,10 @@ typedef struct TheoraContext {
     int         stats_offset;
     int         uv_hshift;
     int         uv_vshift;
+    int         keyframe_mask;
 } TheoraContext;
 
-/*!
-    Concatenates an ogg_packet into the extradata.
-*/
+/** Concatenate an ogg_packet into the extradata. */
 static int concatenate_packet(unsigned int* offset,
                               AVCodecContext* avc_context,
                               const ogg_packet* packet)
@@ -102,7 +101,7 @@ static int get_stats(AVCodecContext *avctx, int eos)
         memcpy(h->stats + h->stats_offset, buf, bytes);
         h->stats_offset += bytes;
     } else {
-        int b64_size = ((h->stats_offset + 2) / 3) * 4 + 1;
+        int b64_size = AV_BASE64_SIZE(h->stats_offset);
         // libtheora generates a summary header at the end
         memcpy(h->stats, buf, bytes);
         avctx->stats_out = av_malloc(b64_size);
@@ -218,6 +217,7 @@ static av_cold int encode_init(AVCodecContext* avc_context)
         return -1;
     }
 
+    h->keyframe_mask = (1 << t_info.keyframe_granule_shift) - 1;
     /* Clear up theora_info struct */
     th_info_clear(&t_info);
 
@@ -241,7 +241,7 @@ static av_cold int encode_init(AVCodecContext* avc_context)
         header, comment, and tables.
 
         Each one is prefixed with a 16bit size, then they
-        are concatenated together into ffmpeg's extradata.
+        are concatenated together into libavcodec's extradata.
     */
     offset = 0;
 
@@ -334,8 +334,10 @@ static int encode_frame(AVCodecContext* avc_context, uint8_t *outbuf,
     }
     memcpy(outbuf, o_packet.packet, o_packet.bytes);
 
-    // HACK: does not take codec delay into account (neither does the decoder though)
+    // HACK: assumes no encoder delay, this is true until libtheora becomes
+    // multithreaded (which will be disabled unless explictly requested)
     avc_context->coded_frame->pts = frame->pts;
+    avc_context->coded_frame->key_frame = !(o_packet.granulepos & h->keyframe_mask);
 
     return o_packet.bytes;
 }
@@ -354,10 +356,10 @@ static av_cold int encode_close(AVCodecContext* avc_context)
     return 0;
 }
 
-/*! AVCodec struct exposed to libavcodec */
-AVCodec libtheora_encoder = {
+/** AVCodec struct exposed to libavcodec */
+AVCodec ff_libtheora_encoder = {
     .name = "libtheora",
-    .type = CODEC_TYPE_VIDEO,
+    .type = AVMEDIA_TYPE_VIDEO,
     .id = CODEC_ID_THEORA,
     .priv_data_size = sizeof(TheoraContext),
     .init = encode_init,