[vlc-commits] demux: asf: discard duplicate payloads

Francois Cartegnie git at videolan.org
Tue Nov 17 13:13:37 CET 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Nov  5 17:30:55 2020 +0100| [ff91d2c89e3d013abf6718b1eadbbf1a9292a44b] | committer: Francois Cartegnie

demux: asf: discard duplicate payloads

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ff91d2c89e3d013abf6718b1eadbbf1a9292a44b
---

 modules/demux/asf/asf.c       |  3 +++
 modules/demux/asf/asfpacket.c | 40 ++++++++++++++++++++++++++++++++++++----
 modules/demux/asf/asfpacket.h |  9 +++++++++
 modules/demux/mp4/mp4.c       |  1 +
 4 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/modules/demux/asf/asf.c b/modules/demux/asf/asf.c
index 0e58c53732..e16f621bc8 100644
--- a/modules/demux/asf/asf.c
+++ b/modules/demux/asf/asf.c
@@ -178,6 +178,7 @@ static int Open( vlc_object_t * p_this )
     p_sys->packet_sys.priv = p_demux;
     p_sys->packet_sys.s = p_demux->s;
     p_sys->packet_sys.logger = p_demux->obj.logger;
+    p_sys->packet_sys.b_deduplicate = false;
     p_sys->packet_sys.pf_doskip = Packet_DoSkip;
     p_sys->packet_sys.pf_send = Packet_Enqueue;
     p_sys->packet_sys.pf_gettrackinfo = Packet_GetTrackInfo;
@@ -906,6 +907,8 @@ static int DemuxInit( demux_t *p_demux )
         tk->p_es = NULL;
         tk->queue.p_first = NULL;
         tk->queue.pp_last = &tk->queue.p_first;
+        tk->info.i_pkt = 0;
+        tk->info.i_pktcount = 0;
 
         if ( !b_mms )
         {
diff --git a/modules/demux/asf/asfpacket.c b/modules/demux/asf/asfpacket.c
index 1543e71060..2d009db3b4 100644
--- a/modules/demux/asf/asfpacket.c
+++ b/modules/demux/asf/asfpacket.c
@@ -77,10 +77,37 @@ static uint32_t SkipBytes( stream_t *s, uint32_t i_bytes )
 }
 
 static int DemuxSubPayload( asf_packet_sys_t *p_packetsys,
-                            uint8_t i_stream_number, block_t **pp_frame,
+                            uint8_t i_stream_number, asf_track_info_t *p_tkinfo,
                             uint32_t i_sub_payload_data_length, vlc_tick_t i_pts, vlc_tick_t i_dts,
-                            uint32_t i_media_object_offset, bool b_keyframe, bool b_ignore_pts )
+                            uint32_t i_media_object_number, uint32_t i_media_object_offset,
+                            bool b_keyframe, bool b_ignore_pts )
 {
+    block_t **pp_frame = &p_tkinfo->p_frame;
+
+    if( p_packetsys->b_deduplicate )
+    {
+        for(size_t i=0; i<p_tkinfo->i_pktcount; i++)
+        {
+            if(p_tkinfo->prev[i].media_number == i_media_object_number &&
+               p_tkinfo->prev[i].media_offset == i_media_object_offset)
+            {
+                vlc_debug(p_packetsys->logger, "dropping duplicate num %"PRIu32" off %"PRIu32,
+                          i_media_object_number , i_media_object_offset);
+                ssize_t skipped = vlc_stream_Read( p_packetsys->s, NULL, i_sub_payload_data_length );
+                return ( skipped >= 0 && (uint32_t) skipped == i_sub_payload_data_length ) ? 0 : -1;
+            }
+        }
+
+        unsigned dedupindex;
+        if( p_tkinfo->i_pktcount < ASFPACKET_DEDUPLICATE )
+            dedupindex = p_tkinfo->i_pkt = p_tkinfo->i_pktcount++;
+        else
+            dedupindex = (++p_tkinfo->i_pkt) % ASFPACKET_DEDUPLICATE;
+
+        p_tkinfo->prev[dedupindex].media_number = i_media_object_number;
+        p_tkinfo->prev[dedupindex].media_offset = i_media_object_offset;
+    }
+
     /* FIXME I don't use i_media_object_number, sould I ? */
     if( *pp_frame && i_media_object_offset == 0 )
     {
@@ -342,9 +369,10 @@ static int DemuxPayload(asf_packet_sys_t *p_packetsys, asf_packet_t *pkt, int i_
             i_payload_dts -= VLC_TICK_FROM_MSFTIME(p_tkinfo->p_sp->i_time_offset);
 
         if ( i_sub_payload_data_length &&
-             DemuxSubPayload( p_packetsys, i_stream_number, &p_tkinfo->p_frame,
+             DemuxSubPayload( p_packetsys, i_stream_number, p_tkinfo,
                               i_sub_payload_data_length, i_payload_pts, i_payload_dts,
-                              i_media_object_offset, b_packet_keyframe, b_ignore_pts ) < 0)
+                              i_media_object_number, i_media_object_offset,
+                              b_packet_keyframe, b_ignore_pts ) < 0)
             return -1;
 
         if ( pkt->left > pkt->i_skip + i_sub_payload_data_length )
@@ -539,6 +567,8 @@ void ASFPacketTrackInit( asf_track_info_t *p_ti )
     p_ti->p_esp = NULL;
     p_ti->p_sp = NULL;
     p_ti->p_frame = NULL;
+    p_ti->i_pktcount = 0;
+    p_ti->i_pkt = 0;
 }
 
 void ASFPacketTrackReset( asf_track_info_t *p_ti )
@@ -546,4 +576,6 @@ void ASFPacketTrackReset( asf_track_info_t *p_ti )
     if( p_ti->p_frame )
         block_ChainRelease( p_ti->p_frame );
     p_ti->p_frame = NULL;
+    p_ti->i_pktcount = 0;
+    p_ti->i_pkt = 0;
 }
