[FFmpeg-soc] [soc]: r5876 - in mms: Makefile_mmsh.patch mms.c mms.h mmsh.c mmst.c

spyfeng subversion at mplayerhq.hu
Sun Aug 1 09:41:56 CEST 2010


Author: spyfeng
Date: Sun Aug  1 09:41:56 2010
New Revision: 5876

Log:
extract common function to mms.c.
update libavformat/Makefile.

Added:
   mms/mms.c
Modified:
   mms/Makefile_mmsh.patch
   mms/mms.h
   mms/mmsh.c
   mms/mmst.c

Modified: mms/Makefile_mmsh.patch
==============================================================================
--- mms/Makefile_mmsh.patch	Wed Jul 28 17:42:24 2010	(r5875)
+++ mms/Makefile_mmsh.patch	Sun Aug  1 09:41:56 2010	(r5876)
@@ -1,26 +1,28 @@
 Index: libavformat/Makefile
 ===================================================================
---- libavformat/Makefile	(revision 23550)
+--- libavformat/Makefile	(revision 24643)
 +++ libavformat/Makefile	(working copy)
-@@ -279,6 +279,8 @@
+@@ -287,7 +287,9 @@
  OBJS-$(CONFIG_FILE_PROTOCOL)             += file.o
  OBJS-$(CONFIG_GOPHER_PROTOCOL)           += gopher.o
  OBJS-$(CONFIG_HTTP_PROTOCOL)             += http.o httpauth.o
-+OBJS-$(CONFIG_MMS_PROTOCOL)              += mmsh.o
-+OBJS-$(CONFIG_MMSH_PROTOCOL)             += mmsh.o
- OBJS-$(CONFIG_MMST_PROTOCOL)             += mmst.o asf.o
+-OBJS-$(CONFIG_MMST_PROTOCOL)             += mmst.o asf.o
++OBJS-$(CONFIG_MMS_PROTOCOL)              += mmsh.o mms.o asf.o
++OBJS-$(CONFIG_MMSH_PROTOCOL)             += mmsh.o mms.o asf.o
++OBJS-$(CONFIG_MMST_PROTOCOL)             += mmst.o mms.o asf.o
+ OBJS-$(CONFIG_MD5_PROTOCOL)              += md5proto.o
  OBJS-$(CONFIG_PIPE_PROTOCOL)             += file.o
  
 Index: libavformat/allformats.c
 ===================================================================
---- libavformat/allformats.c	(revision 23550)
+--- libavformat/allformats.c	(revision 24643)
 +++ libavformat/allformats.c	(working copy)
-@@ -221,6 +221,8 @@
+@@ -225,6 +225,8 @@
      REGISTER_PROTOCOL (FILE, file);
      REGISTER_PROTOCOL (GOPHER, gopher);
      REGISTER_PROTOCOL (HTTP, http);
 +    REGISTER_PROTOCOL (MMS, mms);
 +    REGISTER_PROTOCOL (MMSH, mmsh);
      REGISTER_PROTOCOL (MMST, mmst);
+     REGISTER_PROTOCOL (MD5,  md5);
      REGISTER_PROTOCOL (PIPE, pipe);
-     REGISTER_PROTOCOL (RTMP, rtmp);

