From ca49904d3171e458087e6ae92a1db482aca88d81 Mon Sep 17 00:00:00 2001 From: TangoCash Date: Wed, 1 Nov 2017 00:25:04 +0100 Subject: [PATCH] gstreamer playback - get real apid from TS --- libarmbox/Makefile.am | 3 ++- libarmbox/playback_gst.cpp | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/libarmbox/Makefile.am b/libarmbox/Makefile.am index ee99e6a..065cd26 100644 --- a/libarmbox/Makefile.am +++ b/libarmbox/Makefile.am @@ -15,7 +15,8 @@ AM_LDFLAGS = \ @SWRESAMPLE_LIBS@ \ -lpthread -lasound -lrt \ -lgstreamer-1.0 \ - -lgsttag-1.0 + -lgsttag-1.0 \ + -lgstmpegts-1.0 libarmbox_la_SOURCES = \ hardware_caps.c \ diff --git a/libarmbox/playback_gst.cpp b/libarmbox/playback_gst.cpp index 390ffc5..bc9f0b2 100644 --- a/libarmbox/playback_gst.cpp +++ b/libarmbox/playback_gst.cpp @@ -50,6 +50,7 @@ extern cDemux * videoDemux; #include #include +#include #include typedef enum @@ -76,6 +77,9 @@ gchar * uri = NULL; GstTagList * m_stream_tags = NULL; static int end_eof = 0; #define HTTP_TIMEOUT 30 +// taken from record.h +#define REC_MAX_APIDS 20 +int real_apids[REC_MAX_APIDS]; gint match_sinktype(const GValue *velement, const gchar *type) { @@ -83,6 +87,25 @@ gint match_sinktype(const GValue *velement, const gchar *type) return strcmp(g_type_name(G_OBJECT_TYPE(element)), type); } +void processMpegTsSection(GstMpegtsSection* section) +{ + for (unsigned int i = 0; i < REC_MAX_APIDS; i++) { + real_apids[i] = 0; + } + int cnt = 0; + if (section->section_type == GST_MPEGTS_SECTION_PMT) { + const GstMpegtsPMT* pmt = gst_mpegts_section_get_pmt(section); + for (guint i = 0; i < pmt->streams->len; ++i) { + const GstMpegtsPMTStream* stream = static_cast(g_ptr_array_index(pmt->streams, i)); + if (stream->stream_type == 0x05 || stream->stream_type >= 0x80) { + lt_info_c( "%s:%s Audio Stream pid: %d\n", FILENAME, __FUNCTION__, stream->pid); + real_apids[cnt] = stream->pid; + cnt++; + } + } + } +} + void playbinNotifySource(GObject *object, GParamSpec *unused, gpointer user_data) { GstElement *source = NULL; @@ -269,7 +292,14 @@ GstBusSyncReply Gst_bus_call(GstBus * bus, GstMessage *msg, gpointer user_data) lt_debug_c( "%s:%s - GST_MESSAGE_INFO: update info tags\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? break; } - + case GST_MESSAGE_ELEMENT: + { + GstMpegtsSection* section = gst_message_parse_mpegts_section(msg); + if (section) { + processMpegTsSection(section); + gst_mpegts_section_unref(section); + } + } case GST_MESSAGE_STATE_CHANGED: { if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin)) @@ -853,7 +883,7 @@ void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *nu for (i = 0; i < n_audio; i++) { // apids - apids[i]=i; + apids[i]= real_apids[i] ? real_apids[i] : i; GstPad * pad = 0; g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad);