shithub: aacdec

Download patch

ref: 6e780526004821251344c8612cae1bb65705b312
parent: 5866a7cbffd838b0bc79b267969b373de0b6c8b4
author: menno <menno>
date: Sun Aug 3 14:00:15 EDT 2003

in_mp4: VBR display
in_mp4: RAW AAC+SBR playback fixed

--- a/plugins/in_mp4/config.c
+++ b/plugins/in_mp4/config.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: config.c,v 1.4 2003/08/02 22:34:46 menno Exp $
+** $Id: config.c,v 1.5 2003/08/03 18:00:14 menno Exp $
 **/
 
 #define WIN32_LEAN_AND_MEAN
@@ -36,6 +36,7 @@
 int m_show_errors = 1;
 int m_use_for_aac = 1;
 int m_downmix = 0;
+int m_vbr_display = 0;
 
 void _r_s(char *name,char *data, int mlen)
 {
--- a/plugins/in_mp4/config.h
+++ b/plugins/in_mp4/config.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: config.h,v 1.4 2003/08/02 22:34:46 menno Exp $
+** $Id: config.h,v 1.5 2003/08/03 18:00:15 menno Exp $
 **/
 
 char app_name[];
@@ -32,6 +32,7 @@
 int m_show_errors;
 int m_use_for_aac;
 int m_downmix;
+int m_vbr_display;
 
 #define RS(x) (_r_s(#x,x,sizeof(x)))
 #define WS(x) (WritePrivateProfileString(app_name,#x,x,INI_FILE))
--- 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.37 2003/08/03 08:57:32 knik Exp $
+** $Id: in_mp4.c,v 1.38 2003/08/03 18:00:15 menno Exp $
 **/
 
 //#define DEBUG_OUTPUT
@@ -123,9 +123,11 @@
 HANDLE play_thread_handle = INVALID_HANDLE_VALUE; // the handle to the decode thread
 
 /* Function definitions */
+void *decode_aac_frame(state *st, faacDecFrameInfo *frameInfo);
 DWORD WINAPI MP4PlayThread(void *b); // the decode thread procedure
 DWORD WINAPI AACPlayThread(void *b); // the decode thread procedure
 
+
 #ifdef DEBUG_OUTPUT
 void in_mp4_DebugOutput(char *message)
 {
@@ -169,6 +171,7 @@
     char show_errors[10];
     char use_for_aac[10];
     char downmix[10];
+    char vbr_display[10];
 
     config_init();
 
@@ -177,6 +180,7 @@
     strcpy(resolution, "0");
     strcpy(use_for_aac, "1");
     strcpy(downmix, "0");
+    strcpy(vbr_display, "1");
 
     RS(priority);
     RS(resolution);
@@ -183,6 +187,7 @@
     RS(show_errors);
     RS(use_for_aac);
     RS(downmix);
+    RS(vbr_display);
 
     m_priority = atoi(priority);
     m_resolution = atoi(resolution);
@@ -189,6 +194,7 @@
     m_show_errors = atoi(show_errors);
     m_use_for_aac = atoi(use_for_aac);
     m_downmix = atoi(downmix);
+    m_vbr_display = atoi(vbr_display);
 }
 
 void config_write()
@@ -198,6 +204,7 @@
     char show_errors[10];
     char use_for_aac[10];
     char downmix[10];
+    char vbr_display[10];
 
     itoa(m_priority, priority, 10);
     itoa(m_resolution, resolution, 10);
@@ -204,6 +211,7 @@
     itoa(m_show_errors, show_errors, 10);
     itoa(m_use_for_aac, use_for_aac, 10);
     itoa(m_downmix, downmix, 10);
+    itoa(m_vbr_display, vbr_display, 10);
 
     WS(priority);
     WS(resolution);
@@ -210,6 +218,7 @@
     WS(show_errors);
     WS(use_for_aac);
     WS(downmix);
+    WS(vbr_display);
 }
 
 void init()
@@ -546,6 +555,8 @@
             SendMessage(GetDlgItem(hwndDlg, IDC_USEFORAAC), BM_SETCHECK, BST_CHECKED, 0);
         if (m_downmix)
             SendMessage(GetDlgItem(hwndDlg, IDC_DOWNMIX), BM_SETCHECK, BST_CHECKED, 0);
+        if (m_vbr_display)
+            SendMessage(GetDlgItem(hwndDlg, IDC_VBR), BM_SETCHECK, BST_CHECKED, 0);
         return TRUE;
 
     case WM_COMMAND:
