changeset 2968:9989497ab31e

Minor fixes by David.
author atmos4
date Sun, 18 Nov 2001 13:10:22 +0000
parents 3f4e4ade4897
children 291f45785de9
files libao2/ao_dxr3.c libvo/vo_dxr3.c
diffstat 2 files changed, 124 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/libao2/ao_dxr3.c	Sun Nov 18 10:17:37 2001 +0000
+++ b/libao2/ao_dxr3.c	Sun Nov 18 13:10:22 2001 +0000
@@ -63,50 +63,59 @@
   fd_audio = open( "/dev/em8300_ma", O_WRONLY );  
   if( fd_audio < 0 )
   {
-    printf("Can't open audio device /dev/em8300_ma  -> nosound\n");
+    printf("AO: [dxr3] Can't open audio device /dev/em8300_ma  -> nosound\n");
     return 0;
   }
   
   fd_control = open( "/dev/em8300", O_WRONLY );
   if( fd_control < 0 )
   {
-    printf("Can't open em8300 control /dev/em8300\n");
+    printf("AO: [dxr3] Can't open em8300 control /dev/em8300\n");
     return 0;
   }
   
   ao_format = format;
-  ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_format);
+  if( ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_format) < 0 )
+    printf( "AO: [dxr3] Unable to set audio format\n" );
   if(format == AFMT_AC3 && ao_format != AFMT_AC3) 
   {
-      printf("Can't set audio device /dev/em8300_ma to AC3 output\n");
+      printf("AO: [dxr3] Can't set audio device /dev/em8300_ma to AC3 output\n");
       return 0;
   }
-  printf("audio_setup: sample format: %s (requested: %s)\n",
+  printf("AO: [dxr3] Sample format: %s (requested: %s)\n",
     audio_out_format_name(ao_format), audio_out_format_name(format));
   
   if(format != AFMT_AC3) 
   {
 	ao_channels=channels-1;
-        ioctl (fd_audio, SNDCTL_DSP_STEREO, &ao_channels);
+        if( ioctl (fd_audio, SNDCTL_DSP_STEREO, &ao_channels) < 0 )
+	    printf( "AO: [dxr3] Unable to set number of channels\n" );
   
 	// set rate
 	ao_samplerate=rate;
-	ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_samplerate);
-	printf("audio_setup: using %d Hz samplerate (requested: %d)\n",ao_samplerate,rate);
+	if( ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_samplerate) < 0 )
+	    printf( "AO: [dxr3] Unable to set samplerate\n" );
+	printf("AO: [dxr3] Using %d Hz samplerate (requested: %d)\n",ao_samplerate,rate);
   }
 
-  if(ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1){
+  if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1 )
+  {
       int r=0;
-      printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
-      if(ioctl(fd_audio, SNDCTL_DSP_GETBLKSIZE, &r)==-1){
-          printf("audio_setup: %d bytes/frag (config.h)\n",ao_outburst);
-      } else { 
+      printf("AO: [dxr3] Driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
+      if( ioctl( fd_audio, SNDCTL_DSP_GETBLKSIZE, &r) ==-1 )
+      {
+          printf( "AO: [dxr3] %d bytes/frag (config.h)\n", ao_outburst );
+      } 
+      else 
+      { 
           ao_outburst=r;
-          printf("audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_outburst);
+          printf( "AO: [dxr3] %d bytes/frag (GETBLKSIZE)\n",ao_outburst);
       }
-  } else {
-      printf("audio_setup: frags: %3d/%d  (%d bytes/frag)  free: %6d\n",
-          dxr3_buf_info.fragments, dxr3_buf_info.fragstotal, dxr3_buf_info.fragsize, dxr3_buf_info.bytes);
+  } 
+  else 
+  {
+      printf("AO: [dxr3] frags: %3d/%d  (%d bytes/frag)  free: %6d\n",
+          dxr3_buf_info.fragments+1, dxr3_buf_info.fragstotal, dxr3_buf_info.fragsize, dxr3_buf_info.bytes);
       if(ao_buffersize==-1) ao_buffersize=dxr3_buf_info.bytes;
       ao_outburst=dxr3_buf_info.fragsize;
   }
@@ -128,7 +137,7 @@
     }
     free(data);
     if(ao_buffersize==0){
-        printf("\n   ***  Your audio driver DOES NOT support select()  ***\n");
+        printf("\nAO: [dxr3]   ***  Your audio driver DOES NOT support select()  ***\n");
           printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
         return 0;
     }
@@ -136,7 +145,8 @@
   }
 
   ioval = EM8300_PLAYMODE_PLAY;
-  ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval );
+  if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
+    printf( "AO: [dxr3] Unable to set playmode\n" );
   close( fd_control );
 
   return 1;
