]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/matroska.c
nut needs crc.o
[ffmpeg] / libavformat / matroska.c
index afe161b84545c0ddc9ae241a3db7302da58c144b..d22e85f2c2e93bdd9a4334ab46bf7dedbe8cb4fe 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "avformat.h"
 /* For codec_get_bmp_id and codec_get_wav_id. */
-#include "avi.h"
+#include "riff.h"
 #include "intfloat_readwrite.h"
 
 /* EBML version supported */
@@ -183,14 +183,14 @@ typedef enum {
  */
 
 typedef struct CodecTags{
-    char *str;
+    const char *str;
     enum CodecID id;
 }CodecTags;
 
 #define MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC   "V_MS/VFW/FOURCC"
 #define MATROSKA_CODEC_ID_AUDIO_ACM          "A_MS/ACM"
 
-CodecTags codec_tags[]={
+static CodecTags codec_tags[]={
 //    {"V_MS/VFW/FOURCC"  , CODEC_ID_NONE},
     {"V_UNCOMPRESSED"   , CODEC_ID_RAWVIDEO},
     {"V_MPEG4/ISO/SP"   , CODEC_ID_MPEG4},
@@ -2206,7 +2206,7 @@ matroska_read_header (AVFormatContext    *s,
             st = av_new_stream(s, track->stream_index);
             if (st == NULL)
                 return AVERROR_NOMEM;
-            av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */
+            av_set_pts_info(st, 64, matroska->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
 
             st->codec->codec_id = codec_id;
 
@@ -2295,7 +2295,7 @@ matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
             case MATROSKA_ID_BLOCK: {
                 uint8_t *data, *origdata;
                 int size;
-                uint64_t block_time;
+                int16_t block_time;
                 uint32_t *lace_size = NULL;
                 int n, track, flags, laces = 0;
                 uint64_t num;
@@ -2329,7 +2329,7 @@ matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
                 }
 
                 /* block_time (relative to cluster time) */
-                block_time = ((data[0] << 8) | data[1]) * matroska->time_scale;
+                block_time = (data[0] << 8) | data[1];
                 data += 2;
                 size -= 2;
                 flags = *data;
@@ -2417,7 +2417,7 @@ matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
 
                 if (res == 0) {
                     for (n = 0; n < laces; n++) {
-                        uint64_t timecode = 0;
+                        uint64_t timecode = AV_NOPTS_VALUE;
 
                         pkt = av_mallocz(sizeof(AVPacket));
                         /* XXX: prevent data copy... */
@@ -2425,10 +2425,8 @@ matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
                             res = AVERROR_NOMEM;
                             break;
                         }
-                        if (cluster_time != (uint64_t)-1) {
-                            if (block_time < 0 && (-block_time) > cluster_time)
-                                timecode = cluster_time;
-                            else
+                        if (cluster_time != (uint64_t)-1 && n == 0) {
+                            if (cluster_time + block_time >= 0)
                                 timecode = cluster_time + block_time;
                         }
                         /* FIXME: duration */
@@ -2440,7 +2438,7 @@ matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
                         pkt->stream_index =
                             matroska->tracks[track]->stream_index;
 
-                        pkt->pts = timecode / 1000000; /* ns to ms */
+                        pkt->pts = timecode;
                         pkt->pos= pos;
 
                         matroska_queue_packet(matroska, pkt);
@@ -2514,7 +2512,7 @@ matroska_parse_cluster (MatroskaDemuxContext *matroska)
                 uint64_t num;
                 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
                     break;
-                cluster_time = num * matroska->time_scale;
+                cluster_time = num;
                 break;
             }
 
@@ -2632,16 +2630,12 @@ matroska_read_close (AVFormatContext *s)
         av_free(track);
     }
 
-    for (n = 0; n < s->nb_streams; n++) {
-        av_free(s->streams[n]->codec->extradata);
-    }
-
     memset(matroska, 0, sizeof(MatroskaDemuxContext));
 
     return 0;
 }
 
-static AVInputFormat matroska_iformat = {
+AVInputFormat matroska_demuxer = {
     "matroska",
     "Matroska file format",
     sizeof(MatroskaDemuxContext),
@@ -2650,10 +2644,3 @@ static AVInputFormat matroska_iformat = {
     matroska_read_packet,
     matroska_read_close,
 };
-
-int
-matroska_init(void)
-{
-    av_register_input_format(&matroska_iformat);
-    return 0;
-}