[FFmpeg-soc] [soc]: r4595 - in concat/libavformat: concat.c concatgen.c concatgen.h m3u.c playlist.h

gkovacs subversion at mplayerhq.hu
Sat Jul 4 20:59:56 CEST 2009


Author: gkovacs
Date: Sat Jul  4 20:59:56 2009
New Revision: 4595

Log:
moved format-independent demuxer portions from m3u demuxer into concatgen for future reuse in pls, asx, and xpsf demuxers

Added:
   concat/libavformat/concat.c
   concat/libavformat/concatgen.c
   concat/libavformat/concatgen.h
Modified:
   concat/libavformat/m3u.c
   concat/libavformat/playlist.h

Added: concat/libavformat/concat.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ concat/libavformat/concat.c	Sat Jul  4 20:59:56 2009	(r4595)
@@ -0,0 +1,64 @@
+/*
+ * Standard playlist/concatenation demuxer
+ * Copyright (c) 2009 Geza Kovacs
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "concatgen.h"
+
+/* The ffmpeg codecs we support, and the IDs they have in the file */
+static const AVCodecTag codec_concat_tags[] = {
+    { 0, 0 },
+};
+
+static int concat_probe(AVProbeData *p)
+{
+    // concat demuxer should only be manually constructed in ffmpeg
+    return 0;
+}
+
+static int concat_read_header(AVFormatContext *s,
+                              AVFormatParameters *ap)
+{
+    // PlaylistD should be constructed externally
+    return 0;
+}
+
+
+#if CONFIG_CONCAT_DEMUXER
+AVInputFormat concat_demuxer = {
+    "concat",
+    NULL_IF_CONFIG_SMALL("CONCAT format"),
+    0,
+    concat_probe,
+    concat_read_header,
+    concatgen_read_packet,
+    concatgen_read_close,
+    concatgen_read_seek,
+    concatgen_read_timestamp,
+    NULL, //flags
+    NULL, //extensions
+    NULL, //value
+    concatgen_read_play,
+    concatgen_read_pause,
+    (const AVCodecTag* const []){codec_concat_tags, 0},
+    NULL, //m3u_read_seek2
+    NULL, //metadata_conv
+    NULL, //next
+};
+#endif

