[datatype-dev] CR-Client: fix initial seeking in WM local fileformat

[datatype-dev] CR-Client: fix initial seeking in WM local fileformat

Eric Hyche ehyche at real.com
Wed Nov 8 07:48:06 PST 2006


Description
---------------------------------------
When the ASF fileformat was called with Seek() before being
called with GetPacket(), an error occurred. This situation
can happen when called by dtdrive as in:

dtdrive -J 8000 somefile.asf

The problem was that the CHXASFIndex object was only getting set up
when we received a packet, and it was assumed that by the
time we read the ASF Index at the end of the file that we
had already set up the CHXASFIndex object. The fix was simply
to move the code which creates and initializes the CHXASFIndex
object into common code and call this code from both the
packet reading location and the index reading location.

Files Modified
---------------------------------------
datatype/wm/fileformat/asf_file_format_file.cpp
datatype/wm/fileformat/pub/asf_file_format_file.h

Branches
---------------------------------------
HEAD and 150Cay

Testing
---------------------------------------
The command "dtdrive -J 8000 thefullmonty.wmv" was successfully run after this change.

Index: asf_file_format_file.cpp
===================================================================
RCS file: /cvsroot/datatype/wm/fileformat/asf_file_format_file.cpp,v
retrieving revision 1.6
diff -u -w -r1.6 asf_file_format_file.cpp
--- asf_file_format_file.cpp    30 Oct 2006 15:55:32 -0000      1.6
+++ asf_file_format_file.cpp    8 Nov 2006 15:41:05 -0000
@@ -1080,6 +1080,10 @@
                 retVal = pASFObj->Unpack(pBuffer->GetBuffer(), pBuffer->GetSize());
                 if (SUCCEEDED(retVal))
                 {
+                    // Make sure the ASF index is set up
+                    retVal = SetupASFIndex();
+                    if (SUCCEEDED(retVal))
+                    {
                     // Is this a Index Object or a Simple Index Object?
                     if (pASFObj->m_eASFObjectType == HX_ASF_Index_Object)
                     {
@@ -1088,11 +1092,8 @@
                         // simply copy all the information from this Index Object
                         // and put it in our on-the-fly Index Object. That way, we should
                         // never have to seek to the end of the file again from now on.
-                        if (m_pASFIndex)
-                        {
                             m_pASFIndex->ImportIndexObject((CHXASFTopLevelIndexObject*) pASFObj);
                         }
-                    }
                     else
                     {
                         // Get the WM stream number of this simple index object
@@ -1100,11 +1101,8 @@
                         // This is a simple index object. Our on-the-fly index object
                         // contains similar information so we will first import
                         // this information into our on-the-fly object
-                        if (m_pASFIndex)
-                        {
                             m_pASFIndex->ImportSimpleIndexObject((CHXASFTopLevelSimpleIndexObject*) pASFObj,
usWMStreamNum,
                                                                  m_pFilePropertiesObject->m_ulMaxDataPacketSize);
-                        }
                         // Increment the index of the simple index object we have seen so far
                         m_ulSimpleIndexOrderIndex++;
                     }
@@ -1146,6 +1144,7 @@
                     }
                 }
             }
+            }
             HX_RELEASE(pASFObj);
         }
         else