@@ -557,6 +568,8 @@
             m_show_errors = SendMessage(GetDlgItem(hwndDlg, IDC_ERROR), BM_GETCHECK, 0, 0);
             m_use_for_aac = SendMessage(GetDlgItem(hwndDlg, IDC_USEFORAAC), BM_GETCHECK, 0, 0);
             m_downmix = SendMessage(GetDlgItem(hwndDlg, IDC_DOWNMIX), BM_GETCHECK, 0, 0);
+            m_vbr_display = SendMessage(GetDlgItem(hwndDlg, IDC_VBR), BM_GETCHECK, 0, 0);
+
             m_priority = SendMessage(GetDlgItem(hwndDlg, IDC_PRIORITY), TBM_GETPOS, 0, 0);
             for (i = 0; i < 6; i++)
             {
@@ -767,6 +780,7 @@
         int bread = 0;
         double length = 0.;
         __int64 bitrate = 128;
+        faacDecFrameInfo frameInfo;
 
         module.is_seekable = 1;
 
@@ -865,6 +879,11 @@
             avg_bitrate = bitrate;
         else
             avg_bitrate = bitrate*1000;
+
+        decode_aac_frame(&mp4state, &frameInfo);
+        mp4state.channels = frameInfo.channels;
+        mp4state.samplerate = frameInfo.samplerate;
+
     } else {
         mp4state.mp4file = MP4Read(mp4state.filename, 0);
         if (!mp4state.mp4file)
@@ -928,6 +947,7 @@
 
     maxlatency = module.outMod->Open(mp4state.samplerate, (int)mp4state.channels,
         res_table[m_resolution], -1, -1);
+
     if (maxlatency < 0) // error opening device
     {
         faacDecClose(mp4state.hDecoder);
@@ -946,8 +966,8 @@
     module.SAVSAInit(maxlatency, mp4state.samplerate);
     module.VSASetInfo((int)mp4state.channels, mp4state.samplerate);
 
-    br = (int)floor(((float)avg_bitrate + 500.0)/1000.0);
-    sr = (int)floor((float)mp4state.samplerate/1000.0);
+    br = (int)floor(((float)avg_bitrate + 500.0)/1000.0 + 0.5);
+    sr = (int)floor((float)mp4state.samplerate/1000.0 + 0.5);
     module.SetInfo(br, sr, (int)mp4state.channels, 1);
 
     module.outMod->SetVolume(-666); // set the output plug-ins default volume
@@ -1275,6 +1295,8 @@
 {
     int done = 0;
     int l;
+    int seq_frames = 0;
+    int seq_bytes = 0;
 
     void *sample_buffer;
     unsigned char *buffer;
@@ -1317,7 +1339,7 @@
             }
 
             Sleep(10);
-        } else if (module.outMod->CanWrite() >= (1024*mp4state.channels*sizeof(short))) {
+        } else if (module.outMod->CanWrite() >= (2048*mp4state.channels*sizeof(short))) {
 
             if (mp4state.last_frame)
             {
@@ -1365,8 +1387,8 @@
                         mp4state.decode_pos_ms);
                     module.VSAAddPCMData(sample_buffer, (int)mp4state.channels, res_table[m_resolution],
                         mp4state.decode_pos_ms);
-		    mp4state.decode_pos_ms += (double)frameInfo.samples * 1000.0 /
-		      ((double)mp4state.samplerate * (double)frameInfo.channels);
+                    mp4state.decode_pos_ms += (double)frameInfo.samples * 1000.0 /
+                        ((double)frameInfo.samplerate * (double)frameInfo.channels);
 
                     l = frameInfo.samples * res_table[m_resolution] / 8;
 
@@ -1379,7 +1401,7 @@
                             frameInfo.samples/frameInfo.channels,
                             res_table[m_resolution],
                             frameInfo.channels,
-                            mp4state.samplerate) *
+                            frameInfo.samplerate) *
                             (frameInfo.channels*(res_table[m_resolution]/8));
 
                         module.outMod->Write(dsp_buffer, l);
@@ -1387,6 +1409,22 @@
                     } else {
                         module.outMod->Write(sample_buffer, l);
                     }
