]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/gxfenc.c
cosmetics: Group all external library decoders and encoders together.
[ffmpeg] / libavformat / gxfenc.c
index 77b994a31cd457f8ed0af6e5d592ac7bc6546379..39b9ed3e19b4102e58623fbb681eba0203c2aaca 100644 (file)
@@ -15,7 +15,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
+ * along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
@@ -45,6 +45,7 @@ typedef struct GXFStreamContext {
     int b_per_gop;
     int first_gop_closed;
     int64_t current_dts;
+    int dts_delay;
 } GXFStreamContext;
 
 typedef struct GXFContext {
@@ -84,7 +85,7 @@ static const GXF_Lines gxf_lines_tab[] = {
     { 720,  6 },
 };
 
-static const CodecTag gxf_media_types[] = {
+static const AVCodecTag gxf_media_types[] = {
     { CODEC_ID_MJPEG     ,   3 }, /* NTSC */
     { CODEC_ID_MJPEG     ,   4 }, /* PAL */
     { CODEC_ID_PCM_S24LE ,   9 },
@@ -405,6 +406,7 @@ static int gxf_write_umf_track_description(ByteIOContext *pb, GXFContext *ctx)
         case CODEC_ID_PCM_S16LE:  id= 'A'; break;
         case CODEC_ID_DVVIDEO:    id= sc->track_type == 6 ? 'E' : 'D'; break;
         case CODEC_ID_MJPEG:      id= 'V'; break;
+        default:                  break;
         }
         sc->media_info= id << 8;
         /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */
@@ -570,6 +572,8 @@ static int gxf_write_umf_packet(ByteIOContext *pb, GXFContext *ctx)
     return updatePacketSize(pb, pos);
 }
 
+#define GXF_NODELAY -5000
+
 static int gxf_write_header(AVFormatContext *s)
 {
     ByteIOContext *pb = &s->pb;
@@ -621,7 +625,8 @@ static int gxf_write_header(AVFormatContext *s)
                 gxf->flags |= 0x00000040;
             }
             gxf->sample_rate = sc->sample_rate;
-            av_set_pts_info(st, 64, 1, sc->sample_rate);
+            av_set_pts_info(st, 64, 1, st->codec->time_base.den);
+            sc->dts_delay = GXF_NODELAY;
             if (gxf_find_lines_index(sc) < 0)
                 sc->lines_index = -1;
             sc->sample_size = st->codec->bit_rate;
@@ -644,7 +649,7 @@ static int gxf_write_header(AVFormatContext *s)
                 }
                 break;
             default:
-                av_log(NULL, AV_LOG_ERROR, "video codec not supported\n");
+                av_log(s, AV_LOG_ERROR, "video codec not supported\n");
                 return -1;
             }
         }
@@ -705,7 +710,7 @@ static int gxf_parse_mpeg_frame(GXFStreamContext *sc, const uint8_t *buf, int si
 static int gxf_write_media_preamble(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt, int size)
 {
     GXFStreamContext *sc = &ctx->streams[pkt->stream_index];
-    int64_t dts = av_rescale(pkt->dts, ctx->sample_rate, sc->sample_rate);
+    int64_t dts = av_rescale(pkt->dts, ctx->sample_rate, sc->codec->time_base.den);
 
     put_byte(pb, sc->media_type);
     put_byte(pb, sc->index);
@@ -784,18 +789,23 @@ static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pk
     int i;
 
     for (i = 0; i < s->nb_streams; i++) {
-        if (s->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) {
-            GXFStreamContext *sc = &gxf->streams[i];
+        AVStream *st = s->streams[i];
+        GXFStreamContext *sc = &gxf->streams[i];
+        if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
             if (pkt && pkt->stream_index == i) {
                 av_fifo_write(&sc->audio_buffer, pkt->data, pkt->size);
                 pkt = NULL;
             }
             if (flush || av_fifo_size(&sc->audio_buffer) >= GXF_AUDIO_PACKET_SIZE) {
-                if (gxf_new_audio_packet(gxf, sc, &new_pkt, flush) > 0) {
+                if (!pkt && gxf_new_audio_packet(gxf, sc, &new_pkt, flush) > 0) {
                     pkt = &new_pkt;
                     break; /* add pkt right now into list */
                 }
             }
+        } else if (pkt && pkt->stream_index == i) {
+            if (sc->dts_delay == GXF_NODELAY) /* adjust dts if needed */
+                sc->dts_delay = pkt->dts;
+            pkt->dts -= sc->dts_delay;
         }
     }
     return av_interleave_packet_per_dts(s, out, pkt, flush);