]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/gxf.c
Specify the server address when opening an rtp:// URL in rtsp.c, so
[ffmpeg] / libavformat / gxf.c
index dccfdd74749087298bf6b762c1dd750c94a27665..45467c648e09cd1ddeb050c4e9f783a552138a93 100644 (file)
@@ -2,49 +2,25 @@
  * GXF demuxer.
  * Copyright (c) 2006 Reimar Doeffinger.
  *
- * 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
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "avformat.h"
 #include "common.h"
-
-typedef enum {
-    PKT_MAP = 0xbc,
-    PKT_MEDIA = 0xbf,
-    PKT_EOS = 0xfb,
-    PKT_FLT = 0xfc,
-    PKT_UMF = 0xfd
-} pkt_type_t;
-
-typedef enum {
-    MAT_NAME = 0x40,
-    MAT_FIRST_FIELD = 0x41,
-    MAT_LAST_FIELD = 0x42,
-    MAT_MARK_IN = 0x43,
-    MAT_MARK_OUT = 0x44,
-    MAT_SIZE = 0x45
-} mat_tag_t;
-
-typedef enum {
-    TRACK_NAME = 0x4c,
-    TRACK_AUX = 0x4d,
-    TRACK_VER = 0x4e,
-    TRACK_MPG_AUX = 0x4f,
-    TRACK_FPS = 0x50,
-    TRACK_LINES = 0x51,
-    TRACK_FPF = 0x52
-} track_tag_t;
+#include "gxf.h"
 
 typedef struct {
     int64_t first_field;
@@ -85,8 +61,6 @@ static int parse_packet_header(ByteIOContext *pb, pkt_type_t *type, int *length)
 static int gxf_probe(AVProbeData *p) {
     static const uint8_t startcode[] = {0, 0, 0, 0, 1, 0xbc}; // start with map packet
     static const uint8_t endcode[] = {0, 0, 0, 0, 0xe1, 0xe2};
-    if (p->buf_size < 16)
-        return 0;
     if (!memcmp(p->buf, startcode, sizeof(startcode)) &&
         !memcmp(&p->buf[16 - sizeof(endcode)], endcode, sizeof(endcode)))
         return AVPROBE_SCORE_MAX;
@@ -112,37 +86,33 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
         case 4:
             st->codec->codec_type = CODEC_TYPE_VIDEO;
             st->codec->codec_id = CODEC_ID_MJPEG;
-            st->codec->codec_tag = MKTAG('M', 'J', 'P', 'G');
             break;
         case 13:
         case 15:
             st->codec->codec_type = CODEC_TYPE_VIDEO;
             st->codec->codec_id = CODEC_ID_DVVIDEO;
-            st->codec->codec_tag = MKTAG('d', 'v', 'c', ' ');
             break;
         case 14:
         case 16:
             st->codec->codec_type = CODEC_TYPE_VIDEO;
             st->codec->codec_id = CODEC_ID_DVVIDEO;
-            st->codec->codec_tag = MKTAG('d', 'v', 'c', 'p');
             break;
         case 11:
         case 12:
         case 20:
             st->codec->codec_type = CODEC_TYPE_VIDEO;
             st->codec->codec_id = CODEC_ID_MPEG2VIDEO;
-            st->codec->codec_tag = MKTAG('M', 'P', 'G', '2');
+            st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc.
             break;
         case 22:
         case 23:
             st->codec->codec_type = CODEC_TYPE_VIDEO;
             st->codec->codec_id = CODEC_ID_MPEG1VIDEO;
-            st->codec->codec_tag = MKTAG('M', 'P', 'G', '1');
+            st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc.
             break;
         case 9:
             st->codec->codec_type = CODEC_TYPE_AUDIO;
             st->codec->codec_id = CODEC_ID_PCM_S24LE;
-            st->codec->codec_tag = 0x1;
             st->codec->channels = 1;
             st->codec->sample_rate = 48000;
             st->codec->bit_rate = 3 * 1 * 48000 * 8;
@@ -152,7 +122,6 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
         case 10:
             st->codec->codec_type = CODEC_TYPE_AUDIO;
             st->codec->codec_id = CODEC_ID_PCM_S16LE;
-            st->codec->codec_tag = 0x1;
             st->codec->channels = 1;
             st->codec->sample_rate = 48000;
             st->codec->bit_rate = 2 * 1 * 48000 * 8;
@@ -162,10 +131,16 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
         case 17:
             st->codec->codec_type = CODEC_TYPE_AUDIO;
             st->codec->codec_id = CODEC_ID_AC3;
-            st->codec->codec_tag = 0x2000;
             st->codec->channels = 2;
             st->codec->sample_rate = 48000;
             break;
+        // timecode tracks:
+        case 7:
+        case 8:
+        case 24:
+            st->codec->codec_type = CODEC_TYPE_DATA;
+            st->codec->codec_id = CODEC_ID_NONE;
+            break;
         default:
             st->codec->codec_type = CODEC_TYPE_UNKNOWN;
             st->codec->codec_id = CODEC_ID_NONE;
@@ -176,7 +151,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
 
 /**
  * \brief filters out interesting tags from material information.
- * \param len lenght of tag section, will be adjusted to contain remaining bytes
+ * \param len length of tag section, will be adjusted to contain remaining bytes
  * \param si struct to store collected information into
  */
 static void gxf_material_tags(ByteIOContext *pb, int *len, st_info_t *si) {
@@ -357,10 +332,11 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
         }
     }
     if (pkt_type == PKT_UMF) {
-        if (len >= 9) {
+        if (len >= 0x39) {
             AVRational fps;
-            len -= 9;
-            url_fskip(pb, 5);
+            len -= 0x39;
+            url_fskip(pb, 5); // preamble
+            url_fskip(pb, 0x30); // payload description
             fps = fps_umf2avr(get_le32(pb));
             if (!main_timebase.num || !main_timebase.den) {
                 // this may not always be correct, but simply the best we can get
@@ -372,13 +348,11 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) {
     } else
         av_log(s, AV_LOG_INFO, "GXF: UMF packet missing\n");
     url_fskip(pb, len);
+    if (!main_timebase.num || !main_timebase.den)
+        main_timebase = (AVRational){1, 50}; // set some arbitrary fallback
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
-        if (main_timebase.num && main_timebase.den)
-            st->time_base = main_timebase;
-        else {
-            st->start_time = st->duration = AV_NOPTS_VALUE;
-        }
+        av_set_pts_info(st, 32, main_timebase.num, main_timebase.den);
     }
     return 0;
 }
@@ -406,7 +380,7 @@ static int64_t gxf_resync_media(AVFormatContext *s, uint64_t max_interval, int t
     int len;
     ByteIOContext *pb = &s->pb;
     pkt_type_t type;
-    tmp = 0xff;
+    tmp = get_be32(pb);
 start:
     while (tmp)
         READ_ONE();
@@ -470,10 +444,10 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) {
         // as well.
         ret = av_get_packet(pb, pkt, pkt_len);
         pkt->stream_index = get_sindex(s, track_id, track_type);
-        pkt->pts = field_nr;
+        pkt->dts = field_nr;
         return ret;
     }
-    return AVERROR_IO;
+    return AVERROR(EIO);
 }
 
 static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) {
@@ -494,7 +468,7 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int
     maxlen = FFMAX(maxlen, 200 * 1024);
     url_fseek(&s->pb, pos, SEEK_SET);
     found = gxf_resync_media(s, maxlen, -1, timestamp);
-    if (ABS(found - timestamp) > 4)
+    if (FFABS(found - timestamp) > 4)
         return -1;
     return 0;
 }