diff mbox

[FFmpeg-devel] avformat: Add rtp_mpegtsraw (MPEG-TS RAW Stream output)

Message ID w_ve93ic8tyPjWRyi77XupCXQNrDV-0h6FVaFfLMK-Xbr7FzLD_V31kP4DL8pV0SmvYu0dms511PLS_GaZ8B-ymxrCS1vwjDerI8O5_-fhM=@protonmail.com
State New
Headers show

Commit Message

Andreas Håkon Jan. 15, 2017, 8:59 p.m. UTC
Hi Moritz,


-------- Original Message --------
Subject: Re: [FFmpeg-devel] [PATCH] avformat: Add rtp_mpegtsraw (MPEG-TS RAW Stream output)
From: barsnick@gmx.net
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>

On Fri, Jan 13, 2017 at 07:57:28 -0500, Andreas Håkon wrote:
> +static int rtp_mpegtsraw_write_close(AVFormatContext *s)
> +{

ffmpeg bracket style is different.


The bracket style is identical to the rest of the ffmpeg code... !?


> + struct MuxChain *chain = s->priv_data;
> + int ret = AVERROR(ENOMEM);
> + ret = rtp_mpegts_write_header(s);

Why would you assign a value to ret which you immediately discard?


Fixed.


> + avformat_free_context(chain->mpegts_ctx);
> +
> + chain->mpegts_ctx = NULL;

Indentation is inconsistent, throughout the patch BTW.


Fixed.


> + int ret = 0;
> +
> + ret = av_write_frame(chain->rtp_ctx, pkt);

Same here with the assignment.


Fixed too.

Updated patch attached.
A.H.
From df0810cd82002e2741b1fbfc792979a43fa8f85c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20H=C3=A5kon?= <andreas.hakon@protonmail.com>
Date: Sun, 15 Jan 2017 21:53:14 +0100
Subject: [PATCH] avformat: Add rtp_mpegtsraw (MPEG-TS RAW Stream output)

---
 ffmpeg.c                    |  1 +
 libavformat/allformats.c    |  1 +
 libavformat/mpegts.c        |  2 +-
 libavformat/rtpenc.c        |  6 ++++++
 libavformat/rtpenc_mpegts.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 55 insertions(+), 1 deletion(-)

Comments

Moritz Barsnick Jan. 15, 2017, 10:34 p.m. UTC | #1
On Sun, Jan 15, 2017 at 15:59:14 -0500, Andreas Håkon wrote:
> The bracket style is identical to the rest of the ffmpeg code... !?

Is appears you're right and I'm wrong, though I was totally convinced
of the opposite...

Moritz
diff mbox

Patch

diff --git a/ffmpeg.c b/ffmpeg.c
index 6d1e358..7e62538 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3231,6 +3231,7 @@  static int init_output_stream_encode(OutputStream *ost)
         }
         break;
     case AVMEDIA_TYPE_DATA:
+        av_log(NULL, AV_LOG_TRACE, "Using bitstream with codec %s\n", avcodec_get_name(enc_ctx->codec_id));
         break;
     default:
         abort();
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a79b75..b58e178 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -269,6 +269,7 @@  void av_register_all(void)
     REGISTER_MUXDEMUX(RSO,              rso);
     REGISTER_MUXDEMUX(RTP,              rtp);
     REGISTER_MUXER   (RTP_MPEGTS,       rtp_mpegts);
+    REGISTER_MUXER   (RTP_MPEGTSRAW,    rtp_mpegtsraw);
     REGISTER_MUXDEMUX(RTSP,             rtsp);
     REGISTER_DEMUXER (SAMI,             sami);
     REGISTER_MUXDEMUX(SAP,              sap);
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 0aa0ad7..2c23a05 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2663,7 +2663,7 @@  static int mpegts_read_header(AVFormatContext *s)
             return AVERROR(ENOMEM);
         avpriv_set_pts_info(st, 60, 1, 27000000);
         st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
