[MPlayer-cvslog] r25386 - in trunk/libmpdemux: demuxer.c demuxer.h

ulion subversion at mplayerhq.hu
Thu Dec 13 13:51:05 CET 2007


Author: ulion
Date: Thu Dec 13 13:51:05 2007
New Revision: 25386

Log:
Add demuxer functions for chapter feature.


Modified:
   trunk/libmpdemux/demuxer.c
   trunk/libmpdemux/demuxer.h

Modified: trunk/libmpdemux/demuxer.c
==============================================================================
--- trunk/libmpdemux/demuxer.c	(original)
+++ trunk/libmpdemux/demuxer.c	Thu Dec 13 13:51:05 2007
@@ -1216,3 +1216,74 @@ int demuxer_seek_chapter(demuxer_t *demu
         return current;
     }
 }
+
+int demuxer_get_current_chapter(demuxer_t *demuxer) {
+    int chapter = -1;
+    if (!demuxer->num_chapters || !demuxer->chapters) {
+        if (stream_control(demuxer->stream, STREAM_CTRL_GET_CURRENT_CHAPTER,
+                           &chapter) == STREAM_UNSUPPORTED)
+            chapter = -1;
+    }
+    else {
+        sh_video_t *sh_video = demuxer->video->sh;
+        sh_audio_t *sh_audio = demuxer->audio->sh;
+        uint64_t now;
+        now = (sh_video ? sh_video->pts : (sh_audio?sh_audio->pts:0))*1000+0.5;
+        for (chapter = demuxer->num_chapters - 1; chapter >= 0; --chapter) {
+            if (demuxer->chapters[chapter].start <= now)
+                break;
+        }
+    }
+    return chapter;
+}
+
+char *demuxer_chapter_name(demuxer_t *demuxer, int chapter) {
+    if (demuxer->num_chapters && demuxer->chapters) {
+        if (chapter >=0 && chapter < demuxer->num_chapters &&
+                demuxer->chapters[chapter].name)
+            return strdup(demuxer->chapters[chapter].name);
+    }
+    return NULL;
+}
+
+char *demuxer_chapter_display_name(demuxer_t *demuxer, int chapter) {
+    char *chapter_name = demuxer_chapter_name(demuxer, chapter);
+    if (chapter_name) {
+        char *tmp = malloc(strlen(chapter_name) + 14);
+        snprintf(tmp, 63, "(%d) %s", chapter + 1, chapter_name);
+        free(chapter_name); 
+        return tmp;
+    }
+    else {
+        int chapter_num = demuxer_chapter_count(demuxer);
+        char tmp[30];
+        if (chapter_num <= 0)
+            sprintf(tmp, "(%d)", chapter + 1);
+        else
+            sprintf(tmp, "(%d) of %d", chapter + 1, chapter_num);
+        return strdup(tmp);
+    }
+}
+
+float demuxer_chapter_time(demuxer_t *demuxer, int chapter, float *end) {
+    if (demuxer->num_chapters && demuxer->chapters && chapter >= 0
+            && chapter < demuxer->num_chapters) {
+        if (end)
+            *end = demuxer->chapters[chapter].end / 1000.0;
+        return demuxer->chapters[chapter].start / 1000.0;
+    }
+    return -1.0;
+}
+
+int demuxer_chapter_count(demuxer_t *demuxer) {
+    if (!demuxer->num_chapters || !demuxer->chapters) {
+        int num_chapters = 0;
+        if (stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS,
+                           &num_chapters) == STREAM_UNSUPPORTED)
+            num_chapters = 0;
+        return num_chapters;
+    }
+    else
+        return demuxer->num_chapters;
+}
+

Modified: trunk/libmpdemux/demuxer.h
==============================================================================
--- trunk/libmpdemux/demuxer.h	(original)
+++ trunk/libmpdemux/demuxer.h	Thu Dec 13 13:51:05 2007
@@ -387,5 +387,15 @@ extern int get_demuxer_type_from_name(ch
 int demuxer_add_chapter(demuxer_t* demuxer, const char* name, uint64_t start, uint64_t end);
 int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, float *seek_pts, int *num_chapters, char **chapter_name);
 
+/// Get current chapter index if available.
+int demuxer_get_current_chapter(demuxer_t *demuxer);
+/// Get chapter name by index if available.
+char *demuxer_chapter_name(demuxer_t *demuxer, int chapter);
+/// Get chapter display name by index.
+char *demuxer_chapter_display_name(demuxer_t *demuxer, int chapter);
+/// Get chapter start time and end time by index if available.
+float demuxer_chapter_time(demuxer_t *demuxer, int chapter, float *end);
+/// Get total chapter number.
+int demuxer_chapter_count(demuxer_t *demuxer);
 
 #endif /* DEMUXER_H */



More information about the MPlayer-cvslog mailing list