WTV muxer (1_extract_wtv_common_code.patch)
authorzhentan feng <spyfeng@gmail.com>
Tue, 23 Aug 2011 13:40:58 +0000 (21:40 +0800)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 7 Sep 2011 23:55:07 +0000 (01:55 +0200)
libavformat/wtv.c
libavformat/wtv.h
libavformat/wtvdec.c

index 926f924..7a29309 100644 (file)
@@ -39,6 +39,37 @@ const ff_asf_guid ff_mediatype_video =
 const ff_asf_guid ff_format_none =
     {0xD6,0x17,0x64,0x0F,0x18,0xC3,0xD0,0x11,0xA4,0x3F,0x00,0xA0,0xC9,0x22,0x31,0x96};
 
+/* declare utf16le strings */
+#define _ , 0,
+const uint8_t ff_timeline_le16[] =
+    {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e', 0};
+const uint8_t ff_timeline_table_0_entries_Events_le16[] =
+    {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e'_'.'_'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'E'_'v'_'e'_'n'_'t'_'s', 0};
+const uint8_t ff_table_0_entries_legacy_attrib_le16[] =
+    {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0};
+const uint8_t ff_table_0_entries_time_le16[] =
+    {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'t'_'i'_'m'_'e', 0};
+#undef _
+
+const ff_asf_guid ff_DSATTRIB_TRANSPORT_PROPERTIES =
+    {0x12,0xF6,0x22,0xB6,0xAD,0x47,0x71,0x46,0xAD,0x6C,0x05,0xA9,0x8E,0x65,0xDE,0x3A};
+const ff_asf_guid ff_metadata_guid =
+    {0x5A,0xFE,0xD7,0x6D,0xC8,0x1D,0x8F,0x4A,0x99,0x22,0xFA,0xB1,0x1C,0x38,0x14,0x53};
+const ff_asf_guid ff_stream2_guid =
+    {0xA2,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
+
+/* Media subtypes */
+const ff_asf_guid ff_mediasubtype_cpfilters_processed =
+    {0x28,0xBD,0xAD,0x46,0xD0,0x6F,0x96,0x47,0x93,0xB2,0x15,0x5C,0x51,0xDC,0x04,0x8D};
+
+/* Formats */
+const ff_asf_guid ff_format_cpfilters_processed =
+    {0x6F,0xB3,0x39,0x67,0x5F,0x1D,0xC2,0x4A,0x81,0x92,0x28,0xBB,0x0E,0x73,0xD1,0x6A};
+const ff_asf_guid ff_format_waveformatex =
+    {0x81,0x9F,0x58,0x05,0x56,0xC3,0xCE,0x11,0xBF,0x01,0x00,0xAA,0x00,0x55,0x59,0x5A};
+const ff_asf_guid ff_format_mpeg2_video =
+    {0xE3,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA};
+
 const AVCodecGuid ff_video_guids[] = {
     {CODEC_ID_MPEG2VIDEO, {0x26,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}},
     {CODEC_ID_NONE}
index 252804d..7e4f243 100644 (file)
 #define WTV_SECTOR_BITS    12
 #define WTV_SECTOR_SIZE    (1 << WTV_SECTOR_BITS)
 #define WTV_BIGSECTOR_BITS 18
+#define WTV_PAD8(x) (((x) + 7) & ~7)
+
+extern const uint8_t ff_timeline_le16[16];
+extern const uint8_t ff_timeline_table_0_entries_Events_le16[62];
+extern const uint8_t ff_table_0_entries_legacy_attrib_le16[58];
+extern const uint8_t ff_table_0_entries_time_le16[40];
 
 extern const ff_asf_guid ff_dir_entry_guid;
 extern const ff_asf_guid ff_wtv_guid;
@@ -38,4 +44,12 @@ extern const ff_asf_guid ff_mediatype_audio;
 extern const ff_asf_guid ff_mediatype_video;
 extern const ff_asf_guid ff_format_none;
 extern const AVCodecGuid ff_video_guids[];
+
+extern const ff_asf_guid ff_DSATTRIB_TRANSPORT_PROPERTIES;
+extern const ff_asf_guid ff_metadata_guid;
+extern const ff_asf_guid ff_stream2_guid;
+extern const ff_asf_guid ff_mediasubtype_cpfilters_processed;
+extern const ff_asf_guid ff_format_cpfilters_processed;
+extern const ff_asf_guid ff_format_waveformatex;
+extern const ff_asf_guid ff_format_mpeg2_video;
 #endif /* AVFORMAT_WTV_H */
index f13dc74..e27fa14 100644 (file)
@@ -314,10 +314,6 @@ typedef struct {
 } WtvContext;
 
 /* WTV GUIDs */
-static const ff_asf_guid metadata_guid =
-    {0x5A,0xFE,0xD7,0x6D,0xC8,0x1D,0x8F,0x4A,0x99,0x22,0xFA,0xB1,0x1C,0x38,0x14,0x53};
-static const ff_asf_guid stream2_guid =
-    {0xA2,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D};
 static const ff_asf_guid EVENTID_SubtitleSpanningEvent =
     {0x48,0xC0,0xCE,0x5D,0xB9,0xD0,0x63,0x41,0x87,0x2C,0x4F,0x32,0x22,0x3B,0xE8,0x8A};
 static const ff_asf_guid EVENTID_LanguageSpanningEvent =
@@ -350,8 +346,6 @@ static const ff_asf_guid mediatype_mstvcaption =
     {0x89,0x8A,0x8B,0xB8,0x49,0xB0,0x80,0x4C,0xAD,0xCF,0x58,0x98,0x98,0x5E,0x22,0xC1};
 
 /* Media subtypes */
-static const ff_asf_guid mediasubtype_cpfilters_processed =
-    {0x28,0xBD,0xAD,0x46,0xD0,0x6F,0x96,0x47,0x93,0xB2,0x15,0x5C,0x51,0xDC,0x04,0x8D};
 static const ff_asf_guid mediasubtype_dvb_subtitle =
     {0xC3,0xCB,0xFF,0x34,0xB3,0xD5,0x71,0x41,0x90,0x02,0xD4,0xC6,0x03,0x01,0x69,0x7F};
 static const ff_asf_guid mediasubtype_teletext =
@@ -362,14 +356,8 @@ static const ff_asf_guid mediasubtype_mpeg2_sections =
     {0x79,0x85,0x9F,0x4A,0xF8,0x6B,0x92,0x43,0x8A,0x6D,0xD2,0xDD,0x09,0xFA,0x78,0x61};
 
 /* Formats */
-static const ff_asf_guid format_cpfilters_processed =
-    {0x6F,0xB3,0x39,0x67,0x5F,0x1D,0xC2,0x4A,0x81,0x92,0x28,0xBB,0x0E,0x73,0xD1,0x6A};
-static const ff_asf_guid format_waveformatex =
-    {0x81,0x9F,0x58,0x05,0x56,0xC3,0xCE,0x11,0xBF,0x01,0x00,0xAA,0x00,0x55,0x59,0x5A};
 static const ff_asf_guid format_videoinfo2 =
     {0xA0,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA};
-static const ff_asf_guid format_mpeg2_video =
-    {0xE3,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA};
 
 static int read_probe(AVProbeData *p)
 {
@@ -510,7 +498,7 @@ static void parse_legacy_attrib(AVFormatContext *s, AVIOContext *pb)
         length = avio_rl32(pb);
         if (!length)
             break;
-        if (ff_guidcmp(&guid, metadata_guid)) {
+        if (ff_guidcmp(&guid, ff_metadata_guid)) {
             av_log(s, AV_LOG_WARNING, "unknown guid "FF_PRI_GUID", expected metadata_guid; "
                    "remaining metadata entries ignored\n", FF_ARG_GUID(guid));
             break;
@@ -600,8 +588,8 @@ static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid,
 {
     WtvContext *wtv = s->priv_data;
     AVIOContext *pb = wtv->pb;
-    if (!ff_guidcmp(subtype, mediasubtype_cpfilters_processed) &&
-        !ff_guidcmp(formattype, format_cpfilters_processed)) {
+    if (!ff_guidcmp(subtype, ff_mediasubtype_cpfilters_processed) &&
+        !ff_guidcmp(formattype, ff_format_cpfilters_processed)) {
         ff_asf_guid actual_subtype;
         ff_asf_guid actual_formattype;
 
@@ -623,7 +611,7 @@ static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid,
         st = new_stream(s, st, sid, AVMEDIA_TYPE_AUDIO);
         if (!st)
             return NULL;
-        if (!ff_guidcmp(formattype, format_waveformatex)) {
+        if (!ff_guidcmp(formattype, ff_format_waveformatex)) {
             int ret = ff_get_wav_header(pb, st->codec, size);
             if (ret < 0)
                 return NULL;
@@ -653,7 +641,7 @@ static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid,
         if (!ff_guidcmp(formattype, format_videoinfo2)) {
             int consumed = parse_videoinfoheader2(s, st);
             avio_skip(pb, FFMAX(size - consumed, 0));
-        } else if (!ff_guidcmp(formattype, format_mpeg2_video)) {
+        } else if (!ff_guidcmp(formattype, ff_format_mpeg2_video)) {
             int consumed = parse_videoinfoheader2(s, st);
             avio_skip(pb, FFMAX(size - consumed, 0));
         } else {
@@ -746,7 +734,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
                 parse_media_type(s, 0, sid, mediatype, subtype, formattype, size);
                 consumed += 92 + size;
             }
-        } else if (!ff_guidcmp(g, stream2_guid)) {
+        } else if (!ff_guidcmp(g, ff_stream2_guid)) {
             int stream_index = ff_find_stream_index(s, sid);
             if (stream_index >= 0 && !((WtvStream*)s->streams[stream_index]->priv_data)->seen_data) {
                 ff_asf_guid mediatype, subtype, formattype;
@@ -835,7 +823,6 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
                     if (wtv->epoch == AV_NOPTS_VALUE || wtv->pts < wtv->epoch)
                         wtv->epoch = wtv->pts;
                 if (mode == SEEK_TO_PTS && wtv->pts >= seekts) {
-#define WTV_PAD8(x) (((x) + 7) & ~7)
                     avio_skip(pb, WTV_PAD8(len) - consumed);
                     return 0;
                 }
@@ -854,7 +841,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
         } else if (
             !ff_guidcmp(g, /* DSATTRIB_CAPTURE_STREAMTIME */ (const ff_asf_guid){0x14,0x56,0x1A,0x0C,0xCD,0x30,0x40,0x4F,0xBC,0xBF,0xD0,0x3E,0x52,0x30,0x62,0x07}) ||
             !ff_guidcmp(g, /* DSATTRIB_PicSampleSeq */ (const ff_asf_guid){0x02,0xAE,0x5B,0x2F,0x8F,0x7B,0x60,0x4F,0x82,0xD6,0xE4,0xEA,0x2F,0x1F,0x4C,0x99}) ||
-            !ff_guidcmp(g, /* DSATTRIB_TRANSPORT_PROPERTIES */ (const ff_asf_guid){0x12,0xF6,0x22,0xB6,0xAD,0x47,0x71,0x46,0xAD,0x6C,0x05,0xA9,0x8E,0x65,0xDE,0x3A}) ||
+            !ff_guidcmp(g, /* DSATTRIB_TRANSPORT_PROPERTIES */ ff_DSATTRIB_TRANSPORT_PROPERTIES) ||
             !ff_guidcmp(g, /* dvr_ms_vid_frame_rep_data */ (const ff_asf_guid){0xCC,0x32,0x64,0xDD,0x29,0xE2,0xDB,0x40,0x80,0xF6,0xD2,0x63,0x28,0xD2,0x76,0x1F}) ||
             !ff_guidcmp(g, /* EVENTID_ChannelChangeSpanningEvent */ (const ff_asf_guid){0xE5,0xC5,0x67,0x90,0x5C,0x4C,0x05,0x42,0x86,0xC8,0x7A,0xFE,0x20,0xFE,0x1E,0xFA}) ||
             !ff_guidcmp(g, /* EVENTID_ChannelInfoSpanningEvent */ (const ff_asf_guid){0x80,0x6D,0xF3,0x41,0x32,0x41,0xC2,0x4C,0xB1,0x21,0x01,0xA4,0x32,0x19,0xD8,0x1B}) ||
@@ -879,18 +866,6 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
     return AVERROR_EOF;
 }
 
-/* declare utf16le strings */
-#define _ , 0,
-static const uint8_t timeline_le16[] =
-    {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e', 0};
-static const uint8_t table_0_entries_legacy_attrib_le16[] =
-    {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0};
-static const uint8_t table_0_entries_time_le16[] =
-    {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'t'_'i'_'m'_'e', 0};
-static const uint8_t timeline_table_0_entries_Events_le16[] =
-    {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e'_'.'_'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'E'_'v'_'e'_'n'_'t'_'s', 0};
-#undef _
-
 static int read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
     WtvContext *wtv = s->priv_data;
@@ -920,7 +895,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
         return AVERROR_INVALIDDATA;
 
     /* parse chunks up until first data chunk */
-    wtv->pb = wtvfile_open(s, root, root_size, timeline_le16);
+    wtv->pb = wtvfile_open(s, root, root_size, ff_timeline_le16);
     if (!wtv->pb) {
         av_log(s, AV_LOG_ERROR, "timeline data missing\n");
         return AVERROR_INVALIDDATA;
@@ -934,7 +909,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
     timeline_pos = avio_tell(s->pb); // save before opening another file
 
     /* read metadata */
-    pb = wtvfile_open(s, root, root_size, table_0_entries_legacy_attrib_le16);
+    pb = wtvfile_open(s, root, root_size, ff_table_0_entries_legacy_attrib_le16);
     if (pb) {
         parse_legacy_attrib(s, pb);
         wtvfile_close(pb);
@@ -943,7 +918,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
     /* read seek index */
     if (s->nb_streams) {
         AVStream *st = s->streams[0];
-        pb = wtvfile_open(s, root, root_size, table_0_entries_time_le16);
+        pb = wtvfile_open(s, root, root_size, ff_table_0_entries_time_le16);
         if (pb) {
             while(1) {
                 uint64_t timestamp = avio_rl64(pb);
@@ -956,7 +931,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap)
             wtvfile_close(pb);
 
             if (wtv->nb_index_entries) {
-                pb = wtvfile_open(s, root, root_size, timeline_table_0_entries_Events_le16);
+                pb = wtvfile_open(s, root, root_size, ff_timeline_table_0_entries_Events_le16);
                 if (pb) {
                     int i;
                     while (1) {