Added: mms/mms.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ mms/mms.c	Sun Aug  1 09:41:56 2010	(r5876)
@@ -0,0 +1,86 @@
+/*
+ * MMS protocol over TCP
+ * Copyright (c) 2006,2007 Ryan Martell
+ * Copyright (c) 2007 Björn Axelsson
+ * Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com>
+ *
+ * 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 "mms.h"
+#include "asf.h"
+#include "libavutil/intreadwrite.h"
+
+int ff_asf_header_parser(MMSContext *mms)
+{
+    uint8_t *p = mms->asf_header;
+    uint8_t *end;
+    int flags, stream_id;
+    mms->stream_num = 0;
+
+    if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||
+        memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {
+        av_log(NULL, AV_LOG_ERROR,
+               "Corrupt stream (invalid ASF header, size=%d)\n",
+               mms->asf_header_size);
+        return AVERROR_INVALIDDATA;
+    }
+
+    end = mms->asf_header + mms->asf_header_size;
+
+    p += sizeof(ff_asf_guid) + 14;
+    while(end - p >= sizeof(ff_asf_guid) + 8) {
+        uint64_t chunksize = AV_RL64(p + sizeof(ff_asf_guid));
+        if (!chunksize || chunksize > end - p) {
+            av_log(NULL, AV_LOG_ERROR,
+                   "Corrupt stream (header chunksize %"PRId64" is invalid)\n",
+                   chunksize);
+            return AVERROR_INVALIDDATA;
+        }
+        if (!memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {
+            /* read packet size */
+            if (end - p > sizeof(ff_asf_guid) * 2 + 68) {
+                mms->asf_packet_len = AV_RL32(p + sizeof(ff_asf_guid) * 2 + 64);
+                if (mms->asf_packet_len <= 0 || mms->asf_packet_len > sizeof(mms->in_buffer)) {
+                    av_log(NULL, AV_LOG_ERROR,
+                           "Corrupt stream (too large pkt_len %d)\n",
+                           mms->asf_packet_len);
+                    return AVERROR_INVALIDDATA;
+                }
+            }
+        } else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {
+            flags     = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);
+            stream_id = flags & 0x7F;
+            //The second condition is for checking CS_PKT_STREAM_ID_REQUEST packet size,
+            //we can calcuate the packet size by stream_num.
+            //Please see function send_stream_selection_request().
+            if (mms->stream_num < MAX_STREAMS &&
+                    46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {
+                mms->streams[mms->stream_num].id = stream_id;
+                mms->stream_num++;
+            } else {
+                av_log(NULL, AV_LOG_ERROR,
+                       "Corrupt stream (too many A/V streams)\n");
+                return AVERROR_INVALIDDATA;
+            }
+        } else if (!memcmp(p, ff_asf_head1_guid, sizeof(ff_asf_guid))) {
+            chunksize = 46; // see references [2] section 3.4. This should be set 46.
+        }
+        p += chunksize;
+    }
+
+    return 0;
+}

Modified: mms/mms.h
==============================================================================
--- mms/mms.h	Wed Jul 28 17:42:24 2010	(r5875)
+++ mms/mms.h	Sun Aug  1 09:41:56 2010	(r5876)
@@ -55,4 +55,6 @@ typedef struct {
 
     int stream_num;                      ///< stream numbers.
 } MMSContext;
+
+int ff_asf_header_parser(MMSContext * mms);
 #endif

Modified: mms/mmsh.c
==============================================================================
--- mms/mmsh.c	Wed Jul 28 17:42:24 2010	(r5875)
+++ mms/mmsh.c	Sun Aug  1 09:41:56 2010	(r5876)
@@ -90,68 +90,6 @@ static int mmsh_close(URLContext *h)
     return 0;
 }
 
