]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ffv1.c
rename always_inline to av_always_inline and move to common.h
[ffmpeg] / libavcodec / ffv1.c
index 71bb887318c9259fc8dfd2c365d406f4bbc94601..1ca18a4e87d988bc925554a74b2136fbd91eb501 100644 (file)
@@ -3,19 +3,21 @@
  *
  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
  */
 
@@ -184,7 +186,7 @@ typedef struct FFV1Context{
     DSPContext dsp;
 }FFV1Context;
 
-static always_inline int fold(int diff, int bits){
+static av_always_inline int fold(int diff, int bits){
     if(bits==8)
         diff= (int8_t)diff;
     else{
@@ -223,7 +225,7 @@ static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signe
     int i;
 
     if(v){
-        const int a= ABS(v);
+        const int a= FFABS(v);
         const int e= av_log2(a);
         put_rac(c, state+0, 0);
 
@@ -271,7 +273,7 @@ static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){
 static inline void update_vlc_state(VlcState * const state, const int v){
     int drift= state->drift;
     int count= state->count;
-    state->error_sum += ABS(v);
+    state->error_sum += FFABS(v);
     drift += v;
 
     if(count == 128){ //FIXME variable
@@ -354,6 +356,7 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState * const state, int
     return ret;
 }
 
+#ifdef CONFIG_ENCODERS
 static inline int encode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){
     PlaneContext * const p= &s->plane[plane_index];
     RangeCoder * const c= &s->c;
@@ -527,6 +530,7 @@ static void write_header(FFV1Context *f){
     for(i=0; i<5; i++)
         write_quant_table(c, f->quant_table[i]);
 }
+#endif /* CONFIG_ENCODERS */
 
 static int common_init(AVCodecContext *avctx){
     FFV1Context *s = avctx->priv_data;
@@ -545,17 +549,12 @@ static int common_init(AVCodecContext *avctx){
     return 0;
 }
 
+#ifdef CONFIG_ENCODERS
 static int encode_init(AVCodecContext *avctx)
 {
     FFV1Context *s = avctx->priv_data;
     int i;
 
-    if(avctx->strict_std_compliance >FF_COMPLIANCE_EXPERIMENTAL){
-        av_log(avctx, AV_LOG_ERROR, "this codec is under development, files encoded with it may not be decodeable with future versions!!!\n"
-               "use vstrict=-2 / -strict -2 to use it anyway\n");
-        return -1;
-    }
-
     common_init(avctx);
 
     s->version=0;
@@ -614,6 +613,7 @@ static int encode_init(AVCodecContext *avctx)
 
     return 0;
 }
+#endif /* CONFIG_ENCODERS */
 
 
 static void clear_state(FFV1Context *f){
@@ -638,6 +638,7 @@ static void clear_state(FFV1Context *f){
     }
 }
 
+#ifdef CONFIG_ENCODERS
 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
     FFV1Context *f = avctx->priv_data;
     RangeCoder * const c= &f->c;
@@ -693,8 +694,10 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
         return used_count + (put_bits_count(&f->pb)+7)/8;
     }
 }
+#endif /* CONFIG_ENCODERS */
 
-static void common_end(FFV1Context *s){
+static int common_end(AVCodecContext *avctx){
+    FFV1Context *s = avctx->priv_data;
     int i;
 
     for(i=0; i<s->plane_count; i++){
@@ -702,13 +705,6 @@ static void common_end(FFV1Context *s){
 
         av_freep(&p->state);
     }
-}
-
-static int encode_end(AVCodecContext *avctx)
-{
-    FFV1Context *s = avctx->priv_data;
-
-    common_end(s);
 
     return 0;
 }
@@ -959,11 +955,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8
     p->pict_type= FF_I_TYPE; //FIXME I vs. P
     if(get_rac(c, &keystate)){
         p->key_frame= 1;
-        read_header(f);
+        if(read_header(f) < 0)
+            return -1;
         clear_state(f);
     }else{
         p->key_frame= 0;
     }
+    if(!f->plane[0].state && !f->plane[0].vlc_state)
+        return -1;
 
     p->reference= 0;
     if(avctx->get_buffer(avctx, p) < 0){
@@ -1021,7 +1020,7 @@ AVCodec ffv1_decoder = {
     sizeof(FFV1Context),
     decode_init,
     NULL,
-    NULL,
+    common_end,
     decode_frame,
     CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
     NULL
@@ -1035,6 +1034,7 @@ AVCodec ffv1_encoder = {
     sizeof(FFV1Context),
     encode_init,
     encode_frame,
-    encode_end,
+    common_end,
+    .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_RGBA32, -1},
 };
 #endif