@@ -145,60 +155,82 @@
 // close audio device
 static void uninit()
 {
-    ioctl(fd_audio, SNDCTL_DSP_RESET, NULL);
+    printf( "AO: [dxr3] Uninitializing\n" );
+    if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
+	printf( "AO: [dxr3] Unable to reset device\n" );
     close( fd_audio );
 }
 
 // stop playing and empty buffers (for seeking/pause)
 static void reset()
 {
-    uninit();
-    if(fd_audio<0)
-    {
-	printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE ***\n");
-	return;
-    }
-
-  ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_format);
-  if(ao_format != AFMT_AC3) 
-  {
-    ioctl (fd_audio, SNDCTL_DSP_STEREO, &ao_channels);
-    ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_samplerate);
-  }
+    if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
+	printf( "AO: [dxr3] Unable to reset device\n" );
 }
 
 // stop playing, keep buffers (for pause)
 static void audio_pause()
 {
     // for now, just call reset();
-    reset();
+//  reset();
+  int ioval;
+  fd_control = open( "/dev/em8300", O_WRONLY );
+  if( fd_control < 0 )
+    printf( "AO: [dxr3] Oops, unable to pause playback\n" );
+  else
+  {
+    ioval = EM8300_PLAYMODE_PAUSED;
+    if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
+	printf( "AO: [dxr3] Unable to pause playback\n" );
+    close( fd_control );
+  }
 }
 
 // resume playing, after audio_pause()
 static void audio_resume()
 {
+  int ioval;
+  fd_control = open( "/dev/em8300", O_WRONLY );
+  if( fd_control < 0 )
+    printf( "AO: [dxr3] Oops, unable to resume playback\n" );
+  else
+  {
+    ioval = EM8300_PLAYMODE_PLAY;
+    if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
+	printf( "AO: [dxr3] Unable to resume playback\n" );
+    close( fd_control );
+  }
 }
 
 
 // return: how many bytes can be played without blocking
 static int get_space()
 {
-  if(ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)!=-1)
-        return (dxr3_buf_info.fragments*dxr3_buf_info.fragsize);
-  return 0;
+    int space = 0;
+    if( ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info) < 0 )
+    {
+	printf( "AO: [dxr3] Unable to get free space in buffer\n" );
+	return 0;
+    }
+    
+    space = dxr3_buf_info.fragments*dxr3_buf_info.fragsize;
+    return space;
 }
 
 static int play(void* data,int len,int flags)
 {
-    ioctl( fd_audio, EM8300_IOCTL_AUDIO_SETPTS, &ao_pts );
+    int pts = ao_pts;
+    if( ioctl( fd_audio, EM8300_IOCTL_AUDIO_SETPTS, &pts ) < 0 )
+	printf( "AO: [dxr3] Unable to set pts\n" );
     return write(fd_audio,data,len);
 }
 
 // return: how many unplayed bytes are in the buffer
 static int get_delay()
 {
-      int r=0;
-     ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r);
+     int r=0;
+     if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r) < 0 )
+        printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" );
      return r;
 }
 
--- a/libvo/vo_dxr3.c	Sun Nov 18 10:17:37 2001 +0000
+++ b/libvo/vo_dxr3.c	Sun Nov 18 13:10:22 2001 +0000
@@ -105,15 +105,6 @@
 	return -1;
     }
     