+
+                    /* VBR bitrate display */
+                    if (m_vbr_display)
+                    {
+                        seq_frames++;
+                        seq_bytes += frameInfo.bytesconsumed;
+                        if (seq_frames == (int)(floor((float)frameInfo.samplerate/(float)(frameInfo.samples/frameInfo.channels) + 0.5)))
+                        {
+                            module.SetInfo((int)floor(((float)seq_bytes*8.)/1000. + 0.5),
+                                (int)floor(frameInfo.samplerate/1000. + 0.5),
+                                mp4state.channels, 1);
+
+                            seq_frames = 0;
+                            seq_bytes = 0;
+                        }
+                    }
                 }
             }
         } else {
@@ -1497,6 +1535,8 @@
 {
     int done = 0;
     int l;
+    int seq_frames = 0;
+    int seq_bytes = 0;
 
 #ifdef DEBUG_OUTPUT
     in_mp4_DebugOutput("AACPlayThread");
@@ -1532,7 +1572,7 @@
             }
 
             Sleep(10);
-        } else if (module.outMod->CanWrite() >= (1024*mp4state.channels*sizeof(short))) {
+        } else if (module.outMod->CanWrite() >= (2048*mp4state.channels*sizeof(short))) {
             faacDecFrameInfo frameInfo;
             void *sample_buffer;
 
@@ -1564,8 +1604,8 @@
                     mp4state.decode_pos_ms);
                 module.VSAAddPCMData(sample_buffer, (int)mp4state.channels, res_table[m_resolution],
                     mp4state.decode_pos_ms);
-		mp4state.decode_pos_ms += (double)frameInfo.samples * 1000.0 /
-		  ((double)mp4state.samplerate* (double)frameInfo.channels);
+                mp4state.decode_pos_ms += (double)frameInfo.samples * 1000.0 /
+                    ((double)frameInfo.samplerate* (double)frameInfo.channels);
 
                 l = frameInfo.samples * res_table[m_resolution] / 8;
 
@@ -1578,7 +1618,7 @@
                         frameInfo.samples/frameInfo.channels,
                         res_table[m_resolution],
                         frameInfo.channels,
-                        mp4state.samplerate) *
+                        frameInfo.samplerate) *
                         (frameInfo.channels*(res_table[m_resolution]/8));
 
                     module.outMod->Write(dsp_buffer, l);
@@ -1586,11 +1626,27 @@
                 } else {
                     module.outMod->Write(sample_buffer, l);
                 }
+
+                /* VBR bitrate display */
+                if (m_vbr_display)
+                {
+                    seq_frames++;
+                    seq_bytes += frameInfo.bytesconsumed;
+                    if (seq_frames == (int)(floor((float)frameInfo.samplerate/(float)(frameInfo.samples/frameInfo.channels) + 0.5)))
+                    {
+                        module.SetInfo((int)floor(((float)seq_bytes*8.)/1000. + 0.5),
+                            (int)floor(frameInfo.samplerate/1000. + 0.5),
+                            mp4state.channels, 1);
+
+                        seq_frames = 0;
+                        seq_bytes = 0;
+                    }
+                }
             }
 
             mp4state.samplerate = frameInfo.samplerate;
 
-            mp4state.cur_pos_sec += 1024.0/(double)mp4state.samplerate;
+            mp4state.cur_pos_sec += ((double)(frameInfo.samples/frameInfo.channels)*1024.0)/(double)mp4state.samplerate;
         } else {
             Sleep(10);
         }
--- a/plugins/in_mp4/in_mp4.rc
+++ b/plugins/in_mp4/in_mp4.rc
@@ -112,9 +112,11 @@
     CONTROL         "Downmix to stereo",IDC_DOWNMIX,"Button",BS_AUTOCHECKBOX | 
                     WS_TABSTOP,152,13,74,10
     CONTROL         "Use for AAC",IDC_USEFORAAC,"Button",BS_AUTOCHECKBOX | 
-                    WS_TABSTOP,152,27,55,10
+                    WS_TABSTOP,152,26,55,10
+    CONTROL         "VBR Display",IDC_VBR,"Button",BS_AUTOCHECKBOX | 
+                    WS_TABSTOP,152,39,55,10
     CONTROL         "Show errors",IDC_ERROR,"Button",BS_AUTOCHECKBOX | 
-                    WS_TABSTOP,152,41,53,10
+                    WS_TABSTOP,152,52,53,10
     DEFPUSHBUTTON   "OK",IDOK,122,74,50,14
     PUSHBUTTON      "Cancel",IDCANCEL,61,74,50,14
     GROUPBOX        "Priority",IDC_STATIC,7,7,57,58
--- a/plugins/in_mp4/resource.h
+++ b/plugins/in_mp4/resource.h
@@ -53,6 +53,7 @@
 #define IDC_STATIC11                    1035
 #define IDC_STATIC12                    1036
 #define IDC_DOWNMIX                     1038
+#define IDC_VBR                         1039
 
 // Next default values for new objects
 // 
@@ -60,7 +61,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        103
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1039
+#define _APS_NEXT_CONTROL_VALUE         1040
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif