[MPlayer-dev-eng] [PATCH] video pause/resume

David Holm david at realityrift.com
Mon Feb 18 17:21:05 CET 2002


Hi,
here is a nice little patch that implements VOCTRL_PAUSE and
VOCTRL_RESUME. The dxr3 works alot like an audio card, therefore it also
needs to be signal when to pause video playback since it prebuffers a
couple of frames. Without this patch the dxr3 will play out the frames
in the buffer when pausing and after unpausing sync will be lost.

Also, the responsiveness of the em8300 is sluggish at best, therefore I
placed video_out->control(VOCTRL_PAUSE) before audio_out->pause, and
resume after audio_out->resume, this eliminates any chance of small sync
losses (it shouldn't matter on other hardwares anyway).

//David Holm


-------------- next part --------------
Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.397
diff -u -r1.397 mplayer.c
--- mplayer.c	17 Feb 2002 17:35:34 -0000	1.397
+++ mplayer.c	18 Feb 2002 16:31:34 -0000
@@ -1957,6 +1957,9 @@
 #ifdef HAVE_NEW_GUI
       if(use_gui) mplShMem->Playing=2;
 #endif
+      if (video_out && sh_video)
+	 video_out->control(VOCTRL_PAUSE, NULL);
+
       if (audio_out && sh_audio)
          audio_out->pause();	// pause audio, keep data if possible
 
@@ -2005,6 +2008,8 @@
          osd_function=OSD_PLAY;
       if (audio_out && sh_audio)
         audio_out->resume();	// resume audio
+      if (video_out && sh_video)
+        video_out->control(VOCTRL_RESUME, NULL);	// resume video
       (void)GetRelativeTime();	// keep TF around FT in next cycle
 #ifdef HAVE_NEW_GUI
       if(use_gui && !gui_pause_flag) mplShMem->Playing=1; // play from keyboard
Index: libvo/video_out.h
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/video_out.h,v
retrieving revision 1.21
diff -u -r1.21 video_out.h
--- libvo/video_out.h	17 Feb 2002 09:25:09 -0000	1.21
+++ libvo/video_out.h	18 Feb 2002 16:31:36 -0000
@@ -21,7 +21,7 @@
 #define VOCTRL_QUERY_VAA 1
 /* takes a pointer to uint32_t fourcc */
 #define VOCTRL_QUERY_FORMAT 2
-/* signal a device reset (seek/pause) */
+/* signal a device reset seek */
 #define VOCTRL_RESET 3
 /* true if vo driver can use GUI created windows */
 #define VOCTRL_GUISUPPORT 4
@@ -29,6 +29,10 @@
 #define VOCTRL_FULLSCREEN 5
 /* user wants to have screen shot. (currently without args)*/
 #define VOCTRL_SCREENSHOT 6
+/* signal a device pause */
+#define VOCTRL_PAUSE 7
+/* start/resume playback */
+#define VOCTRL_RESUME 8
 
 #define VO_TRUE		1
 #define VO_FALSE	0
Index: libvo/vo_dxr3.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_dxr3.c,v
retrieving revision 1.57
diff -u -r1.57 vo_dxr3.c
--- libvo/vo_dxr3.c	16 Feb 2002 13:41:32 -0000	1.57
+++ libvo/vo_dxr3.c	18 Feb 2002 16:31:36 -0000
@@ -74,10 +74,9 @@
 static AVCodec *avc_codec = NULL;
 static AVCodecContext *avc_context = NULL;
 static AVPicture avc_picture;
-char *picture_buf = NULL;
-char *avc_outbuf = NULL;
 int avc_outbuf_size = 100000;
 #endif
+char *picture_buf = NULL;
 
 #ifdef HAVE_MMX
 #include "mmx.h"
@@ -104,6 +103,8 @@
 
 /* Static variable used in ioctl's */
 static int ioval = 0;
+static int ptsdiff = 0;
+static int writesize = 0;
 
 static vo_info_t vo_info = 
 {
@@ -117,6 +118,22 @@
 {
 	uint32_t flag = 0;
 	switch (request) {
+	case VOCTRL_RESUME:
+		if (!noprebuf) {
+			ioval = EM8300_PLAYMODE_PLAY;
+			if (ioctl(fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval) < 0) {
+				printf("VO: [dxr3] Unable to set playmode!\n");
+			}
+		}
+		return VO_TRUE;
+	case VOCTRL_PAUSE:
+		if (!noprebuf) {
+			ioval = EM8300_PLAYMODE_PAUSED;
+			if (ioctl(fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval) < 0) {
+				printf("VO: [dxr3] Unable to set playmode!\n");
+			}
+		}
+		return VO_TRUE;
 	case VOCTRL_RESET:
 		if (!noprebuf) {
 			close(fd_video);
@@ -156,7 +173,7 @@
 
 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format,const vo_tune_info_t *info)
 {
-	int tmp1, tmp2;
+	int tmp1, tmp2, size;
 	em8300_register_t reg;
     
 	/* Softzoom turned on, downscale */
@@ -226,10 +243,11 @@
 	}
 	ioctl(fd_control, EM8300_IOCTL_SET_ASPECTRATIO, &ioval);
     
+	size = s_width * s_height;
+	picture_buf = malloc((size * 3) / 2);
+	
 	if (format != IMGFMT_MPEGPES) {
 #ifdef USE_LIBAVCODEC
-		int size;
-		
 		avc_codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
 		if (!avc_codec) {
 			printf("VO: [dxr3] Unable to find mpeg1video codec\n");
@@ -291,10 +309,7 @@
 		avc_picture.linesize[0] = s_width;
 		avc_picture.linesize[1] = s_width / 2;
 		avc_picture.linesize[2] = s_width / 2;
-		avc_outbuf = malloc(avc_outbuf_size);
-
-		size = s_width * s_height;
-		picture_buf = malloc((size * 3) / 2);
+		
 		avc_picture.data[0] = picture_buf;
 		avc_picture.data[1] = avc_picture.data[0] + size;
 		avc_picture.data[2] = avc_picture.data[1] + size / 4;
@@ -350,16 +365,16 @@
 			}
 			write(fd_spu, p->data, p->size);
 		} else {
-			write(fd_video, p->data, p->size);
+			writesize = p->size;
+			memcpy(picture_buf, p->data, p->size);
 		}
 		return 0;
 #ifdef USE_LIBAVCODEC
 	} else {
-		int size, srcStride = (img_format == IMGFMT_YUY2) ? (v_width * 2) : (v_width * 3);
+		int srcStride = (img_format == IMGFMT_YUY2) ? (v_width * 2) : (v_width * 3);
 		sws->swScale(sws, src, &srcStride, 0, v_height, avc_picture.data, avc_picture.linesize);
 		draw_osd();
-		size = avcodec_encode_video(avc_context, avc_outbuf, avc_outbuf_size, &avc_picture);
-		write(fd_video, avc_outbuf, size);
+		writesize = avcodec_encode_video(avc_context, picture_buf, avc_outbuf_size, &avc_picture);
 		return 0;
 #endif
 	}
@@ -370,13 +385,14 @@
 {
 #ifdef USE_LIBAVCODEC
 	if (img_format == IMGFMT_YV12) {
-		int out_size = avcodec_encode_video(avc_context, avc_outbuf, avc_outbuf_size, &avc_picture);
+		writesize = avcodec_encode_video(avc_context, picture_buf, avc_outbuf_size, &avc_picture);
 		if (!noprebuf) {
 			ioctl(fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts);
 		}
-		write(fd_video, avc_outbuf, out_size);
 	}
 #endif
+	write(fd_video, picture_buf, writesize);
+	writesize = 0;
 }
 
 static uint32_t draw_slice(uint8_t *srcimg[], int stride[], int w, int h, int x0, int y0)
@@ -400,10 +416,10 @@
 	if (avc_context) {
 		avcodec_close(avc_context);
 	}
+#endif
 	if (picture_buf) {
 		free(picture_buf);
 	}
-#endif
 	if (fd_video) {
 		close(fd_video);
 	}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20020218/23c80bda/attachment.pgp>


More information about the MPlayer-dev-eng mailing list