⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmacmsup.pas

📁 一套及时通讯的原码
💻 PAS
📖 第 1 页 / 共 3 页
字号:
               else
               begin
                  if (nConvert = 0) and (cbSrcLengthUsed > 0) then
                      bQueued := True;
                  end;
            end
            else exit;
         end;
      end
      {$IFDEF USEWAVEMPEG}
      else if bUseL3Decoder then
      begin
         EnterCriticalSection(DataSection);
         try
            nBytes := SrcBufSize;
            mp3DecGetInputFree(pL3DLL, @nFree);
            mp3DecFill(pL3DLL,lpSrcBuffer, Min(nBytes,nFree), @nFill);
            dec(nBytes,nFill);
            nConvert := 0;
            nRead    := 0;
            bQueued  := True;
            TryCount := 0;
            while True do
            begin
               inc(TryCount);
               Res := mp3DecDecode(pL3DLL, (lpDstBuffer+nConvert), dwDstBufferSize-nConvert, @nRead, @info);
               case Res of
                        MPGA_WARNING_SYNCEOF: break;
                   MPGA_WARNING_SYNCNEEDDATA: begin
                                                 if (nBytes > 0) then
                                                 begin
                                                    mp3DecGetInputFree(pL3DLL, @nFree);
                                                    mp3DecFill(pL3DLL,lpSrcBuffer+(SrcBufSize-nBytes), Min(nBytes,nFree), @nFill);
                                                    dec(nBytes,nFill);
                                                 end
                                                 else break;
                                              end;
                     MPGA_WARNING_SYNCSEARCH: begin
                                                 if (nConvert > 0) then
                                                     break
                                                 else
                                                 begin
                                                    if (TryCount > 100) then exit;
                                                    continue;
                                                 end;
                                              end;
                       MPGA_WARNING_SYNCLOST: continue;
                                     MPGA_OK: begin
                                                 inc(nConvert,nRead);
                                              end;
                       else break;
               end;
            end;
         finally
            if (nBytes > 0) then
            begin
               mp3DecGetInputFree(pL3DLL, @nFree);
               mp3DecFill(pL3DLL,lpSrcBuffer+(SrcBufSize-nBytes), Min(nBytes,nFree), @nFill);
               dec(nBytes,nFill);
            end;
            LeaveCriticalSection(DataSection);
         end;
      end
      else if bUseL2Decoder then
      begin
         EnterCriticalSection(DataSection);
         try
            pL2DLL.mpegCommand(0,CMD_EXTERNALIO_FILL,integer(lpSrcBuffer),SrcBufSize,@nRead);
            nConvert := 0;
            nRead    := 0;
            bQueued  := True;
            TryCount := 0;
            while True do
            begin
               inc(TryCount);
               Res := pL2DLL.mpegGetFrame((lpDstBuffer+nConvert), @nRead, @info);
               case Res of
                        MPGA_WARNING_SYNCEOF: break;
                   MPGA_WARNING_SYNCNEEDDATA: begin
                                                 break;
                                              end;
                     MPGA_WARNING_SYNCSEARCH: begin
                                               if (nConvert > 0) then
                                                   break
                                               else
                                               begin
                                                  if (TryCount > 100) then exit;
                                                  continue;
                                               end;
                                              end;
                       MPGA_WARNING_SYNCLOST: continue;
                                     MPGA_OK: begin
                                                 inc(nConvert,nRead);
                                              end;
                      else break;
               end;
               Sleep(1);
            end;
         finally
            LeaveCriticalSection(DataSection);
         end;
      end
      {$ENDIF};

      Result           := nConvert;
      dwBytesConverted := nConvert;
      dwBytesRead      := 0;
   end;
end;

{-------------------------------------------------------------------------}
function  acmFlushConvert(pConvert: PACMConvert): Boolean;
var
   i: integer;

begin
   Result := False;
   if (pConvert <> nil) then
   with pConvert^ do
   begin
      dwBytesRead := dwBytesConverted;
      bPending    := False;
      bQueued     := False;

      {$IFDEF USEWAVEMPEG}
      if not bUseL3Decoder and not bUseL2Decoder then
      {$ENDIF}
      begin
         for i := 0 to Streams.Count-1 do
         with PACMStream(Streams[i])^,PACMStream(Streams[i])^.acmStreamHeader do
         begin
            dwRemaining := 0;
            cbSrcLength := 0;
            acmStreamConvert(acmStream, @acmStreamHeader,
                             ACM_STREAMCONVERTF_START or ACM_STREAMCONVERTF_END);
         end;
         Result := True;
      end
      {$IFDEF USEWAVEMPEG}
      else if bUseL3Decoder then
      begin
         if (pL3DLL <> 0) then
         begin
            EnterCriticalSection(DataSection);
            try
               if (mp3DecReset(pL3DLL, 0) <> 0) then
               begin
                  Result := False;
                  exit;
               end;
               Result := True;

            finally
               LeaveCriticalSection(DataSection);
            end;
         end;
      end
      else if bUseL2Decoder then
      begin
         if (pL2DLL <> nil) then
         begin
            EnterCriticalSection(DataSection);
            try
               pL2DLL.mpegClose;
               if (pL2DLL.mpegOpen('external://', 0, 0,0, 0) <> 0) then
               begin
                  Result := False;
                  exit;
               end;
               pL2DLL.mpegCommand(0, MP3_KEY, 0, 0, MP3_KEY_STR);
               Result := True;
            finally
               LeaveCriticalSection(DataSection);
            end;
         end;
      end
      {$ENDIF};
   end;