-    /*for( i = 0; i < 64; i+= 4 )
-    {
-	tmp = palette[i];
-	palette[i] = palette[i+3];
-	palette[i+3] = tmp;
-	tmp = palette[i+1];
-	palette[i+1] = palette[i+2];
-	palette[i+2] = tmp;
-    }*/
     if( ioctl( fd_spu, EM8300_IOCTL_SPU_SETPALETTE, palette ) < 0 )
     {
 	printf( "VO: [dxr3] Unable to set subpicture palette!\n" );
@@ -121,7 +112,7 @@
     }
 
     ioval = EM8300_PLAYMODE_PLAY;
-    if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0)
+    if( ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval ) < 0 )
 	printf( "VO: [dxr3] Unable to set playmode!\n" );
     
     close( fd_control );
@@ -138,7 +129,7 @@
 
 	int size;
 
-	printf("Format: YV12\n");
+	printf("VO: [dxr3] Format: YV12\n");
 
         if(!avcodec_inited){
 	  avcodec_init();
@@ -148,8 +139,9 @@
     
         /* find the mpeg1 video encoder */
         codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
-        if (!codec) {
-            fprintf(stderr, "mpeg1 codec not found\nRead DOCS/DXR3!\n");
+        if (!codec) 
+	{
+            printf( "VO: [dxr3] mpeg1 codec not found! Read DOCS/DXR3!\n");
             return -1;
         }
             
@@ -197,11 +189,12 @@
           osd_h=codec_context.height;
         } else s_pos_y=0;
     
-        printf("[vo] position mapping: %d;%d => %d;%d\n",s_pos_x,s_pos_y,d_pos_x,d_pos_y);
+        printf("VO: [dxr3] position mapping: %d;%d => %d;%d\n",s_pos_x,s_pos_y,d_pos_x,d_pos_y);
     
         /* open it */
-        if (avcodec_open(&codec_context, codec) < 0) {
-            fprintf(stderr, "could not open codec\n");
+        if (avcodec_open(&codec_context, codec) < 0) 
+	{
+            printf( "VO: [dxr3] Could not open codec\n");
             return -1;
         }
         
@@ -226,7 +219,7 @@
     {
 #ifdef USE_LIBAVCODEC
 	int size = 0;
-	printf("Format: BGR24\n");
+	printf("VO: [dxr3] Format: BGR24\n");
 
         if(!avcodec_inited)
 	{
@@ -239,7 +232,7 @@
         codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
         if (!codec) 
 	{
-            fprintf(stderr, "mpeg1 codec not found\nRead DOCS/DXR3!\n");
+            printf( "VO: [dxr3] mpeg1 codec not found! Read DOCS/DXR3!\n");
             return -1;
         }
             
@@ -254,7 +247,7 @@
         codec_context.quality=1;
 	codec_context.pix_fmt = PIX_FMT_YUV420P;
 
-        /*if(width<=352 && height<=288){
+        if(width<=352 && height<=288){
           codec_context.width=352;
           codec_context.height=288;
         } else
@@ -272,10 +265,10 @@
         } else {
           codec_context.width=704;
           codec_context.height=576;
-        }*/
-	s_width = codec_context.width = width;
+        }
+/*	s_width = codec_context.width = width;
 	s_height = codec_context.height = height;
-
+*/
         osd_w=scr_width;
         d_pos_x=(codec_context.width-(int)scr_width)/2;
         if(d_pos_x<0){
@@ -290,11 +283,12 @@
           osd_h=codec_context.height;
         } else s_pos_y=0;
     
-        printf("[vo] position mapping: %d;%d => %d;%d\n",s_pos_x,s_pos_y,d_pos_x,d_pos_y);
+        printf("VO: [dxr3] position mapping: %d;%d => %d;%d\n",s_pos_x,s_pos_y,d_pos_x,d_pos_y);
     
         /* open it */
-        if (avcodec_open(&codec_context, codec) < 0) {
-            fprintf(stderr, "could not open codec\n");
+        if (avcodec_open(&codec_context, codec) < 0) 
+	{
+            printf( "VO: [dxr3] could not open codec\n");
             return -1;
         }
 
@@ -315,7 +309,7 @@
     {
 #ifdef USE_LIBAVCODEC
 	int size = 0;
-	printf("Format: YUY2\n");
+	printf("VO: [dxr3] Format: YUY2\n");
 
         if(!avcodec_inited)
 	{
@@ -328,7 +322,7 @@
         codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
         if (!codec) 
 	{
-            fprintf(stderr, "mpeg1 codec not found\nRead DOCS/DXR3!\n");
+            printf( "VO: [dxr3] mpeg1 codec not found! Read DOCS/DXR3!\n");
 	    return -1;
         }
             
@@ -385,8 +379,9 @@
         printf("VO: [dxr3] position mapping: %d;%d => %d;%d\n",s_pos_x,s_pos_y,d_pos_x,d_pos_y);
     
         /* open it */
-        if (avcodec_open(&codec_context, codec) < 0) {
-            fprintf(stderr, "could not open codec\n");
+        if (avcodec_open(&codec_context, codec) < 0) 
+	{
+            printf(stderr, "VO: [dxr3] Could not open codec\n");
             return -1;
         }
 
@@ -409,7 +404,7 @@
 	return 0;
     }
 
-    printf( "Format: Unsupported\n" );
+    printf( "VO: [dxr3] Format: Unsupported\n" );
     return -1;
 }
 
@@ -420,51 +415,26 @@
 
 static void draw_alpha(int x0, int y0, int w, int h, unsigned char* src, unsigned char *srca, int srcstride)
 {
-    int x,y,index=0;
-    int n_rles=0, prev_nibbled=0, nibbled=0;
-    char prevcolor=0;
-    unsigned char *dst = spubuf;
-    unsigned short *subpic_size, *cs_table;
-    subpic_size = dst+=2;
-    cs_table = dst+=2;
-    prevcolor = src[0];
-    for( y = 0; y <= (h-1); y+=2 )
-    {
-	for( x = 0; x < w; x++ )
-	{
-	    if( prevcolor == src[x+(y*w)] ) index++;
-	    else
-	    {
-		if( prevcolor < 64 )
-		    prevcolor = 0x00;
-		else if( prevcolor < 128 )
-		    prevcolor = 0x01;
-		else if( prevcolor < 192 )
-		    prevcolor = 0x02;
-		else
-		    prevcolor = 0x03;
-	    }
-	}
-    }
-    
-    ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts );
-    write( fd_spu, spubuf, (dst-spubuf) );
 }
 
 static void draw_osd(void)
 {
-    vo_draw_text(osd_w,osd_h,draw_alpha);
+//    vo_draw_text(osd_w,osd_h,draw_alpha);
 }
 
 static uint32_t draw_frame(uint8_t * src[])
 {
+    int pts = 0;
     if( img_format == IMGFMT_MPEGPES )
     {
         int data_left;
 	vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
-    
+	unsigned char *data = p->data;
+
 	data_left = p->size;
-	ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts );	
+	pts = p->timestamp;
+	if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &pts ) < 0 )
+	    printf( "VO: [dxr3] Unable to set PTS in draw_frame\n" );
 	while( data_left )
 	    data_left -= write( fd_video, &((unsigned char*)p->data)[p->size-data_left], data_left );
 
@@ -473,7 +443,7 @@
 #ifdef USE_LIBAVCODEC
     else if( img_format == IMGFMT_YV12 )
     {
-	printf("ERROR: Uninplemented\n");
+	printf("VO: [dxr3] ERROR: Uninplemented\n");
     }
     else if( img_format == IMGFMT_BGR24 )
     {
@@ -546,6 +516,9 @@
 #undef ONE_HALF
 #undef FIX(x)
 	//End of ffmpeg code, see ffmpeg.sourceforge.net for terms of license
+	pts = vo_pts;
+	if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &pts ) < 0 )
+	    printf( "VO: [dxr3] Unable to set PTS in draw_frame\n" );
         tmp_size = out_size = avcodec_encode_video(&codec_context, outbuf, outbuf_size, &picture);
 	while( out_size )
 		out_size -= write( fd_video, &outbuf[tmp_size-out_size], out_size );
@@ -562,7 +535,9 @@
 	    {
 	    }
 	}
-	
+	pts = vo_pts;
+	if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &pts ) < 0 )
+	    printf( "VO: [dxr3] Unable to set PTS in draw_frame\n" );
         tmp_size = out_size = avcodec_encode_video(&codec_context, outbuf, outbuf_size, &picture);
         while( out_size )
 		out_size -= write( fd_video, &outbuf[tmp_size-out_size], out_size );
