[FFmpeg-soc] [soc]: r5880 - mms/mmst.c

spyfeng subversion at mplayerhq.hu
Sun Aug 1 10:23:18 CEST 2010


Author: spyfeng
Date: Sun Aug  1 10:23:18 2010
New Revision: 5880

Log:
implement mms_read_packet() in mms_read() directly.

Modified:
   mms/mmst.c

Modified: mms/mmst.c
==============================================================================
--- mms/mmst.c	Sun Aug  1 10:14:50 2010	(r5879)
+++ mms/mmst.c	Sun Aug  1 10:23:18 2010	(r5880)
@@ -454,56 +454,6 @@ static int send_stream_selection_request
     return send_command_packet(mmst_ctx);
 }
 
-/** Read at most one media packet (or a whole header). */
-static int read_mms_packet(MMSTContext *mmst_ctx, uint8_t *buf, int buf_size)
-{
-    int result = 0;
-    int size_to_copy;
-    MMSContext *mms = mmst_ctx->ff_ctx;
-    do {
-        if(mms->asf_header_read_size < mms->asf_header_size && !mmst_ctx->is_playing) {
-            /* Read from ASF header buffer */
-            size_to_copy= FFMIN(buf_size,
-                                mms->asf_header_size - mms->asf_header_read_size);
-            memcpy(buf, mms->asf_header + mms->asf_header_read_size, size_to_copy);
-            mms->asf_header_read_size += size_to_copy;
-            result += size_to_copy;
-            dprintf(NULL, "Copied %d bytes from stored header. left: %d\n",
-                   size_to_copy, mms->asf_header_size - mms->asf_header_read_size);
-            if (mms->asf_header_size == mms->asf_header_read_size) {
-                av_freep(&mms->asf_header);
-                mmst_ctx->is_playing = 1;
-            }
-        } else if(mms->remaining_in_len) {
-            /* Read remaining packet data to buffer.
-             * the result can not be zero because remaining_in_len is positive.*/
-            result = ff_read_data(mms, buf, buf_size);
-        } else {
-            /* Read from network */
-            int err = mms_safe_send_recv(mmst_ctx, NULL, SC_PKT_ASF_MEDIA);
-            if (err == 0) {
-                if(mms->remaining_in_len>mms->asf_packet_len) {
-                    av_log(NULL, AV_LOG_ERROR,
-                           "Incoming pktlen %d is larger than ASF pktsize %d\n",
-                           mms->remaining_in_len, mms->asf_packet_len);
-                    result= AVERROR_IO;
-                } else {
-                    // copy the data to the packet buffer.
-                    result = ff_read_data(mms, buf, buf_size);
-                    if (result == 0) {
-                        dprintf(NULL, "read asf media paket size is zero!\n");
-                        break;
-                    }
-                }
-            } else {
-                dprintf(NULL, "read packet error!\n");
-                break;
-            }
-        }
-    } while(!result); // only return one packet.
-    return result;
-}
-
 static int send_close_packet(MMSTContext *mmst_ctx)
 {
     start_command_packet(mmst_ctx, CS_PKT_STREAM_CLOSE);
@@ -643,7 +593,51 @@ static int mms_read(URLContext *h, uint8
 {
     /* TODO: see tcp.c:tcp_read() about a possible timeout scheme */
     MMSTContext *mmst_ctx = h->priv_data;
-    return read_mms_packet(mmst_ctx, buf, size);
+    int result = 0;
+    int size_to_copy;
+    MMSContext *mms = mmst_ctx->ff_ctx;
+    do {
+        if(mms->asf_header_read_size < mms->asf_header_size && !mmst_ctx->is_playing) {
+            /* Read from ASF header buffer */
+            size_to_copy= FFMIN(size,
+                                mms->asf_header_size - mms->asf_header_read_size);
+            memcpy(buf, mms->asf_header + mms->asf_header_read_size, size_to_copy);
+            mms->asf_header_read_size += size_to_copy;
+            result += size_to_copy;
+            dprintf(NULL, "Copied %d bytes from stored header. left: %d\n",
+                   size_to_copy, mms->asf_header_size - mms->asf_header_read_size);
+            if (mms->asf_header_size == mms->asf_header_read_size) {
+                av_freep(&mms->asf_header);
+                mmst_ctx->is_playing = 1;
+            }
+        } else if(mms->remaining_in_len) {
+            /* Read remaining packet data to buffer.
+             * the result can not be zero because remaining_in_len is positive.*/
+            result = ff_read_data(mms, buf, size);
+        } else {
+            /* Read from network */
+            int err = mms_safe_send_recv(mmst_ctx, NULL, SC_PKT_ASF_MEDIA);
+            if (err == 0) {
+                if(mms->remaining_in_len>mms->asf_packet_len) {
+                    av_log(NULL, AV_LOG_ERROR,
+                           "Incoming pktlen %d is larger than ASF pktsize %d\n",
+                           mms->remaining_in_len, mms->asf_packet_len);
+                    result= AVERROR_IO;
+                } else {
+                    // copy the data to the packet buffer.
+                    result = ff_read_data(mms, buf, size);
+                    if (result == 0) {
+                        dprintf(NULL, "read asf media paket size is zero!\n");
+                        break;
+                    }
+                }
+            } else {
+                dprintf(NULL, "read packet error!\n");
+                break;
+            }
+        }
+    } while(!result); // only return one packet.
+    return result;
 }
 
 URLProtocol mmst_protocol = {


More information about the FFmpeg-soc mailing list