Added: concat/libavformat/concatgen.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ concat/libavformat/concatgen.c	Sat Jul  4 20:59:56 2009	(r4595)
@@ -0,0 +1,132 @@
+/*
+ * Generic functions used by playlist/concatenation demuxers
+ * Copyright (c) 2009 Geza Kovacs
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "concatgen.h"
+
+int concatgen_read_packet(AVFormatContext *s,
+                       AVPacket *pkt)
+{
+    int i;
+    int ret;
+    int stream_index;
+    PlaylistD *playld;
+    AVFormatContext *ic;
+    playld = s->priv_data;
+    stream_index = 0;
+    retr:
+    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
+    ret = ic->iformat->read_packet(ic, pkt);
+    if (pkt) {
+        stream_index = pkt->stream_index;
+        ic = playld->pelist[playld->pe_curidxs[stream_index]]->ic;
+    }
+    if (ret >= 0) {
+        if (pkt) {
+            int64_t time_offset = ff_conv_stream_time(ic, pkt->stream_index, playld->time_offsets[pkt->stream_index]);
+            pkt->dts += time_offset;
+            pkt->pts = pkt->dts + 1;
+        }
+    }
+    // TODO switch from AVERROR_EOF to AVERROR_EOS
+    // -32 AVERROR_EOF for avi, -51 for ogg
+    else if (ret < 0 && playld->pe_curidxs[stream_index] < playld->pelist_size - 1) {
+        // TODO account for out-of-sync audio/video by using per-stream offsets
+        // using streams[]->duration slightly overestimates offset
+//        playld->dts_offset += ic->streams[0]->duration;
+        // using streams[]->cur_dts slightly overestimates offset
+//        playld->dts_offset += ic->streams[0]->cur_dts;
+//        playld->dts_offset += playld->dts_prevpacket;
+        printf("switching streams\n");
+        for (i = 0; i < ic->nb_streams && i < playld->time_offsets_size; ++i) {
+            playld->time_offsets[i] += ff_get_duration(ic, i);
+        }
+        ++playld->pe_curidxs[stream_index];
+//        pkt->destruct(pkt);
+        pkt = av_malloc(sizeof(AVPacket));
+//        for (i = 0; i < playld->pe_curidxs_size; ++i) {
+            ff_playlist_populate_context(playld, s, stream_index);
+//        }
+        goto retr;
+    }
+    else {
+        printf("avpacket ret is %d\n", ret);
+    }
+    return ret;
+}
+
+int concatgen_read_seek(AVFormatContext *s,
+                     int stream_index,
+                     int64_t pts,
+                     int flags)
+{
+    PlaylistD *playld;
+    AVFormatContext *ic;
+    playld = s->priv_data;
+    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
+    ic->iformat->read_seek(ic, stream_index, pts, flags);
+}
+
+int concatgen_read_timestamp(AVFormatContext *s,
+                             int stream_index,
+                             int64_t *pos,
+                             int64_t pos_limit)
+{
+    printf("m3u_read_timestamp called\n");
+    PlaylistD *playld;
+    AVFormatContext *ic;
+    playld = s->priv_data;
+    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
+    if (ic->iformat->read_timestamp)
+        return ic->iformat->read_timestamp(ic, stream_index, pos, pos_limit);
+    return 0;
+}
+
+int concatgen_read_close(AVFormatContext *s)
+{
+    printf("m3u_read_close called\n");
+    PlaylistD *playld;
+    AVFormatContext *ic;
+    playld = s->priv_data;
+    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
+    if (ic->iformat->read_close)
+        return ic->iformat->read_close(ic);
+    return 0;
+}
+
+int concatgen_read_play(AVFormatContext *s)
+{
+    printf("m3u_read_play called\n");
+    PlaylistD *playld;
+    AVFormatContext *ic;
+    playld = s->priv_data;
+    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
+    return av_read_play(ic);
+}
+
+int concatgen_read_pause(AVFormatContext *s)
+{
+    printf("m3u_read_pause called\n");
+    PlaylistD *playld;
+    AVFormatContext *ic;
+    playld = s->priv_data;
+    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
+    return av_read_pause(ic);
+}

Added: concat/libavformat/concatgen.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ concat/libavformat/concatgen.h	Sat Jul  4 20:59:56 2009	(r4595)
@@ -0,0 +1,40 @@
+/*
+ * Generic functions used by playlist/concatenation demuxers
+ * Copyright (c) 2009 Geza Kovacs
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _CONCATGEN_H
+#define _CONCATGEN_H
+
+#include "playlist.h"
+
+int concatgen_read_packet(AVFormatContext *s, AVPacket *pkt);
+
+int concatgen_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags);
+
+int concatgen_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos, int64_t pos_limit);
+
+int concatgen_read_close(AVFormatContext *s);
+
+int concatgen_read_play(AVFormatContext *s);
+
+int concatgen_read_pause(AVFormatContext *s);
+
+#endif /* _CONCATGEN_H */
+

