changeset 2431:a2d95b16e28b

* Releasing movie OpenAL buffers
author a.parshin
date Wed, 23 Jul 2014 20:53:28 +0300
parents cb66a1082fcf
children 99e7bd7ec0a2
files CShow.h Events.cpp MediaPlayer.cpp OpenALSoundProvider.h VideoPlayer.cpp VideoPlayer.h
diffstat 6 files changed, 52 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/CShow.h	Wed Jul 23 20:28:28 2014 +0300
+++ b/CShow.h	Wed Jul 23 20:53:28 2014 +0300
@@ -23,13 +23,13 @@
 
   switch (movie)
   {
-    case MOVIE_3DOLogo: pVideoPlayer->MovieLoop("3dologo", 0, 0);        break;
-	case MOVIE_NWCLogo: pVideoPlayer->MovieLoop("new world logo", 0, 1); break;
-	case MOVIE_JVC:     pVideoPlayer->MovieLoop("jvc", 0, 1);            break;
-	case MOVIE_Intro:   pVideoPlayer->MovieLoop("Intro", 0, 1);          break;
-	case MOVIE_Emerald: pVideoPlayer->MovieLoop("Intro Post", 0, 1);     break;
-	case MOVIE_Death:   pVideoPlayer->MovieLoop("losegame", 2, 1);       break;
-	case MOVIE_Outro:   pVideoPlayer->MovieLoop("end_seq1", 20, 1);      break;
+    case MOVIE_3DOLogo: pVideoPlayer->MovieLoop("3dologo", 0);        break;
+	case MOVIE_NWCLogo: pVideoPlayer->MovieLoop("new world logo", 0); break;
+	case MOVIE_JVC:     pVideoPlayer->MovieLoop("jvc", 0);            break;
+	case MOVIE_Intro:   pVideoPlayer->MovieLoop("Intro", 0);          break;
+	case MOVIE_Emerald: pVideoPlayer->MovieLoop("Intro Post", 0);     break;
+	case MOVIE_Death:   pVideoPlayer->MovieLoop("losegame", 2);       break;
+	case MOVIE_Outro:   pVideoPlayer->MovieLoop("end_seq1", 20);      break;
 
     default:
       Error("Invalid movie requested: %u", movie);
--- a/Events.cpp	Wed Jul 23 20:28:28 2014 +0300
+++ b/Events.cpp	Wed Jul 23 20:53:28 2014 +0300
@@ -465,7 +465,7 @@
         v128 = pCurrentScreen;
         strcpy(Str, Source);
         v16 = RemoveQuotes(Str);
-		pVideoPlayer->MovieLoop(v16, 0, _evt->v5);
+		pVideoPlayer->MovieLoop(v16, 0/*, _evt->v5*/);
         if ( !_stricmp(v16, "arbiter good") )
                 {
                   pParty->alignment = PartyAlignment_Good;
--- a/MediaPlayer.cpp	Wed Jul 23 20:28:28 2014 +0300
+++ b/MediaPlayer.cpp	Wed Jul 23 20:53:28 2014 +0300
@@ -786,6 +786,7 @@
       memset(last_resampled_frame_data, 0, sizeof(last_resampled_frame_data));
       memset(last_resampled_frame_linesize, 0, sizeof(last_resampled_frame_linesize));
 
+      audio_data_in_device = nullptr;
       decoding_packet = nullptr;
 	  ioBuffer = nullptr;
 	  format_ctx = nullptr;
@@ -797,6 +798,9 @@
     virtual void Release()
     {
       ReleaseAVCodec();
+
+      if (audio_data_in_device)
+        provider->DeleteStreamingTrack(&audio_data_in_device);
     }
 
     inline void ReleaseAVCodec()
--- a/OpenALSoundProvider.h	Wed Jul 23 20:28:28 2014 +0300
+++ b/OpenALSoundProvider.h	Wed Jul 23 20:53:28 2014 +0300
@@ -77,6 +77,40 @@
       }
     }
 