-static int asf_header_parser(MMSHContext *mmsh_ctx)
-{
-    MMSContext *mms = mmsh_ctx->ff_ctx;
-    uint8_t *p = mms->asf_header;
-    uint8_t *end;
-    int flags, stream_id;
-    mms->stream_num = 0;
-
-    if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||
-        memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {
-        av_log(NULL, AV_LOG_ERROR,
-               "Corrupt stream (invalid ASF header, size=%d)\n",
-               mms->asf_header_size);
-        return AVERROR_INVALIDDATA;
-    }
-
-    end = mms->asf_header + mms->asf_header_size;
-
-    p += sizeof(ff_asf_guid) + 14;
-    while(end - p >= sizeof(ff_asf_guid) + 8) {
-        uint64_t chunksize = AV_RL64(p + sizeof(ff_asf_guid));
-        if (!chunksize || chunksize > end - p) {
-            av_log(NULL, AV_LOG_ERROR,
-                   "Corrupt stream (header chunksize %"PRId64" is invalid)\n",
-                   chunksize);
-            return AVERROR_INVALIDDATA;
-        }
-        if (!memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {
-            /* read packet size */
-            if (end - p > sizeof(ff_asf_guid) * 2 + 68) {
-                mms->asf_packet_len = AV_RL32(p + sizeof(ff_asf_guid) * 2 + 64);
-                if (mms->asf_packet_len <= 0 || mms->asf_packet_len > sizeof(mms->in_buffer)) {
-                    av_log(NULL, AV_LOG_ERROR,
-                           "Corrupt stream (too large pkt_len %d)\n",
-                           mms->asf_packet_len);
-                    return AVERROR_INVALIDDATA;
-                }
-            }
-        } else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {
-            flags     = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);
-            stream_id = flags & 0x7F;
-            //The second condition is for checking CS_PKT_STREAM_ID_REQUEST packet size,
-            //we can calcuate the packet size by stream_num.
-            //Please see function send_stream_selection_request().
-            if (mms->stream_num < MAX_STREAMS &&
-                    46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {
-                mms->streams[mms->stream_num].id = stream_id;
-                mms->stream_num++;
-            } else {
-                av_log(NULL, AV_LOG_ERROR,
-                       "Corrupt stream (too many A/V streams)\n");
-                return AVERROR_INVALIDDATA;
-            }
-        } else if (!memcmp(p, ff_asf_head1_guid, sizeof(ff_asf_guid))) {
-            chunksize = 46; // see mmst.c references [2] section 3.4. This should be set 46.
-        }
-        p += chunksize;
-    }
-
-    return 0;
-}
-
 static int get_chunk_header(MMSHContext *mmsh_ctx, int *len)
 {
     MMSContext *mms = mmsh_ctx->ff_ctx;
@@ -244,7 +182,7 @@ static int get_http_header_data(MMSHCont
             }
             mms->asf_header_size = len;
             if (!mms->header_parsed) {
-                res = asf_header_parser(mmsh_ctx);
+                res = ff_asf_header_parser(mms);
                 mms->header_parsed = 1;
                 return res;
             }

Modified: mms/mmst.c
==============================================================================
--- mms/mmst.c	Wed Jul 28 17:42:24 2010	(r5875)
+++ mms/mmst.c	Sun Aug  1 09:41:56 2010	(r5876)
@@ -438,68 +438,6 @@ static int send_startup_packet(MMSTConte
     return send_command_packet(mmst_ctx);
 }
 
-static int asf_header_parser(MMSTContext *mmst_ctx)
-{
-    MMSContext *mms = mmst_ctx->ff_ctx;
-    uint8_t *p = mms->asf_header;
-    uint8_t *end;
-    int flags, stream_id;
-    mms->stream_num = 0;
-
-    if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||
-        memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {
-        av_log(NULL, AV_LOG_ERROR,
-               "Corrupt stream (invalid ASF header, size=%d)\n",
-               mms->asf_header_size);
-        return AVERROR_INVALIDDATA;
-    }
-
-    end = mms->asf_header + mms->asf_header_size;
-
-    p += sizeof(ff_asf_guid) + 14;
-    while(end - p >= sizeof(ff_asf_guid) + 8) {
-        uint64_t chunksize = AV_RL64(p + sizeof(ff_asf_guid));
-        if (!chunksize || chunksize > end - p) {
-            av_log(NULL, AV_LOG_ERROR,
-                   "Corrupt stream (header chunksize %"PRId64" is invalid)\n",
-                   chunksize);
-            return AVERROR_INVALIDDATA;
-        }
-        if (!memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {
-            /* read packet size */
-            if (end - p > sizeof(ff_asf_guid) * 2 + 68) {
-                mms->asf_packet_len = AV_RL32(p + sizeof(ff_asf_guid) * 2 + 64);
-                if (mms->asf_packet_len <= 0 || mms->asf_packet_len > sizeof(mms->in_buffer)) {
-                    av_log(NULL, AV_LOG_ERROR,
-                           "Corrupt stream (too large pkt_len %d)\n",
-                           mms->asf_packet_len);
-                    return AVERROR_INVALIDDATA;
-                }
-            }
-        } else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {
-            flags     = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);
-            stream_id = flags & 0x7F;
-            //The second condition is for checking CS_PKT_STREAM_ID_REQUEST packet size,
-            //we can calcuate the packet size by stream_num.
-            //Please see function send_stream_selection_request().
-            if (mms->stream_num < MAX_STREAMS &&
-                    46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {
-                mms->streams[mms->stream_num].id = stream_id;
-                mms->stream_num++;
-            } else {
-                av_log(NULL, AV_LOG_ERROR,
-                       "Corrupt stream (too many A/V streams)\n");
-                return AVERROR_INVALIDDATA;
-            }
-        } else if (!memcmp(p, ff_asf_head1_guid, sizeof(ff_asf_guid))) {
-            chunksize = 46; // see references [2] section 3.4. This should be set 46.
-        }
-        p += chunksize;
-    }
-
-    return 0;
-}
-
 /** Send MMST stream selection command based on the AVStream->discard values. */
 static int send_stream_selection_request(MMSTContext *mmst_ctx)
 {
@@ -654,7 +592,7 @@ static int mms_open(URLContext *h, const
         goto fail;
     if((mmst_ctx->incoming_flags != 0X08) && (mmst_ctx->incoming_flags != 0X0C))
         goto fail;
-    err = asf_header_parser(mmst_ctx);
+    err = ff_asf_header_parser(mms);
     if (err) {
         dprintf(NULL, "asf header parsed failed!\n");
         goto fail;


More information about the FFmpeg-soc mailing list