[libbluray-devel] m2ts_filter: cut also PG/IG strems

hpi1 git at videolan.org
Mon Aug 18 12:09:37 CEST 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Aug 18 12:12:21 2014 +0300| [30c0b5cc58c75189f460b9be6942f2e5916f9e49] | committer: hpi1

m2ts_filter: cut also PG/IG strems

Fixes some main path embedded HDMV menus.

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=30c0b5cc58c75189f460b9be6942f2e5916f9e49
---

 ChangeLog                            |    1 +
 src/libbluray/bluray.c               |    3 ++-
 src/libbluray/decoders/m2ts_filter.c |   28 +++++++++++++++++++++++-----
 src/libbluray/decoders/m2ts_filter.h |    3 ++-
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 299d997..542900d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Fix some main path embedded HDMV menus.
 - Fix missing BD_EVENT_ERROR when BD-J is not supported.
 
 2014-08-03: Version 0.6.1
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index fa6d62c..8477f60 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -580,7 +580,8 @@ static int _open_m2ts(BLURAY *bd, BD_STREAM *st)
 
                 st->m2ts_filter = m2ts_filter_init((int64_t)st->clip->in_time << 1,
                                                    (int64_t)st->clip->out_time << 1,
-                                                   stn->num_video, stn->num_audio);
+                                                   stn->num_video, stn->num_audio,
+                                                   stn->num_ig, stn->num_pg);
 
                 _update_clip_psrs(bd, st->clip);
 
diff --git a/src/libbluray/decoders/m2ts_filter.c b/src/libbluray/decoders/m2ts_filter.c
index 59be42c..dfc462e 100644
--- a/src/libbluray/decoders/m2ts_filter.c
+++ b/src/libbluray/decoders/m2ts_filter.c
@@ -49,7 +49,8 @@ struct m2ts_filter_s
 };
 
 M2TS_FILTER *m2ts_filter_init(int64_t in_pts, int64_t out_pts,
-                              unsigned num_video, unsigned num_audio)
+                              unsigned num_video, unsigned num_audio,
+                              unsigned num_ig, unsigned num_pg)
 {
     M2TS_FILTER *p = calloc(1, sizeof(*p));
 
@@ -59,8 +60,8 @@ M2TS_FILTER *m2ts_filter_init(int64_t in_pts, int64_t out_pts,
 
         p->in_pts   = in_pts;
         p->out_pts  = out_pts;
-        p->wipe_pid = calloc(num_audio + num_video + 1, sizeof(uint16_t));
-        p->pass_pid = calloc(num_audio + num_video + 1, sizeof(uint16_t));
+        p->wipe_pid = calloc(num_audio + num_video + num_ig + num_pg + 1, sizeof(uint16_t));
+        p->pass_pid = calloc(num_audio + num_video + num_ig + num_pg + 1, sizeof(uint16_t));
         if (!p->pass_pid || !p->wipe_pid) {
             m2ts_filter_close(&p);
             return NULL;
@@ -74,6 +75,12 @@ M2TS_FILTER *m2ts_filter_init(int64_t in_pts, int64_t out_pts,
         for (ii = 0; ii < num_audio; ii++) {
             pid[npid++] = 0x1100 + ii;
         }
+        for (ii = 0; ii < num_ig; ii++) {
+            pid[npid++] = 0x1400 + ii;
+        }
+        for (ii = 0; ii < num_pg; ii++) {
+            pid[npid++] = 0x1200 + ii;
+        }
     }
 
     return p;
@@ -218,14 +225,25 @@ static int _filter_es_pts(M2TS_FILTER *p, const uint8_t *buf, uint16_t pid)
         }
     }
     if (p->out_pts >= 0) {
-
+        /*
+         * Note: we can't compare against in_pts here (after passing it once):
+         * PG / IG streams can have timestamps before in_time (except for composition segments), and those are valid.
+         */
         if (_pid_in_list(p->pass_pid, pid)) {
 
             int64_t pts = _es_timestamp(buf + 4 + payload_offset, 188 - payload_offset);
-            if (pts > p->out_pts) {
+            if (pts >= p->out_pts) {
+                /*
+                 * audio/video streams are cutted after out_time (unit with pts==out_time is included in the clip).
+                 * PG/IG streams are cutted before out_time (unit with pts==out_time is dropped out).
+                 */
+                if (pts > p->out_pts ||
+                    (pid >= 0x1200 && pid < 0x1300 /* PG */) ||
+                    (pid >= 0x1400 && pid < 0x1500 /* IG */)) {
                 M2TS_TRACE("Pid 0x%04x passed OUT timestamp %"PRId64" (pts %"PRId64") -> start wiping\n", pid, p->out_pts, pts);
                 _remove_pid(p->pass_pid, pid);
                 _add_pid(p->wipe_pid, pid);
+                }
             }
         }
     }
diff --git a/src/libbluray/decoders/m2ts_filter.h b/src/libbluray/decoders/m2ts_filter.h
index 924c2b9..d84e352 100644
--- a/src/libbluray/decoders/m2ts_filter.h
+++ b/src/libbluray/decoders/m2ts_filter.h
@@ -32,7 +32,8 @@
 typedef struct m2ts_filter_s M2TS_FILTER;
 
 BD_PRIVATE M2TS_FILTER *m2ts_filter_init(int64_t in_pts, int64_t out_pts,
-                                         unsigned num_video, unsigned num_audio);
+                                         unsigned num_video, unsigned num_audio,
+                                         unsigned num_ig, unsigned num_pg);
 BD_PRIVATE void         m2ts_filter_close(M2TS_FILTER **);
 
 /*



More information about the libbluray-devel mailing list