@@ -3382,42 +3381,10 @@

     if (pPacket && m_pFilePropertiesObject)
     {
-        // Clear the return value
-        retVal = HXR_OK;
-        // Do we already have an index?
-        if (!m_pASFIndex)
-        {
-            // Set the return value
-            retVal = HXR_OUTOFMEMORY;
-            // Create the CHXASFIndex object
-            m_pASFIndex = new CHXASFIndex();
-            if (m_pASFIndex)
-            {
-                // Compute the play duration in ms
-                UINT64 ullPlayDurationInMs = m_pFilePropertiesObject->m_ullPlayDuration / ((UINT64) 10000);
-                // Initialize the index object
-                retVal = m_pASFIndex->Init(m_ulNumWMStreams,
-                                           m_pusWMIndex2StreamNumber,
-                                           INT64_TO_UINT32(ullPlayDurationInMs),
-                                           INT64_TO_UINT32(m_pFilePropertiesObject->m_ullPreroll),
-                                           m_ulFirstASFPacketFileOffset,
-                                           m_pIndexParametersObject);
+        // Make sure the ASF index is set up
+        retVal = SetupASFIndex();
                 if (SUCCEEDED(retVal))
                 {
-                    // We need to inform the index object about the stream types
-                    // of each of the WM streams
-                    for (UINT32 i = 0; i < m_ulNumWMStreams && SUCCEEDED(retVal); i++)
-                    {
-                        // Get the WM stream number
-                        UINT16 usWMStreamNum = GetWMStreamNumber(i);
-                        // Set the stream type into the index
-                        retVal = m_pASFIndex->SetWMStreamType(usWMStreamNum, GetStreamType(usWMStreamNum));
-                    }
-                }
-            }
-        }
-        if (m_pASFIndex && SUCCEEDED(retVal))
-        {
             // Add the ASF packet to the index
             retVal = m_pASFIndex->AddASFPacketToIndex(pPacket);
         }
@@ -3726,3 +3693,49 @@

     return ulRet;
 }
+
+HX_RESULT CASFFileFormatFile::SetupASFIndex()
+{
+    HX_RESULT retVal = HXR_OK;
+
+    // Do we already have an index?
+    if (!m_pASFIndex)
+    {
+        // Set the return value
+        retVal = HXR_UNEXPECTED;
+        // Make sure we've received the headers
+        if (m_pFilePropertiesObject && m_ulNumWMStreams)
+        {
+            // Set the return value
+            retVal = HXR_OUTOFMEMORY;
+            // Create the CHXASFIndex object
+            m_pASFIndex = new CHXASFIndex();
+            if (m_pASFIndex)
+            {
+                // Compute the play duration in ms
+                UINT64 ullPlayDurationInMs = m_pFilePropertiesObject->m_ullPlayDuration / ((UINT64) 10000);
+                // Initialize the index object
+                retVal = m_pASFIndex->Init(m_ulNumWMStreams,
+                                           m_pusWMIndex2StreamNumber,
+                                           INT64_TO_UINT32(ullPlayDurationInMs),
+                                           INT64_TO_UINT32(m_pFilePropertiesObject->m_ullPreroll),
+                                           m_ulFirstASFPacketFileOffset,
+                                           m_pIndexParametersObject);
+                if (SUCCEEDED(retVal))
+                {
+                    // We need to inform the index object about the stream types
+                    // of each of the WM streams
+                    for (UINT32 i = 0; i < m_ulNumWMStreams && SUCCEEDED(retVal); i++)
+                    {
+                        // Get the WM stream number
+                        UINT16 usWMStreamNum = GetWMStreamNumber(i);
+                        // Set the stream type into the index
+                        retVal = m_pASFIndex->SetWMStreamType(usWMStreamNum, GetStreamType(usWMStreamNum));
+                    }
+                }
+            }
+        }
+    }
+
+    return retVal;
+}

Index: pub/asf_file_format_file.h
===================================================================
RCS file: /cvsroot/datatype/wm/fileformat/pub/asf_file_format_file.h,v
retrieving revision 1.4
diff -u -w -r1.4 asf_file_format_file.h
--- pub/asf_file_format_file.h  30 Oct 2006 15:55:32 -0000      1.4
+++ pub/asf_file_format_file.h  8 Nov 2006 15:41:06 -0000
@@ -241,6 +241,7 @@
     HX_RESULT                    EstimateSeekTime(UINT32 ulDesiredSeekTime, REF(UINT32) rulSeekOffset);
     UINT16                       GetSimpleIndexObjectStreamNumber(UINT32 ulSimpleIndexOrderIndex);
     UINT32                       GetPacketBufferSize(IHXPacket* pPacket);
+    HX_RESULT                    SetupASFIndex();

     static const char* const m_pszDescription;
     static const char* const m_pszCopyright;


=====================================
Eric Hyche, Technical Lead
RealNetworks, Inc.
ehyche at real.com




More information about the Datatype-dev mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.