[vlc-commits] [Git][videolan/vlc][master] 2 commits: rtp/mpeg12: add audio/MPA MPEG 1/2 Audio payload format

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Fri Nov 26 16:11:40 UTC 2021



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
f67701fe by Rémi Denis-Courmont at 2021-11-26T15:57:05+00:00
rtp/mpeg12: add audio/MPA MPEG 1/2 Audio payload format

- - - - -
a38f2a13 by Rémi Denis-Courmont at 2021-11-26T15:57:05+00:00
rtp: remove hard-coded MPA parser

- - - - -


3 changed files:

- modules/access/rtp/Makefile.am
- + modules/access/rtp/mpeg12.c
- modules/access/rtp/rtpfmt.c


Changes:

=====================================
modules/access/rtp/Makefile.am
=====================================
@@ -31,7 +31,10 @@ endif
 # RTP payload parser plugins
 rtpparsedir = $(accessdir)/rtp
 rtpparse_LTLIBRARIES = \
+	librtp_mpeg12_plugin.la \
 	librtp_pcm_plugin.la
 
+librtp_mpeg12_plugin_la_SOURCES = access/rtp/mpeg12.c
+
 librtp_pcm_plugin_la_SOURCES = access/rtp/pcm.c
 librtp_pcm_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/access/rtp


=====================================
modules/access/rtp/mpeg12.c
=====================================
@@ -0,0 +1,130 @@
+/**
+ * @file mpeg12.c
+ * @brief Real-Time Protocol MPEG 1/2 payload format parser
+ */
+/*****************************************************************************
+ * Copyright © 2021 Rémi Denis-Courmont
+ *
+ * This library 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.1
+ * of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ ****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <vlc_common.h>
+#include <vlc_block.h>
+#include <vlc_es.h>
+#include <vlc_plugin.h>
+#include <vlc_strings.h>
+
+#include "rtp.h"
+
+struct rtp_mpa {
+    size_t offset;
+    struct vlc_rtp_es *es;
+};
+
+static void *rtp_mpa_init(struct vlc_rtp_pt *pt)
+{
+    struct rtp_mpa *sys = malloc(sizeof (*sys));
+    if (unlikely(sys == NULL))
+        return NULL;
+
+    es_format_t fmt;
+
+    es_format_Init(&fmt, AUDIO_ES, VLC_CODEC_MPGA);
+    fmt.b_packetized = false;
+    sys->es = vlc_rtp_pt_request_es(pt, &fmt);
+    return sys;
+}
+
+static void rtp_mpa_destroy(struct vlc_rtp_pt *pt, void *data)
+{
+    struct rtp_mpa *sys = data;
+
+    if (unlikely(sys == NULL))
+        return;
+
+    vlc_rtp_es_destroy(sys->es);
+    free(sys);
+    (void) pt;
+}
+
+static void rtp_mpa_decode(struct vlc_rtp_pt *pt, void *data, block_t *block)
+{
+    struct vlc_logger *log = pt->opaque;
+    struct rtp_mpa *sys = data;
+
+    if (unlikely(sys == NULL))
+        goto drop;
+    if (block->i_buffer < 4) {
+        vlc_warning(log, "malformatted packet (%zu bytes)", block->i_buffer);
+        goto drop;
+    }
+
+    /* 2 bytes unused, 2 bytes fragment offset, then MPEG frame fragment */
+    uint_fast16_t offset = GetWBE(block->p_buffer + 2);
+
+    block->p_buffer += 4;
+    block->i_buffer -= 4;
+
+    if (offset != 0 && offset != sys->offset) {
+        /* Discontinuous offset, probably packet loss. */
+        vlc_warning(log, "offset discontinuity: expected %zu, got %"PRIuFAST16,
+                    sys->offset, offset);
+        block->i_flags |= BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED;
+    }
+
+    sys->offset = offset + block->i_buffer;
+    /* This payload format does not flag the last fragment of a frame,
+     * so the MPGA header must be parsed to figure out the frame size and end
+     * (without introducing a one-packet delay).
+     * We let the packetiser handle it rather than duplicate the logic. */
+    vlc_rtp_es_send(sys->es, block);
+    return;
+
+drop:
+    block_Release(block);
+}
+
+static const struct vlc_rtp_pt_operations rtp_mpa_ops = {
+    NULL, rtp_mpa_init, rtp_mpa_destroy, rtp_mpa_decode,
+};
+
+static int rtp_mpeg12_open(vlc_object_t *obj, struct vlc_rtp_pt *pt,
+                        const struct vlc_sdp_pt *desc)
+{
+    pt->opaque = vlc_object_logger(obj);
+
+    if (vlc_ascii_strcasecmp(desc->name, "MPA") == 0) /* RFC2250 */
+        pt->ops = &rtp_mpa_ops;
+    else
+        return VLC_ENOTSUP;
+
+    return VLC_SUCCESS;
+}
+
+vlc_module_begin()
+    set_shortname(N_("RTP MPEG"))
+    set_description(N_("RTP MPEG-1/2 payload parser"))
+    set_category(CAT_INPUT)
+    set_subcategory(SUBCAT_INPUT_DEMUX)
+    set_rtp_parser_callback(rtp_mpeg12_open)
+    add_shortcut("audio/MPA")
+vlc_module_end()


=====================================
modules/access/rtp/rtpfmt.c
=====================================
@@ -89,37 +89,6 @@ static const struct vlc_rtp_pt_operations rtp_audio_qcelp = {
     NULL, qcelp_init, codec_destroy, codec_decode,
 };
 
-/* PT=14
- * MPA: MPEG Audio (RFC2250, §3.4)
- */
-static void *mpa_init(struct vlc_rtp_pt *pt)
-{
-    es_format_t fmt;
-
-    es_format_Init (&fmt, AUDIO_ES, VLC_CODEC_MPGA);
-    fmt.b_packetized = false;
-    return vlc_rtp_pt_request_es(pt, &fmt);
-}
-
-static void mpa_decode(struct vlc_rtp_pt *pt, void *data, block_t *block)
-{
-    if (block->i_buffer < 4)
-    {
-        block_Release (block);
-        return;
-    }
-
-    block->i_buffer -= 4; /* 32-bits RTP/MPA header */
-    block->p_buffer += 4;
-    block->i_dts = VLC_TICK_INVALID;
-    vlc_rtp_es_send(data, block);
-    (void) pt;
-}
-
-static const struct vlc_rtp_pt_operations rtp_audio_mpa = {
-    NULL, mpa_init, codec_destroy, mpa_decode,
-};
-
 /* PT=32
  * MPV: MPEG Video (RFC2250, §3.5)
  */
@@ -218,8 +187,6 @@ static struct vlc_rtp_pt *vlc_rtp_pt_create(vlc_object_t *obj,
             pt->ops = &rtp_audio_gsm;
         else if (strcmp(desc->name, "QCELP") == 0)
             pt->ops = &rtp_audio_qcelp;
-        else if (strcmp(desc->name, "MPA") == 0)
-            pt->ops = &rtp_audio_mpa;
     } else if (strcmp(desc->media->type, "video") == 0) {
         if (strcmp(desc->name, "MPV") == 0)
             pt->ops = &rtp_video_mpv;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4955734f1c3559a2a1315fc674a1d094c04d9692...a38f2a139ee64df6b54fba83489f660eee1f9d38

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4955734f1c3559a2a1315fc674a1d094c04d9692...a38f2a139ee64df6b54fba83489f660eee1f9d38
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list