Modified: concat/libavformat/m3u.c
==============================================================================
--- concat/libavformat/m3u.c	Sat Jul  4 17:04:59 2009	(r4594)
+++ concat/libavformat/m3u.c	Sat Jul  4 20:59:56 2009	(r4595)
@@ -19,12 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "avformat.h"
-#include "riff.h"
-#include "playlist.h"
-
-/* if we don't know the size in advance */
-#define M3U_UNKNOWN_SIZE ((uint32_t)(~0))
+#include "concatgen.h"
 
 /* The ffmpeg codecs we support, and the IDs they have in the file */
 static const AVCodecTag codec_m3u_tags[] = {
@@ -101,132 +96,22 @@ static int m3u_read_header(AVFormatConte
     return 0;
 }
 
-static int m3u_read_packet(AVFormatContext *s,
-                           AVPacket *pkt)
-{
-    int i;
-    int ret;
-    int stream_index;
-    PlaylistD *playld;
-    AVFormatContext *ic;
-    playld = s->priv_data;
-    stream_index = 0;
-    retr:
-    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
-    ret = ic->iformat->read_packet(ic, pkt);
-    if (pkt) {
-        stream_index = pkt->stream_index;
-        ic = playld->pelist[playld->pe_curidxs[stream_index]]->ic;
-    }
-    if (ret >= 0) {
-        if (pkt) {
-            int64_t time_offset = ff_conv_stream_time(ic, pkt->stream_index, playld->time_offsets[pkt->stream_index]);
-            pkt->dts += time_offset;
-            pkt->pts = pkt->dts + 1;
-        }
-    }
-    // TODO switch from AVERROR_EOF to AVERROR_EOS
-    // -32 AVERROR_EOF for avi, -51 for ogg
-    else if (ret < 0 && playld->pe_curidxs[stream_index] < playld->pelist_size - 1) {
-        // TODO account for out-of-sync audio/video by using per-stream offsets
-        // using streams[]->duration slightly overestimates offset
-//        playld->dts_offset += ic->streams[0]->duration;
-        // using streams[]->cur_dts slightly overestimates offset
-//        playld->dts_offset += ic->streams[0]->cur_dts;
-//        playld->dts_offset += playld->dts_prevpacket;
-        printf("switching streams\n");
-        for (i = 0; i < ic->nb_streams && i < playld->time_offsets_size; ++i) {
-            playld->time_offsets[i] += ff_get_duration(ic, i);
-        }
-        ++playld->pe_curidxs[stream_index];
-//        pkt->destruct(pkt);
-        pkt = av_malloc(sizeof(AVPacket));
-//        for (i = 0; i < playld->pe_curidxs_size; ++i) {
-            ff_playlist_populate_context(playld, s, stream_index);
-//        }
-        goto retr;
-    }
-    else {
-        printf("avpacket ret is %d\n", ret);
-    }
-    return ret;
-}
-
-static int m3u_read_seek(AVFormatContext *s,
-                         int stream_index,
-                         int64_t pts,
-                         int flags)
-{
-    PlaylistD *playld;
-    AVFormatContext *ic;
-    playld = s->priv_data;
-    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
-    ic->iformat->read_seek(ic, stream_index, pts, flags);
-}
-
-static int m3u_read_play(AVFormatContext *s)
-{
-    printf("m3u_read_play called\n");
-    PlaylistD *playld;
-    AVFormatContext *ic;
-    playld = s->priv_data;
-    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
-    return av_read_play(ic);
-}
-
-static int m3u_read_pause(AVFormatContext *s)
-{
-    printf("m3u_read_pause called\n");
-    PlaylistD *playld;
-    AVFormatContext *ic;
-    playld = s->priv_data;
-    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
-    return av_read_pause(ic);
-}
-
-static int m3u_read_close(AVFormatContext *s)
-{
-    printf("m3u_read_close called\n");
-    PlaylistD *playld;
-    AVFormatContext *ic;
-    playld = s->priv_data;
-    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
-    if (ic->iformat->read_close)
-        return ic->iformat->read_close(ic);
-    return 0;
-}
-
-static int m3u_read_timestamp(AVFormatContext *s,
-                              int stream_index,
-                              int64_t *pos,
-                              int64_t pos_limit)
-{
-    printf("m3u_read_timestamp called\n");
-    PlaylistD *playld;
-    AVFormatContext *ic;
-    playld = s->priv_data;
-    ic = playld->pelist[playld->pe_curidxs[0]]->ic;
-    if (ic->iformat->read_timestamp)
-        return ic->iformat->read_timestamp(ic, stream_index, pos, pos_limit);
-    return 0;
-}
-
-#if CONFIG_M3U_DEMUXER
+#if CONFIG_CONCAT_DEMUXER
 AVInputFormat m3u_demuxer = {
     "m3u",
     NULL_IF_CONFIG_SMALL("M3U format"),
     0,
     m3u_probe,
     m3u_read_header,
-    m3u_read_packet,
-    m3u_read_close, //m3u_read_close
-    m3u_read_seek,
-    m3u_read_timestamp, //m3u_read_timestamp
+    concatgen_read_packet,
+    concatgen_read_close,
+    concatgen_read_seek,
+    concatgen_read_timestamp,
     NULL, //flags
     NULL, //extensions
     NULL, //value
-    m3u_read_play,
-    m3u_read_pause,
+    concatgen_read_play,
+    concatgen_read_pause,
     (const AVCodecTag* const []){codec_m3u_tags, 0},
     NULL, //m3u_read_seek2
     NULL, //metadata_conv

Modified: concat/libavformat/playlist.h
==============================================================================
--- concat/libavformat/playlist.h	Sat Jul  4 17:04:59 2009	(r4594)
+++ concat/libavformat/playlist.h	Sat Jul  4 20:59:56 2009	(r4595)
@@ -19,6 +19,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#ifndef _PLAYLIST_H
+#define _PLAYLIST_H
+
+#include "avformat.h"
+#include "riff.h"
 
 typedef struct PlayElem {
     AVFormatContext *ic;
@@ -64,3 +69,5 @@ int64_t ff_conv_stream_time(AVFormatCont
 int64_t ff_conv_base_time(AVFormatContext *ic, int stream_index, int64_t stream_duration);
 
 int64_t ff_get_duration(AVFormatContext *ic, int stream_index);
+
+#endif /* _PLAYLIST_H */


More information about the FFmpeg-soc mailing list