]> git.sesse.net Git - ffmpeg/blobdiff - libav/utils.c
use codec_id so that the codec does not need to be opened
[ffmpeg] / libav / utils.c
index 8a609a9b22ad0db8465fc23e57cad0ee1791d2ef..5a9aa082f4ebaadca402403ee4297fb92b3e8e6e 100644 (file)
@@ -147,8 +147,8 @@ AVInputFormat *av_find_input_format(const char *short_name)
  */
 int av_new_packet(AVPacket *pkt, int size)
 {
-    int64_t* p;
-    pkt->data = av_malloc(size + 9);
+    int i;
+    pkt->data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
     if (!pkt->data)
         return AVERROR_NOMEM;
     pkt->size = size;
@@ -156,8 +156,10 @@ int av_new_packet(AVPacket *pkt, int size)
     pkt->pts = AV_NOPTS_VALUE;
     pkt->stream_index = 0;
     pkt->flags = 0;
-    p = (int64_t*)&pkt->data[size];
-    *p = 0;
+    
+    for(i=0; i<FF_INPUT_BUFFER_PADDING_SIZE; i++)
+        pkt->data[size+i]= 0;
+
     return 0;
 }
 
@@ -333,9 +335,11 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
         if (buf_size > 0) {
             url_setbufsize(&ic->pb, buf_size);
         }
-        /* read probe data */
-        pd->buf_size = get_buffer(&ic->pb, buf, PROBE_BUF_SIZE);
-        url_fseek(&ic->pb, 0, SEEK_SET);
+        if (!fmt) {
+            /* read probe data */
+            pd->buf_size = get_buffer(&ic->pb, buf, PROBE_BUF_SIZE);
+            url_fseek(&ic->pb, 0, SEEK_SET);
+        }
     }
     
     /* guess file format */
@@ -349,6 +353,14 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
         goto fail;
     }
         
+    /* XXX: suppress this hack for redirectors */
+    if (fmt == &redir_demux) {
+        err = redir_open(ic_ptr, &ic->pb);
+        url_fclose(&ic->pb);
+        av_free(ic);
+        return err;
+    }
+
     ic->iformat = fmt;
 
     /* allocate private data */
@@ -536,6 +548,9 @@ int av_find_stream_info(AVFormatContext *ic)
                 st->codec_info_state = CSTATE_FOUND; 
                 codec = avcodec_find_decoder(st->codec.codec_id);
                 if (codec) {
+                    if(codec->capabilities & CODEC_CAP_TRUNCATED)
+                        st->codec.flags |= CODEC_FLAG_TRUNCATED;
+
                     ret = avcodec_open(&st->codec, codec);
                     if (ret >= 0)
                         st->codec_info_state = CSTATE_DECODING;
@@ -744,7 +759,7 @@ int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
 {
     AVStream *st;
     INT64 pts_mask;
-    int ret;
+    int ret, frame_size;
 
     st = s->streams[stream_index];
     pts_mask = (1LL << s->pts_wrap_bits) - 1;
@@ -756,8 +771,24 @@ int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
     /* update pts */
     switch (st->codec.codec_type) {
     case CODEC_TYPE_AUDIO:
+        if (st->codec.frame_size <= 1) {
+            frame_size = size / st->codec.channels;
+            /* specific hack for pcm codecs because no frame size is provided */
+            switch(st->codec.codec_id) {
+            case CODEC_ID_PCM_S16LE:
+            case CODEC_ID_PCM_S16BE:
+            case CODEC_ID_PCM_U16LE:
+            case CODEC_ID_PCM_U16BE:
+                frame_size >>= 1;
+                break;
+            default:
+                break;
+            }
+        } else {
+            frame_size = st->codec.frame_size;
+        }
         av_frac_add(&st->pts, 
-                    (INT64)s->pts_den * st->codec.frame_size);
+                    (INT64)s->pts_den * frame_size);
         break;
     case CODEC_TYPE_VIDEO:
         av_frac_add(&st->pts,