end;

{-------------------------------------------------------------------------}
function  acmEndConvert(pConvert: PACMConvert; SrcBufSize: Longint): Longint;
var
   i: integer;
   nConvert: Longint;
   {$IFDEF USEWAVEMPEG}
   info: Tmpgainfo;
   Res,nRead: DWORD;
   {$ENDIF}

begin
   Result := -1;
   if (pConvert <> nil) then
   with pConvert^ do
   begin
      nConvert := 0;

      {$IFDEF USEWAVEMPEG}
      if not bUseL3Decoder and not bUseL2Decoder then
      {$ENDIF}
      begin
         nConvert := Min(SrcBufSize,dwSrcBufferSize);
         bPending := False;

         for i := 0 to Streams.Count-1 do
         with PACMStream(Streams[i])^,PACMStream(Streams[i])^.acmStreamHeader do
         begin
            if (dwRemaining > 0) then
            begin
               { copy the reamaining bytes to the start }
               GlobalMoveMem(pbSrc^,(pbSrc+dwRemaining)^,nConvert);
               GlobalMoveMem(((pbSrc+dwSrcUser)-dwRemaining)^,pbSrc^,dwRemaining);
               cbSrcLength := nConvert+dwRemaining;
            end
            else cbSrcLength := nConvert;

            if acmStreamConvert(acmStream, @acmStreamHeader,
                                ACM_STREAMCONVERTF_END) = 0 then
            begin
               { wait until the converting is done }
               while (fdwStatus and ACMSTREAMHEADER_STATUSF_DONE = 0) do;

               nConvert := cbDstLengthUsed;
               dwRemaining := cbSrcLength-cbSrcLengthUsed;
               if (dwRemaining > 0) then
               begin
                  { move the remaining bytes to the end of the buffer }
                  GlobalMoveMem((pbSrc+cbSrcLengthUsed)^,(pbSrc+dwSrcUser-dwRemaining)^,dwRemaining);
                  bPending := True;
               end;
            end
            else exit;
         end;
      end
      {$IFDEF USEWAVEMPEG}
      else if bUseL3Decoder then
      begin
         EnterCriticalSection(DataSection);
         try
            mp3DecSetInputEof(pL3DLL);
            nConvert := 0;
            nRead    := 0;
            while True do
            begin
               Res := mp3DecDecode(pL3DLL, (lpDstBuffer+nConvert), dwDstBufferSize-nConvert, @nRead, @info);
               if (Res <> MPGA_OK) then break;

               inc(nConvert,nRead);
            end;
         finally
            LeaveCriticalSection(DataSection);
         end;
      end
      else if bUseL2Decoder then
      begin
         EnterCriticalSection(DataSection);
         try
            pL2DLL.mpegCommand(0,CMD_EXTERNALIO_SETEOF,0,0,nil);
            nConvert := 0;
            nRead    := 0;
            while True do
            begin
               Res := pL2DLL.mpegGetFrame((lpDstBuffer+nConvert), @nRead, @info);
               if (Res <> MPGA_OK) then break;

               inc(nConvert,nRead);
            end;
         finally
            LeaveCriticalSection(DataSection);
         end;
      end;
      {$ENDIF};

      Result           := nConvert;
      dwBytesConverted := nConvert;
      dwBytesRead      := 0;
   end;
end;

{-------------------------------------------------------------------------}
procedure acmDoneConvert(var pConvert: PACMConvert);
var
   i: integer;
   p: Pointer;
begin
   if (pConvert <> nil) then
   with pConvert^ do
   begin
      {$IFDEF USEWAVEMPEG}
      if not bUseL3Decoder and not bUseL2Decoder then
      {$ENDIF}
      begin
         for i := Streams.Count-1 downto 0 do
         with PACMStream(Streams[i])^,PACMStream(Streams[i])^.acmStreamHeader do
         begin
            if (fdwStatus and ACMSTREAMHEADER_STATUSF_PREPARED <> 0) then
            begin
               cbSrcLength := dwSrcUser;
               cbDstLength := dwDstUser;
               acmStreamUnprepareHeader(acmStream, @acmStreamHeader, 0);
               acmStreamClose(acmStream, 0);
            end;
            GlobalFreeMem(Pointer(lpDstBuffer));
            p := Streams[i];
            Streams.Delete(i);
            GlobalFreeMem(p);
         end;
         Streams.Free;
      end
      {$IFDEF USEWAVEMPEG}
      else if bUseL3Decoder then
      begin
         if (pL3DLL <> 0) then
         begin
            EnterCriticalSection(DataSection);
            try
               mp3DecClose(pL3DLL);
               mp3DecDone(pL3DLL);
               pL3DLL := 0;
               GlobalFreeMem(Pointer(lpDstBuffer));
            finally
               LeaveCriticalSection(DataSection);
               DeleteCriticalSection(DataSection);
            end;
         end;
      end
      else if bUseL2Decoder then
      begin
         if (pL2DLL <> nil) then
         begin
            EnterCriticalSection(DataSection);
            try
               pL2DLL.mpegClose;
               FreeL2DLLInstance(pL2DLL);
               pL2DLL := nil;
               GlobalFreeMem(Pointer(lpDstBuffer));
            finally
               LeaveCriticalSection(DataSection);
               DeleteCriticalSection(DataSection);
            end;
         end;
      end
      {$ENDIF};
      if bFreeSrcBuffer then GlobalFreeMem(Pointer(pConvert^.lpSrcBuffer));
   end;
   GlobalFreeMem(Pointer(pConvert));
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -