]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/utils.c
Merge remote-tracking branch 'shariman/wmall'
[ffmpeg] / libavcodec / utils.c
index fb7173123a5b22d5609435b91ba224620da0d42c..619b70f3fba5b902ce732c054bc53ceff0964b39 100644 (file)
@@ -33,6 +33,7 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/dict.h"
+#include "libavutil/avassert.h"
 #include "avcodec.h"
 #include "dsputil.h"
 #include "libavutil/opt.h"
@@ -40,6 +41,7 @@
 #include "thread.h"
 #include "audioconvert.h"
 #include "internal.h"
+#include "bytestream.h"
 #include <stdlib.h>
 #include <stdarg.h>
 #include <limits.h>
@@ -166,10 +168,8 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
     case PIX_FMT_GBRP9BE:
     case PIX_FMT_GBRP10LE:
     case PIX_FMT_GBRP10BE:
-        w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
-        h_align= 16;
-        if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264 || s->codec_id == CODEC_ID_PRORES)
-            h_align= 32; // interlaced is rounded up to 2 MBs
+        w_align = 16; //FIXME assume 16 pixel per macroblock
+        h_align = 16 * 2; // interlaced needs 2 macroblocks height
         break;
     case PIX_FMT_YUV411P:
     case PIX_FMT_UYYVYY411:
@@ -372,7 +372,6 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
     int w= s->width;
     int h= s->height;
     InternalBuffer *buf;
-    int *picture_number;
     AVCodecInternal *avci = s->internal;
 
     if(pic->data[0]!=NULL) {
@@ -393,8 +392,6 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
     }
 
     buf = &avci->buffer[avci->buffer_count];
-    picture_number = &(avci->buffer[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack
-    (*picture_number)++;
 
     if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
         if(s->active_thread_type&FF_THREAD_FRAME) {
@@ -408,10 +405,7 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
         }
     }
 
-    if(buf->base[0]){
-        pic->age= *picture_number - buf->last_pic_num;
-        buf->last_pic_num= *picture_number;
-    }else{
+    if (!buf->base[0]) {
         int h_chroma_shift, v_chroma_shift;
         int size[4] = {0};
         int tmpsize;
@@ -450,7 +444,6 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
             size[i] = picture.data[i+1] - picture.data[i];
         size[i] = tmpsize - (picture.data[i] - picture.data[0]);
 
-        buf->last_pic_num= -256*256*256*64;
         memset(buf->base, 0, sizeof(buf->base));
         memset(buf->data, 0, sizeof(buf->data));
 
@@ -479,7 +472,6 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
         buf->width  = s->width;
         buf->height = s->height;
         buf->pix_fmt= s->pix_fmt;
-        pic->age= 256*256*256*64;
     }
     pic->type= FF_BUFFER_TYPE_INTERNAL;
 
@@ -773,6 +765,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD
             goto free_and_end;
         }
     }
+    if (!HAVE_THREADS && !(codec->capabilities & CODEC_CAP_AUTO_THREADS))
+        avctx->thread_count = 1;
 
     if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
         av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
@@ -1000,9 +994,10 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa
     int ret, got_frame = 0;
 
     if (avctx->get_buffer != avcodec_default_get_buffer) {
-        av_log(avctx, AV_LOG_ERROR, "A custom get_buffer() cannot be used with "
+        av_log(avctx, AV_LOG_ERROR, "Overriding custom get_buffer() for "
                "avcodec_decode_audio3()\n");
-        return AVERROR(EINVAL);
+        avctx->get_buffer = avcodec_default_get_buffer;
+        avctx->release_buffer = avcodec_default_release_buffer;
     }
 
     ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt);
@@ -1036,6 +1031,47 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa
 }
 #endif
 
+static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
+{
+    int size = 0;
+    const uint8_t *data;
+    uint32_t flags;
+
+    if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE))
+        return;
+
+    data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
+    if (!data || size < 4)
+        return;
+    flags = bytestream_get_le32(&data);
+    size -= 4;
+    if (size < 4) /* Required for any of the changes */
+        return;
+    if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
+        avctx->channels = bytestream_get_le32(&data);
+        size -= 4;
+    }
+    if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
+        if (size < 8)
+            return;
+        avctx->channel_layout = bytestream_get_le64(&data);
+        size -= 8;
+    }
+    if (size < 4)
+        return;
+    if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
+        avctx->sample_rate = bytestream_get_le32(&data);
+        size -= 4;
+    }
+    if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {
+        if (size < 8)
+            return;
+        avctx->width  = bytestream_get_le32(&data);
+        avctx->height = bytestream_get_le32(&data);
+        size -= 8;
+    }
+}
+
 int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
                                               AVFrame *frame,
                                               int *got_frame_ptr,
@@ -1052,11 +1088,15 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
 
     if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
         av_packet_split_side_data(avpkt);
+        apply_param_change(avctx, avpkt);
+
         avctx->pkt = avpkt;
         ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt);
         if (ret >= 0 && *got_frame_ptr) {
             avctx->frame_number++;
             frame->pkt_dts = avpkt->dts;
+            if (frame->format == AV_SAMPLE_FMT_NONE)
+                frame->format = avctx->sample_fmt;
         }
     }
     return ret;
@@ -1374,6 +1414,13 @@ const char *av_get_profile_name(const AVCodec *codec, int profile)
 
 unsigned avcodec_version( void )
 {
+    av_assert0(CODEC_ID_V410==164);
+    av_assert0(CODEC_ID_PCM_S8_PLANAR==65563);
+    av_assert0(CODEC_ID_ADPCM_G722==69660);
+    av_assert0(CODEC_ID_BMV_AUDIO==86071);
+    av_assert0(CODEC_ID_SRT==94216);
+    av_assert0(LIBAVCODEC_VERSION_MICRO >= 100);
+
   return LIBAVCODEC_VERSION_INT;
 }