@@ -571,7 +546,7 @@
     }
 #endif
     
-    printf( "Error in draw_frame(...)\n" );
+    printf( "VO: [dxr3] Error in draw_frame(...)\n" );
     return -1;
 }
 
@@ -581,7 +556,7 @@
 
 static uint32_t draw_slice( uint8_t *srcimg[], int stride[], int w, int h, int x0, int y0 )
 {
-    int y;
+    int y, pts;
     unsigned char* s;
     unsigned char* d;
     int data_left;
@@ -627,26 +602,19 @@
 	    s+=stride[2];
 	    d+=picture.linesize[2];
 	}
+	pts = vo_pts;
 	
+	if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &pts ) < 0 )
+	    printf( "VO: [dxr3] Unable to set PTS in draw_slice\n" );
         tmp_size = out_size = avcodec_encode_video(&codec_context, outbuf, outbuf_size, &picture);
         while( out_size )
 		out_size -= write( fd_video, &outbuf[tmp_size-out_size], out_size );
 
 	return 0;
 #endif
-	return -1;
-    }
-    else if( img_format == IMGFMT_BGR24 )
-    {
+	printf( "VO: [dxr3] You need to install ffmpeg.so or libavcodec, read DOCS/DXR3\n" );
 	return -1;
     }
-    else if( img_format == IMGFMT_MPEGPES )
-    {
-        data_left = p->size;
-        while( data_left )
-		data_left -= write( fd_video, &((unsigned char*)p->data)[p->size-data_left], data_left );
-	return 0;
-    }
 
     return -1;
 }