-        st->codecpar->codec_id   = AV_CODEC_ID_MPEG2TS;
+        st->codecpar->codec_id   = AV_CODEC_ID_BIN_DATA;
 
         /* we iterate until we find two PCRs to estimate the bitrate */
         pcr_pid    = -1;
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index efa63a5..e465501 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -82,6 +82,7 @@  static int is_supported(enum AVCodecID id)
     case AV_CODEC_ID_MJPEG:
     case AV_CODEC_ID_SPEEX:
     case AV_CODEC_ID_OPUS:
+    case AV_CODEC_ID_BIN_DATA:
         return 1;
     default:
         return 0;
@@ -160,6 +161,7 @@  static int rtp_write_header(AVFormatContext *s1)
         avpriv_set_pts_info(st, 32, 1, 90000);
     }
     s->buf_ptr = s->buf;
+    av_log(s1, AV_LOG_TRACE, "Using RTP muxer with codec %s\n", avcodec_get_name(st->codecpar->codec_id));
     switch(st->codecpar->codec_id) {
     case AV_CODEC_ID_MP2:
     case AV_CODEC_ID_MP3:
@@ -571,6 +573,7 @@  static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
         ff_rtp_send_amr(s1, pkt->data, size);
         break;
     case AV_CODEC_ID_MPEG2TS:
+    case AV_CODEC_ID_BIN_DATA:
         rtp_send_mpegts_raw(s1, pkt->data, size);
         break;
     case AV_CODEC_ID_DIRAC:
@@ -624,6 +627,9 @@  static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
         /* Intentional fallthrough */
     default:
         /* better than nothing : send the codec raw data */
+        av_log(s1, AV_LOG_WARNING,
+               "RTP output is unsupported with codec %s\n",
+               avcodec_get_name(st->codecpar->codec_id));
         rtp_send_raw(s1, pkt->data, size);
         break;
     }
diff --git a/libavformat/rtpenc_mpegts.c b/libavformat/rtpenc_mpegts.c
index 7af02e0..0e5a61a 100644
--- a/libavformat/rtpenc_mpegts.c
+++ b/libavformat/rtpenc_mpegts.c
@@ -143,6 +143,41 @@  static int rtp_mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
     return ret;
 }
 
+static int rtp_mpegtsraw_write_close(AVFormatContext *s)
+{
+    rtp_mpegts_write_close(s);
+    return 0;
+}
+
+static int rtp_mpegtsraw_write_header(AVFormatContext *s)
+{
+    struct MuxChain *chain = s->priv_data;
+    int ret;
+
+    ret = rtp_mpegts_write_header(s);
+    if (ret < 0)
+        return ret;
+
+    if (chain->mpegts_ctx) {
+        av_write_trailer(chain->mpegts_ctx);
+        ffio_free_dyn_buf(&chain->mpegts_ctx->pb);
+        avformat_free_context(chain->mpegts_ctx);
+        chain->mpegts_ctx = NULL;
+    }
+
+    return ret;
+}
+
+static int rtp_mpegtsraw_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    struct MuxChain *chain = s->priv_data;
+    int ret;
+
+    ret = av_write_frame(chain->rtp_ctx, pkt);
+
+    return ret;
+}
+
 AVOutputFormat ff_rtp_mpegts_muxer = {
     .name              = "rtp_mpegts",
     .long_name         = NULL_IF_CONFIG_SMALL("RTP/mpegts output format"),
@@ -153,3 +188,14 @@  AVOutputFormat ff_rtp_mpegts_muxer = {
     .write_packet      = rtp_mpegts_write_packet,
     .write_trailer     = rtp_mpegts_write_close,
 };
+
+AVOutputFormat ff_rtp_mpegtsraw_muxer = {
+    .name              = "rtp_mpegtsraw",
+    .long_name         = NULL_IF_CONFIG_SMALL("RTP/mpegts RAW-Stream output format"),
+    .priv_data_size    = sizeof(struct MuxChain),
+    .audio_codec       = AV_CODEC_ID_AAC,
+    .video_codec       = AV_CODEC_ID_MPEG4,
+    .write_header      = rtp_mpegtsraw_write_header,
+    .write_packet      = rtp_mpegtsraw_write_packet,
+    .write_trailer     = rtp_mpegtsraw_write_close,
+};