On 29/11/14 17:53, Vittorio Giovara wrote:
From: Fredrik Axelsson <[email protected]>

Signed-off-by: Fredrik Axelsson <[email protected]>
Signed-off-by: Michael Niedermayer <[email protected]>
---
  libavformat/mpegtsenc.c | 42 +++++++++++++++++++++++++++++++++++-------
  1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 1082650..e68c74c 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -78,6 +78,7 @@ typedef struct MpegTSWrite {

      int pmt_start_pid;
      int start_pid;
+    int m2ts_mode;

      int reemit_pat_pmt; // backward compatibility

@@ -465,9 +466,28 @@ static MpegTSService *mpegts_add_service(MpegTSWrite *ts, 
int sid,
      return service;
  }

+static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb)
+{
+    return av_rescale(avio_tell(pb) + 11, 8 * PCR_TIME_BASE, ts->mux_rate) +
+           ts->first_pcr;
+}
+
+static void mpegts_prefix_m2ts_header(AVFormatContext *s)
+{
+    MpegTSWrite *ts = s->priv_data;
+    if (ts->m2ts_mode) {
+        int64_t pcr = get_pcr(s->priv_data, s->pb);
+        uint32_t tp_extra_header = pcr % 0x3fffffff;

Do not we have a name for                   ^^^^

+        tp_extra_header = AV_RB32(&tp_extra_header);
+        avio_write(s->pb, (unsigned char *) &tp_extra_header,
+                sizeof(tp_extra_header));

Align               ^^^
+    }
+}
+
  static void section_write_packet(MpegTSSection *s, const uint8_t *packet)
  {
      AVFormatContext *ctx = s->opaque;
+    mpegts_prefix_m2ts_header(ctx);
      avio_write(ctx->pb, packet, TS_PACKET_SIZE);
  }

@@ -665,6 +685,14 @@ static int mpegts_write_header(AVFormatContext *s)
             service->pcr_packet_period,
             ts->sdt_packet_period, ts->pat_packet_period);

+    if (ts->m2ts_mode == -1) {
+        if (av_match_ext(s->filename, "m2ts")) {
+            ts->m2ts_mode = 1;
+        } else {
+            ts->m2ts_mode = 0;
+        }
+    }
+
      avio_flush(s->pb);

      return 0;
@@ -705,12 +733,6 @@ static void retransmit_si_info(AVFormatContext *s)
      }
  }

-static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb)
-{
-    return av_rescale(avio_tell(pb) + 11, 8 * PCR_TIME_BASE, ts->mux_rate) +
-           ts->first_pcr;
-}
-
  static int write_pcr_bits(uint8_t *buf, int64_t pcr)
  {
      int64_t pcr_low = pcr % 300, pcr_high = pcr / 300;
@@ -737,6 +759,7 @@ static void mpegts_insert_null_packet(AVFormatContext *s)
      *q++ = 0xff;
      *q++ = 0x10;
      memset(q, 0x0FF, TS_PACKET_SIZE - (q - buf));
+    mpegts_prefix_m2ts_header(s);
      avio_write(s->pb, buf, TS_PACKET_SIZE);
  }

@@ -762,6 +785,7 @@ static void mpegts_insert_pcr_only(AVFormatContext *s, 
AVStream *st)

      /* stuffing bytes */
      memset(q, 0xFF, TS_PACKET_SIZE - (q - buf));
+    mpegts_prefix_m2ts_header(s);
      avio_write(s->pb, buf, TS_PACKET_SIZE);
  }


Ok.

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to