diff Plugins/Input/aac/src/libmp4.c @ 250:b9e6cdce7219 trunk

[svn] Reduce code duplication and add a return statement.
author chainsaw
date Sat, 03 Dec 2005 09:27:11 -0800
parents 094ef8a0a9fd
children 1e642d74d68c
line wrap: on
line diff
--- a/Plugins/Input/aac/src/libmp4.c	Sat Dec 03 09:14:33 2005 -0800
+++ b/Plugins/Input/aac/src/libmp4.c	Sat Dec 03 09:27:11 2005 -0800
@@ -203,6 +203,7 @@
       bPlaying = FALSE;
       g_static_mutex_unlock(&mutex);
       g_thread_exit(NULL);
+      return(NULL);
     }else{
       faacDecHandle	decoder;
       unsigned char	*buffer	= NULL;
@@ -217,31 +218,14 @@
 
       decoder = faacDecOpen();
       MP4GetTrackESConfiguration(mp4file, mp4track, &buffer, &bufferSize);
-      if(!buffer){
-	g_free(args);
-	faacDecClose(decoder);
-	MP4Close(mp4file);
-	bPlaying = FALSE;
-	g_static_mutex_unlock(&mutex);
-	g_thread_exit(NULL);
-      }
-      if(faacDecInit2(decoder, buffer, bufferSize, &samplerate, &channels)<0){
-	g_free(args);
-	faacDecClose(decoder);
-	MP4Close(mp4file);
-	bPlaying = FALSE;
-	g_static_mutex_unlock(&mutex);
-	g_thread_exit(NULL);
-      }
+      if(!buffer)
+	goto out;
+      if(faacDecInit2(decoder, buffer, bufferSize, &samplerate, &channels)<0)
+	goto out;
       g_free(buffer);
       if(channels == 0){
 	g_print("Number of Channels not supported\n");
-	g_free(args);
-	faacDecClose(decoder);
-	MP4Close(mp4file);
-	bPlaying = FALSE;
-	g_static_mutex_unlock(&mutex);
-	g_thread_exit(NULL);
+	goto out;
       }
       duration = MP4GetTrackDuration(mp4file, mp4track);
       msDuration = MP4ConvertFromTrackDuration(mp4file, mp4track, duration,
@@ -269,13 +253,7 @@
 	buffer=NULL;
 	bufferSize=0;
 	if(sampleID > numSamples){
-	  mp4_ip.output->close_audio();
-	  g_free(args);
-	  faacDecClose(decoder);
-	  MP4Close(mp4file);
-	  bPlaying = FALSE;
-	  g_static_mutex_unlock(&mutex);
-	  g_thread_exit(NULL);
+	  goto out;
 	}
 	rc = MP4ReadSample(mp4file, mp4track, sampleID++, &buffer, &bufferSize,
 			   NULL, NULL, NULL, NULL);
@@ -285,25 +263,13 @@
 	  sampleBuffer = NULL;
 	  sampleID=0;
 	  mp4_ip.output->buffer_free();
-	  mp4_ip.output->close_audio();
-	  g_free(args);
-	  faacDecClose(decoder);
-	  MP4Close(mp4file);
-	  bPlaying = FALSE;
-	  g_static_mutex_unlock(&mutex);
-	  g_thread_exit(NULL);
+	  goto out;
 	}else{
 	  sampleBuffer = faacDecDecode(decoder, &frameInfo, buffer, bufferSize);
 	  if(frameInfo.error > 0){
 	    g_print("MP4: %s\n",
 		    faacDecGetErrorMessage(frameInfo.error));
-	    mp4_ip.output->close_audio();
-	    g_free(args);
-	    faacDecClose(decoder);
-	    MP4Close(mp4file);
-	    bPlaying = FALSE;
-	    g_static_mutex_unlock(&mutex);
-	    g_thread_exit(NULL);
+	    goto out;
 	  }
 	  if(buffer){
 	    g_free(buffer); buffer=NULL; bufferSize=0;
@@ -321,6 +287,7 @@
       while(bPlaying && mp4_ip.output->buffer_free()){
 	xmms_usleep(10000);
       }
+out:
       mp4_ip.output->close_audio();
       g_free(args);
       faacDecClose(decoder);
@@ -328,6 +295,7 @@
       bPlaying = FALSE;
       g_static_mutex_unlock(&mutex);
       g_thread_exit(NULL);
+      return(NULL);
     }
   } else{
     // WE ARE READING AN AAC FILE