diff --git a/modules/demux/asf/asfpacket.h b/modules/demux/asf/asfpacket.h
index af1a029d81..5dae1af491 100644
--- a/modules/demux/asf/asfpacket.h
+++ b/modules/demux/asf/asfpacket.h
@@ -28,6 +28,7 @@
 #include "libasf.h"
 
 #define ASFPACKET_PREROLL_FROM_CURRENT -1
+#define ASFPACKET_DEDUPLICATE 8
 
 typedef struct
 {
@@ -35,6 +36,13 @@ typedef struct
     asf_object_stream_properties_t *p_sp;
     asf_object_extended_stream_properties_t *p_esp;
     int i_cat;
+    struct
+    {
+        unsigned media_number;
+        unsigned media_offset;
+    } prev[ASFPACKET_DEDUPLICATE];
+    unsigned i_pkt;
+    unsigned i_pktcount;
 } asf_track_info_t;
 
 typedef struct asf_packet_sys_s asf_packet_sys_t;
@@ -48,6 +56,7 @@ struct asf_packet_sys_s
     /* global stream info */
     vlc_tick_t *pi_preroll;
     vlc_tick_t *pi_preroll_start;
+    bool b_deduplicate; /* Flip4mac repeats data object payloads */
 
     /* callbacks */
     void (*pf_send)(asf_packet_sys_t *, uint8_t, block_t **);
diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index a496f52c12..55a7b8a480 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -1169,6 +1169,7 @@ static int Open( vlc_object_t * p_this )
     p_sys->asfpacketsys.logger = p_demux->obj.logger;
     p_sys->asfpacketsys.pi_preroll = &p_sys->i_preroll;
     p_sys->asfpacketsys.pi_preroll_start = &p_sys->i_preroll_start;
+    p_sys->asfpacketsys.b_deduplicate = true;
     p_sys->asfpacketsys.pf_doskip = NULL;
     p_sys->asfpacketsys.pf_send = MP4ASF_Send;
     p_sys->asfpacketsys.pf_gettrackinfo = MP4ASF_GetTrackInfo;



More information about the vlc-commits mailing list