changeset 31794:543698dab5d2

Properly close file on error or uninit. Avoids failing with "device busy" e.g. when reinitializing the ao. Fixes bug #1746.
author reimar
date Fri, 30 Jul 2010 18:28:02 +0000
parents 9fdee6f96925
children e9739c0f84ed
files libao2/ao_mpegpes.c
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libao2/ao_mpegpes.c	Fri Jul 30 18:18:03 2010 +0000
+++ b/libao2/ao_mpegpes.c	Fri Jul 30 18:28:02 2010 +0000
@@ -118,25 +118,29 @@
 	if( (ioctl(vo_mpegpes_fd2,AUDIO_SELECT_SOURCE, AUDIO_SOURCE_MEMORY) < 0))
 	{
 		mp_msg(MSGT_VO, MSGL_ERR, "DVB AUDIO SELECT SOURCE: %s\n", strerror(errno));
-		return -1;
+		goto fail;
 	}
 	if((ioctl(vo_mpegpes_fd2,AUDIO_PLAY) < 0))
 	{
 		mp_msg(MSGT_VO, MSGL_ERR, "DVB AUDIO PLAY: %s\n", strerror(errno));
-		return -1;
+		goto fail;
 	}
 	if((ioctl(vo_mpegpes_fd2,AUDIO_SET_AV_SYNC, true) < 0))
 	{
 		mp_msg(MSGT_VO, MSGL_ERR, "DVB AUDIO SET AV SYNC: %s\n", strerror(errno));
-		return -1;
+		goto fail;
 	}
 	//FIXME: in vo_mpegpes audio was initialized as MUTEd
 	if((ioctl(vo_mpegpes_fd2,AUDIO_SET_MUTE, false) < 0))
 	{
 		mp_msg(MSGT_VO, MSGL_ERR, "DVB AUDIO SET MUTE: %s\n", strerror(errno));
-		return -1;
+		goto fail;
 	}
 	return vo_mpegpes_fd2;
+fail:
+	close(vo_mpegpes_fd2);
+	vo_mpegpes_fd2 = -1;
+	return -1;
 }
 #endif
 
@@ -273,7 +277,9 @@
 
 // close audio device
 static void uninit(int immed){
-
+	if (vo_mpegpes_fd2 >= 0)
+		close(vo_mpegpes_fd2);
+	vo_mpegpes_fd2 = -1;
 }
 
 // stop playing and empty buffers (for seeking/pause)