+    void DeleteStreamingTrack(StreamingTrackBuffer **buffer)
+    {
+      if (!buffer && !*buffer)
+        return;
+      auto track = *buffer;
+
+      int status;
+      alGetSourcei(track->source_id, AL_SOURCE_STATE, &status);
+      if (status == AL_PLAYING)
+      {
+        alSourceStop(track->source_id);
+        if (CheckError()) __debugbreak();
+      }
+
+      int num_processed_buffers = 0;
+      int num_queued_buffers = 0;
+      alGetSourcei(track->source_id, AL_BUFFERS_PROCESSED, &num_processed_buffers);
+      alGetSourcei(track->source_id, AL_BUFFERS_QUEUED, &num_queued_buffers);
+      int num_track_buffers = num_queued_buffers + num_processed_buffers;
+      for (int i = 0; i < num_processed_buffers; ++i)
+      {
+        unsigned int buffer_id;
+        alSourceUnqueueBuffers(track->source_id, 1, &buffer_id);
+        if (!CheckError())
+          alDeleteBuffers(1, &buffer_id);
+        else __debugbreak();
+      }
+
+      alDeleteSources(1, &track->source_id);
+      CheckError();
+
+      delete *buffer;
+      *buffer = nullptr;
+    }
 
     void DeleteBuffer16(TrackBuffer **buffer)
     {
--- a/VideoPlayer.cpp	Wed Jul 23 20:28:28 2014 +0300
+++ b/VideoPlayer.cpp	Wed Jul 23 20:53:28 2014 +0300
@@ -94,7 +94,7 @@
 }
 
 //----- (004BE70E) --------------------------------------------------------
-void VideoPlayer::MovieLoop(const char *pMovieName, int a2, int ScreenSizeFlag/*, int a4*/)
+void VideoPlayer::MovieLoop(const char *pMovieName, int a2/*, int ScreenSizeFlag, int a4*/)
 {
   int v4; // ebp@1
   MSG Msg; // [sp+Ch] [bp-1Ch]@12
@@ -107,7 +107,7 @@
     if ( a2 == 2 )
       v4 = 0;
     ShowCursor(0);//Убрать курсор
-    OpenGlobalMovie(pMovieName, 0, ScreenSizeFlag);
+    OpenGlobalMovie(pMovieName, 0);
     bPlayingMovie = 1;
     field_44 = v4;
     pRenderer->ClearTarget(0);
@@ -360,7 +360,7 @@
 }
 
 //----- (004BF411) --------------------------------------------------------
-void VideoPlayer::OpenGlobalMovie(const char *pFilename, unsigned int bLoop, int a4)
+void VideoPlayer::OpenGlobalMovie(const char *pFilename, unsigned int bLoop/*, int ScreenSizeFlag*/)
 {
 //  unsigned int v10; // eax@11
 
@@ -433,7 +433,7 @@
   if ( this->uMovieFormatSwapped == 1 )
     OpenHouseMovie(Source, LOBYTE(this->bLoopPlaying));
   else if ( this->uMovieFormatSwapped == 2 )
-    OpenGlobalMovie(Source, LOBYTE(this->bLoopPlaying), 1);
+    OpenGlobalMovie(Source, LOBYTE(this->bLoopPlaying));
   else
     __debugbreak();
 }
--- a/VideoPlayer.h	Wed Jul 23 20:28:28 2014 +0300
+++ b/VideoPlayer.h	Wed Jul 23 20:53:28 2014 +0300
@@ -50,12 +50,12 @@
   void OpenHouseMovie(const char *pMovieName, unsigned int a3_1);//0x4BF28F
   void PlayDeathMovie();
   bool AnyMovieLoaded();
-  void OpenGlobalMovie(const char *pFilename, unsigned int bLoop, int a4);
+  void OpenGlobalMovie(const char *pFilename, unsigned int bLoop);
   void _4BF5B2();
   void SelectMovieType();//0x4BF73A
   void _inlined_in_463149();
 
-  void MovieLoop(const char *pMovieName, int a2, int a3);
+  void MovieLoop(const char *pMovieName, int a2);
   void UpdatePalette();
   void LoadMovie(const char *);