@@ -655,15 +623,15 @@
 static uint32_t
 query_format(uint32_t format)
 {
-    if(format==IMGFMT_MPEGPES) return 0x2|0x4;
+    if(format==IMGFMT_MPEGPES) return 1;
 #ifdef USE_LIBAVCODEC
-    if(format==IMGFMT_YV12) return 0x1|0x4;
+    if(format==IMGFMT_YV12) return 1;
 //    if(format==IMGFMT_YUY2) return 0x1|0x4;
-    if(format==IMGFMT_BGR24) return 0x1|0x4;
+    if(format==IMGFMT_BGR24) return 1;
 #else
-    if(format==IMGFMT_YV12) {printf("You need to compile with libavcodec or ffmpeg.so to play this file!\n" ); return 0;}
-    if(format==IMGFMT_YUY2) {printf("You need to compile with libavcodec or ffmpeg.so to play this file!\n" ); return 0;}
-    if(format==IMGFMT_BGR24) {printf("You need to compile with libavcodec or ffmpeg.so to play this file!\n" ); return 0;}
+    if(format==IMGFMT_YV12) {printf("VO: [dxr3] You need to compile with libavcodec or ffmpeg.so to play this file!\n" ); return 0;}
+    if(format==IMGFMT_YUY2) {printf("VO: [dxr3] You need to compile with libavcodec or ffmpeg.so to play this file!\n" ); return 0;}
+    if(format==IMGFMT_BGR24) {printf("VO: [dxr3] You need to compile with libavcodec or ffmpeg.so to play this file!\n" ); return 0;}
 #endif    
     return 0;
 }
@@ -671,6 +639,7 @@
 static void
 uninit(void)
 {
+    printf( "VO: [dxr3] Uninitializing\n" );
     free(outbuf);
     free(picture_buf);
     free(spubuf);