shithub: aacdec

Download patch

ref: 7be9972c11f3f7383594f389ba753c20cc724371
parent: 056bcd7aa532463f1fc3421fcd612360c0f35c8a
author: ca5e <ca5e>
date: Mon Nov 10 13:57:59 EST 2003

Some seeking changes

--- a/plugins/foo_mp4/foo_mp4.cpp
+++ b/plugins/foo_mp4/foo_mp4.cpp
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: foo_mp4.cpp,v 1.69 2003/11/02 14:59:06 menno Exp $
+** $Id: foo_mp4.cpp,v 1.70 2003/11/10 18:57:59 ca5e Exp $
 **/
 
 #include <mp4.h>
@@ -729,6 +729,7 @@
             m_aac_bytes_into_buffer = bread;
             m_aac_bytes_consumed = 0;
             m_file_offset = 0;
+            m_last_offset = -1;
             m_at_eof = (bread != 768*6) ? 1 : 0;
 
             if (init==0)
@@ -913,10 +914,14 @@
 
                     if (m_header_type != 1)
                     {
-                        m_tail->offset = m_file_offset;
-                        m_tail->next = (struct seek_list*)malloc(sizeof(struct seek_list));
-                        m_tail = m_tail->next;
-                        m_tail->next = NULL;
+                        if (m_last_offset < m_file_offset)
+                        {
+                            m_tail->offset = m_file_offset;
+                            m_tail->next = (struct seek_list*)malloc(sizeof(struct seek_list));
+                            m_tail = m_tail->next;
+                            m_tail->next = NULL;
+                            m_last_offset = m_file_offset;
+                        }
                     }
 
                     advance_buffer(frameInfo.bytesconsumed);
@@ -1076,6 +1081,7 @@
     long m_aac_bytes_into_buffer;
     long m_aac_bytes_consumed;
     __int64 m_file_offset;
+    __int64 m_last_offset;
     unsigned char *m_aac_buffer;
     int m_at_eof;
 
--- a/plugins/in_mp4/in_mp4.c
+++ b/plugins/in_mp4/in_mp4.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: in_mp4.c,v 1.45 2003/11/05 14:41:46 ca5e Exp $
+** $Id: in_mp4.c,v 1.46 2003/11/10 18:57:23 ca5e Exp $
 **/
 
 //#define DEBUG_OUTPUT
@@ -93,6 +93,7 @@
     char filename[_MAX_PATH];
     int filetype; /* 0: MP4; 1: AAC */
     int last_frame;
+    __int64 last_offset;
 
     /* MP4 stuff */
     MP4FileHandle mp4file;
@@ -2004,7 +2005,7 @@
 
 void *decode_aac_frame(state *st, faacDecFrameInfo *frameInfo)
 {
-    void *sample_buffer;
+    void *sample_buffer = NULL;
 
     do
     {
@@ -2017,10 +2018,14 @@
 
             if (st->m_header_type != 1)
             {
-                st->m_tail->offset = st->m_file_offset;
-                st->m_tail->next = (struct seek_list*)malloc(sizeof(struct seek_list));
-                st->m_tail = st->m_tail->next;
-                st->m_tail->next = NULL;
+                if (st->last_offset < st->m_file_offset)
+                {
+                    st->m_tail->offset = st->m_file_offset;
+                    st->m_tail->next = (struct seek_list*)malloc(sizeof(struct seek_list));
+                    st->m_tail = st->m_tail->next;
+                    st->m_tail->next = NULL;
+                    st->last_offset = st->m_file_offset;
+                }
             }
 
             advance_buffer(st, frameInfo->bytesconsumed);
@@ -2053,6 +2058,7 @@
         if (target->offset == 0 && frames > 0)
             return 0;
         fseek(st->aacfile, target->offset, SEEK_SET);
+        st->m_file_offset = target->offset;
 
         bread = fread(st->m_aac_buffer, 1, 768*6, st->aacfile);
         if (bread != 768*6)
@@ -2061,7 +2067,10 @@
             st->m_at_eof = 0;
         st->m_aac_bytes_into_buffer = bread;
         st->m_aac_bytes_consumed = 0;
+        st->m_file_offset += bread;
 
+        faacDecPostSeekReset(st->hDecoder, -1);
+
         return 1;
     } else {
         if (seconds > st->cur_pos_sec)
@@ -2089,10 +2098,9 @@
                 }
             }
 
-            return 1;
-        } else {
-            return 0;
+            faacDecPostSeekReset(st->hDecoder, -1);
         }
+        return 1;
     }
 }