[FFmpeg-devel] Start of SCTE-35 support [PATCH]

Carlos Fernandez Sanz carlos at ccextractor.org
Thu Jul 7 02:48:30 EEST 2016


Hi,

Apologies for resending - gmail sent the first attempt as a binary attachment.

This patch starts the work on SCTE-35 support; for now it just detects
SCTE-35 and if present sends the data to a dummy function. Since it's
my first contribution to ffmpeg I preferred to start small and
continue working as small pieces of work are accepted or commented.

Carlos


>From c0166b6d74945ef3f2121e97215c1455f9408eaf Mon Sep 17 00:00:00 2001
From: Carlos <carlos at ccextractor.org>
Date: Mon, 11 Jan 2016 23:27:37 -0800
Subject: [PATCH] SCTE extraction from mpegts

Signed-off-by: carlos <carlos at ccextractor.org>
---
 libavcodec/avcodec.h    |  1 +
 libavcodec/codec_desc.c |  6 ++++++
 libavformat/mpegts.c    | 42 ++++++++++++++++++++++++++++++++++++------
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 39713ed..3a3c2fc 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -628,6 +628,7 @@ enum AVCodecID {
     /* other specific kind of codecs (generally used for attachments) */
     AV_CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID
pointing at the start of various fake codecs.
     AV_CODEC_ID_TTF = 0x18000,
+    AV_CODEC_ID_SCTE_35,

     AV_CODEC_ID_BINTEXT    = 0x18800,
     AV_CODEC_ID_XBIN,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 9d94b72..59fd261 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2949,6 +2949,12 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .long_name = NULL_IF_CONFIG_SMALL("binary data"),
         .mime_types= MT("application/octet-stream"),
     },
+    {
+        .id        = AV_CODEC_ID_SCTE_35,
+        .type      = AVMEDIA_TYPE_DATA,
+        .name      = "scte_35",
+        .long_name = NULL_IF_CONFIG_SMALL("SCTE 35 Message Queue"),
+    },

     /* deprecated codec ids */
 };
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index b31d233..467f1de 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -57,6 +57,7 @@ enum MpegTSFilterType {
     MPEGTS_PES,
     MPEGTS_SECTION,
     MPEGTS_PCR,
+    MPEGTS_DATA,
 };

 typedef struct MpegTSFilter MpegTSFilter;
@@ -510,6 +511,11 @@ static MpegTSFilter
*mpegts_open_pcr_filter(MpegTSContext *ts, unsigned int pid)
     return mpegts_open_filter(ts, pid, MPEGTS_PCR);
 }

+static MpegTSFilter *mpegts_open_data_filter(MpegTSContext *ts,
unsigned int pid)
+{
+    return mpegts_open_filter(ts, pid, MPEGTS_DATA);
+}
+
 static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
 {
     int pid;
@@ -705,6 +711,7 @@ static const StreamType ISO_types[] = {
     { 0x21, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_JPEG2000   },
     { 0x24, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_HEVC       },
     { 0x42, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_CAVS       },
+    { 0x86, AVMEDIA_TYPE_DATA,  AV_CODEC_ID_SCTE_35    },
     { 0xd1, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_DIRAC      },
     { 0xea, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VC1        },
     { 0 },
@@ -872,6 +879,13 @@ static void reset_pes_packet_state(PESContext *pes)
     av_buffer_unref(&pes->buffer);
 }

+static void new_data_packet(const uint8_t *buffer, int len, AVPacket *pkt)
+{
+    av_init_packet(pkt);
+    pkt->data = buffer;
+    pkt->size = len;
+}
+
 static int new_pes_packet(PESContext *pes, AVPacket *pkt)
 {
     char *sd;
@@ -1975,6 +1989,19 @@ static void pmt_cb(MpegTSFilter *filter, const
uint8_t *section, int section_len
                 pes->st->id = pes->pid;
             }
             st = pes->st;
+        } else if (stream_type == 0x86 && prog_reg_desc ==  AV_RL32("CUEI")) {
+            int idx = ff_find_stream_index(ts->stream, pid);
+            if (idx >= 0) {
+                st = ts->stream->streams[idx];
+            } else {
+                st = avformat_new_stream(ts->stream, NULL);
+                if (!st)
+                    goto out;
+                st->id = pid;
+                st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
+                mpegts_find_stream_type(st, stream_type, ISO_types);
+                mpegts_open_data_filter(ts, pid);
+            }
         } else if (stream_type != 0x13) {
             if (ts->pids[pid])
                 mpegts_close_filter(ts, ts->pids[pid]); // wrongly
added sdt filter probably
@@ -2317,15 +2344,16 @@ static int handle_packet(MpegTSContext *ts,
const uint8_t *packet)
                 }
             }
         }
-
-    } else {
+    } else if (tss->type == MPEGTS_DATA) {
+        p++;
+        new_data_packet(p,p_end - p, ts->pkt);
+        ts->stop_parse = 1;
+    } else if (tss->type == MPEGTS_PES) {
         int ret;
         // Note: The position here points actually behind the current packet.
-        if (tss->type == MPEGTS_PES) {
-            if ((ret = tss->u.pes_filter.pes_cb(tss, p, p_end - p, is_start,
+        if ((ret = tss->u.pes_filter.pes_cb(tss, p, p_end - p, is_start,
                                                 pos -
ts->raw_packet_size)) < 0)
-                return ret;
-        }
+            return ret;
     }

     return 0;
@@ -2730,6 +2758,8 @@ static int mpegts_read_packet(AVFormatContext
*s, AVPacket *pkt)
                     ret = 0;
                     break;
                 }
+            } else if (ts->pids[i] && ts->pids[i]->type == MPEGTS_DATA) {
+                return ret;
             }
     }

-- 
2.7.4


More information about the ffmpeg-devel mailing list