diff options
author | atmos4 <atmos4@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-11-29 17:31:58 +0000 |
---|---|---|
committer | atmos4 <atmos4@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-11-29 17:31:58 +0000 |
commit | 98feb0179d79ae56ae9898b7be7db63f2913f93b (patch) | |
tree | e978259857a67dc32b0e937752e108bfc8319b73 /libvo/vo_dxr3.c | |
parent | f1e6f33f26a53ce3541da8a922eb7308efb4f917 (diff) | |
download | mpv-98feb0179d79ae56ae9898b7be7db63f2913f93b.tar.bz2 mpv-98feb0179d79ae56ae9898b7be7db63f2913f93b.tar.xz |
Newest DXR3 patch (improved 1.0rc2) by David Holm.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3202 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libvo/vo_dxr3.c')
-rw-r--r-- | libvo/vo_dxr3.c | 536 |
1 files changed, 135 insertions, 401 deletions
diff --git a/libvo/vo_dxr3.c b/libvo/vo_dxr3.c index 23de7c8786..1036b4661d 100644 --- a/libvo/vo_dxr3.c +++ b/libvo/vo_dxr3.c @@ -33,25 +33,19 @@ LIBVO_EXTERN (dxr3) -#ifdef USE_LIBAVCODEC - -#ifdef USE_LIBAVCODEC_SO -#include <libffmpeg/avcodec.h> -#else -#include "../libavcodec/avcodec.h" -#endif -static AVPicture picture; -static AVCodec *codec=NULL; -static AVCodecContext codec_context; -extern int avcodec_inited; +#ifdef USE_MP1E +#include <rte.h> +rte_context* mp1e_context = NULL; +rte_codec* mp1e_codec = NULL; +rte_buffer mp1e_buffer; #endif -static unsigned char *picture_buf=NULL; -static unsigned char *outbuf=NULL; +static unsigned char *picture_data[3]; +static unsigned int picture_linesize[3]; static unsigned char *spubuf=NULL; -static int outbuf_size = 0; static int v_width,v_height; static int s_width,s_height; +static int c_width,c_height; static int s_pos_x,s_pos_y; static int d_pos_x,d_pos_y; static int osd_w,osd_h; @@ -70,12 +64,18 @@ static vo_info_t vo_info = "" }; +#ifdef USE_MP1E +void write_dxr3( rte_context* context, void* data, size_t size, void* user_data ) +{ + if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts ) < 0 ) + printf( "VO: [dxr3] Unable to set PTS\n" ); + write( fd_video, data, size ); +} +#endif + static uint32_t init(uint32_t scr_width, uint32_t scr_height, uint32_t width, uint32_t height, uint32_t fullscreen, char *title, uint32_t format) { - int i; - char tmp; - fd_control = open( "/dev/em8300", O_WRONLY ); if( fd_control < 1 ) { @@ -120,283 +120,125 @@ init(uint32_t scr_width, uint32_t scr_height, uint32_t width, uint32_t height, u img_format = format; v_width = width; v_height = height; + s_width = scr_width; + s_height = scr_height; spubuf = malloc(53220); /* 53220 bytes is the standardized max size of a subpic */ - picture_buf=NULL; if( format == IMGFMT_YV12 ) { -#ifdef USE_LIBAVCODEC - +#ifdef USE_MP1E int size; + enum rte_frame_rate frame_rate; - printf("VO: [dxr3] Format: YV12\n"); - - if(!avcodec_inited){ - avcodec_init(); - avcodec_register_all(); - avcodec_inited=1; - } - - /* find the mpeg1 video encoder */ - codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); - if (!codec) + if( !rte_init() ) { - printf( "VO: [dxr3] mpeg1 codec not found! Read DOCS/DXR3!\n"); - return -1; - } - - memset(&codec_context,0,sizeof(codec_context)); - codec_context.bit_rate=100000; // not used - codec_context.frame_rate=25*FRAME_RATE_BASE; - codec_context.gop_size=0; - codec_context.flags=CODEC_FLAG_QSCALE; - codec_context.quality=1; - codec_context.pix_fmt = PIX_FMT_YUV420P; + printf( "VO: [dxr3] Unable to initialize RTE!\n" ); + return -1; + } + if(width<=352 && height<=288){ - codec_context.width=352; - codec_context.height=288; + c_width=352; + c_height=288; } else if(width<=352 && height<=576){ - codec_context.width=352; - codec_context.height=576; + c_width=352; + c_height=576; } else if(width<=480 && height<=576){ - codec_context.width=480; - codec_context.height=576; + c_width=480; + c_height=576; } else if(width<=544 && height<=576){ - codec_context.width=544; - codec_context.height=576; + c_width=544; + c_height=576; } else { - codec_context.width=704; - codec_context.height=576; - } - s_width = codec_context.width; - s_height = codec_context.height;; - - - osd_w=scr_width; - d_pos_x=(codec_context.width-(int)scr_width)/2; - if(d_pos_x<0){ - s_pos_x=-d_pos_x;d_pos_x=0; - osd_w=codec_context.width; - } else s_pos_x=0; - - osd_h=scr_height; - d_pos_y=(codec_context.height-(int)scr_height)/2; - if(d_pos_y<0){ - s_pos_y=-d_pos_y;d_pos_y=0; - osd_h=codec_context.height; - } else s_pos_y=0; - - 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) - { - printf( "VO: [dxr3] Could not open codec\n"); - return -1; - } - - outbuf_size=10000+width*height; - outbuf = malloc(outbuf_size); - - size = codec_context.width*codec_context.height; - picture_buf = malloc((size * 3)/2); /* size for YUV 420 */ - - picture.data[0] = picture_buf; - picture.data[1] = picture.data[0] + size; - picture.data[2] = picture.data[1] + size / 4; - picture.linesize[0] = codec_context.width; - picture.linesize[1] = codec_context.width / 2; - picture.linesize[2] = codec_context.width / 2; - - return 0; -#endif - return -1; - } - else if(format==IMGFMT_BGR24) - { -#ifdef USE_LIBAVCODEC - int size = 0; - printf("VO: [dxr3] Format: BGR24\n"); - - if(!avcodec_inited) - { - avcodec_init(); - avcodec_register_all(); - avcodec_inited=1; + c_width=704; + c_height=576; } - - /* find the mpeg1 video encoder */ - codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); - if (!codec) + + mp1e_context = rte_context_new( c_width, c_height, "mp1e", (void*)0xdeadbeef ); + rte_set_verbosity( mp1e_context, 0 ); + + if( !mp1e_context ) { - printf( "VO: [dxr3] mpeg1 codec not found! Read DOCS/DXR3!\n"); - return -1; - } - - outbuf_size=10000+width*height; - outbuf = malloc(outbuf_size); + printf( "VO: [dxr3] Unable to create context!\n" ); + return -1; + } - memset(&codec_context,0,sizeof(codec_context)); - codec_context.bit_rate=100000; - codec_context.frame_rate=25*FRAME_RATE_BASE; - codec_context.gop_size=0; - codec_context.flags=CODEC_FLAG_QSCALE; - codec_context.quality=1; - codec_context.pix_fmt = PIX_FMT_YUV420P; - - if(width<=352 && height<=288){ - codec_context.width=352; - codec_context.height=288; - } else - if(width<=352 && height<=576){ - codec_context.width=352; - codec_context.height=576; - } else - if(width<=480 && height<=576){ - codec_context.width=480; - codec_context.height=576; - } else - if(width<=544 && height<=576){ - codec_context.width=544; - codec_context.height=576; - } else { - codec_context.width=704; - codec_context.height=576; - } -/* 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){ - s_pos_x=-d_pos_x;d_pos_x=0; - osd_w=codec_context.width; - } else s_pos_x=0; - - osd_h=scr_height; - d_pos_y=(codec_context.height-(int)scr_height)/2; - if(d_pos_y<0){ - s_pos_y=-d_pos_y;d_pos_y=0; - osd_h=codec_context.height; - } else s_pos_y=0; - - 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) + if( !rte_set_format( mp1e_context, "mpeg1" ) ) { - printf( "VO: [dxr3] could not open codec\n"); - return -1; - } - - size = 10000+codec_context.width*codec_context.height; - picture_buf = malloc((size * 3)/2); - - picture.data[0] = picture_buf; - picture.data[1] = picture.data[0] + size; - picture.data[2] = picture.data[1] + size / 4; - picture.linesize[0] = codec_context.width; - picture.linesize[1] = codec_context.width / 2; - picture.linesize[2] = codec_context.width / 2; - return 0; -#endif - return -1; - } - else if(format==IMGFMT_YUY2) - { -#ifdef USE_LIBAVCODEC - int size = 0; - printf("VO: [dxr3] Format: YUY2\n"); + printf( "VO: [dxr3] Unable to set format\n" ); + return -1; + } - if(!avcodec_inited) - { - avcodec_init(); - avcodec_register_all(); - avcodec_inited=1; - } - - /* find the mpeg1 video encoder */ - codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); - if (!codec) - { - printf( "VO: [dxr3] mpeg1 codec not found! Read DOCS/DXR3!\n"); + rte_set_mode( mp1e_context, RTE_VIDEO ); + mp1e_codec = rte_codec_set( mp1e_context, RTE_STREAM_VIDEO, 0, "mpeg1-video" ); + + if( vo_fps < 24.0 ) frame_rate = RTE_RATE_1; + else if( vo_fps < 25.0 ) frame_rate = RTE_RATE_2; + else if( vo_fps < 29.97 ) frame_rate = RTE_RATE_3; + else if( vo_fps < 30.0 ) frame_rate = RTE_RATE_4; + else if( vo_fps < 50.0 ) frame_rate = RTE_RATE_5; + else if( vo_fps < 59.97 ) frame_rate = RTE_RATE_6; + else if( vo_fps < 60.0 ) frame_rate = RTE_RATE_7; + else if( vo_fps > 60.0 ) frame_rate = RTE_RATE_8; + else frame_rate = RTE_RATE_NORATE; + + if( !rte_set_video_parameters( mp1e_context, RTE_YUV420, mp1e_context->width, + mp1e_context->height, frame_rate, + 3e6, "I" ) ) + { + printf( "VO: [dxr3] Unable to set RTE context!\n" ); + rte_context_destroy( mp1e_context ); return -1; - } - - outbuf_size=10000+width*height; - outbuf = malloc(outbuf_size); + } - memset(&codec_context,0,sizeof(codec_context)); - codec_context.bit_rate=100000; - codec_context.frame_rate=25*FRAME_RATE_BASE; - codec_context.gop_size=0; - codec_context.flags=CODEC_FLAG_QSCALE; - codec_context.quality=1; - codec_context.pix_fmt = PIX_FMT_YUV420P; - - if(width<=352 && height<=288){ - codec_context.width=352; - codec_context.height=288; - } else - if(width<=352 && height<=576){ - codec_context.width=352; - codec_context.height=576; - } else - if(width<=480 && height<=576){ - codec_context.width=480; - codec_context.height=576; - } else - if(width<=544 && height<=576){ - codec_context.width=544; - codec_context.height=576; - } else { - codec_context.width=704; - codec_context.height=576; - } - s_width = codec_context.width; - s_height = codec_context.height;; - /* FOR DEBUGGING ONLY!! */ - codec_context.width = width; - codec_context.height = height; + rte_set_input( mp1e_context, RTE_VIDEO, RTE_PUSH, TRUE, NULL, NULL, NULL ); + rte_set_output( mp1e_context, write_dxr3, NULL, NULL ); + if( !rte_init_context( mp1e_context ) ) + { + printf( "VO: [dxr3] Unable to init RTE context!\n" ); + rte_context_delete( mp1e_context ); + return -1; + } + osd_w=scr_width; - d_pos_x=(codec_context.width-(int)scr_width)/2; + d_pos_x=(c_width-(int)scr_width)/2; if(d_pos_x<0){ s_pos_x=-d_pos_x;d_pos_x=0; - osd_w=codec_context.width; + osd_w=c_width; } else s_pos_x=0; osd_h=scr_height; - d_pos_y=(codec_context.height-(int)scr_height)/2; + d_pos_y=(c_height-(int)scr_height)/2; if(d_pos_y<0){ s_pos_y=-d_pos_y;d_pos_y=0; - osd_h=codec_context.height; + osd_h=c_height; } else s_pos_y=0; 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) + + size = c_width*c_height; + + picture_data[0] = malloc((size * 3)/2); + picture_data[1] = picture_data[0] + size; + picture_data[2] = picture_data[1] + size / 4; + picture_linesize[0] = c_width; + picture_linesize[1] = c_width / 2; + picture_linesize[2] = c_width / 2; + memset(picture_data[0],0,size); + + if( !rte_start_encoding( mp1e_context ) ) { - printf( "VO: [dxr3] Could not open codec\n" ); - return -1; - } + printf( "VO: [dxr3] Unable to start mp1e encoding!\n" ); + uninit(); + return -1; + } - size = 10000+codec_context.width*codec_context.height; - picture_buf = malloc((size * 3)/2); - - picture.data[0] = picture_buf; - picture.data[1] = picture.data[0] + size; - picture.data[2] = picture.data[1] + size / 4; - picture.linesize[0] = codec_context.width; - picture.linesize[1] = codec_context.width / 2; - picture.linesize[2] = codec_context.width / 2; return 0; #endif - return -1; + return -1; } else if(format==IMGFMT_MPEGPES) { @@ -419,7 +261,6 @@ static void draw_alpha(int x0, int y0, int w, int h, unsigned char* src, unsigne static void draw_osd(void) { -// vo_draw_text(osd_w,osd_h,draw_alpha); } static uint32_t draw_frame(uint8_t * src[]) @@ -428,120 +269,16 @@ static uint32_t draw_frame(uint8_t * src[]) { int data_left; vo_mpegpes_t *p=(vo_mpegpes_t *)src[0]; - unsigned char *data = p->data; - data_left = p->size; if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts ) < 0 ) - printf( "VO: [dxr3] Unable to set PTS in draw_frame\n" ); + printf( "VO: [dxr3] Unable to set PTS\n" ); + + data_left = p->size; while( data_left ) data_left -= write( fd_video, &((unsigned char*)p->data)[p->size-data_left], data_left ); return 0; } -#ifdef USE_LIBAVCODEC - else if( img_format == IMGFMT_YV12 ) - { - printf("VO: [dxr3] ERROR: Uninplemented\n"); - } - else if( img_format == IMGFMT_BGR24 ) - { - int tmp_size, out_size; - int wrap, wrap3, x, y; - int r, g, b, R, G, B, h = v_height, w = v_width; - unsigned char *s, *Y, *U, *V; - - if(d_pos_x+w>picture.linesize[0]) w=picture.linesize[0]-d_pos_x; - if(d_pos_y+h>codec_context.height) h=codec_context.height-d_pos_y; - - Y = picture.data[0]+d_pos_x+(d_pos_y*picture.linesize[0]); - U = picture.data[1]+(d_pos_x/2)+((d_pos_y/2)*picture.linesize[1]); - V = picture.data[2]+(d_pos_x/2)+((d_pos_y/2)*picture.linesize[2]); - - //BGR24->YUV420P from ffmpeg, see ffmpeg.sourceforge.net for terms of license -#define SCALEBITS 8 -#define ONE_HALF (1 << (SCALEBITS - 1)) -#define FIX(x) ((int) ((x) * (1L<<SCALEBITS) + 0.5)) - wrap = s_width; - wrap3 = w * 3; - s = src[0]+s_pos_x+(s_pos_y*wrap3); - for( y = 0; y < h; y+=2 ) - { - for( x = 0; x < w; x+=2 ) - { - b = s[0]; - g = s[1]; - r = s[2]; - R = r; - G = g; - B = b; - Y[0] = (FIX(0.29900) * r + FIX(0.58700) * g + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - b = s[3]; - g = s[4]; - r = s[5]; - R += r; - G += g; - B += b; - Y[1] = (FIX(0.29900) * r + FIX(0.58700) * g + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - s += wrap3; - Y += wrap; - - b = s[0]; - g = s[1]; - r = s[2]; - R += r; - G += g; - B += b; - Y[0] = (FIX(0.29900) * r + FIX(0.58700) * g + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - b = s[3]; - g = s[4]; - r = s[5]; - R += r; - G += g; - B += b; - Y[1] = (FIX(0.29900) * r + FIX(0.58700) * g + FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; - U[0] = ((- FIX(0.16874) * R - FIX(0.33126) * G - FIX(0.50000) * B + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; - V[0] = ((FIX(0.50000) * R - FIX(0.41869) * G - FIX(0.08131) * B + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; - - U++; - V++; - s -= (wrap3-6); - Y -= (wrap-(3/2)); - } - s += wrap3; - Y += wrap; - } -#undef SCALEBITS -#undef ONE_HALF -#undef FIX(x) - //End of ffmpeg code, see ffmpeg.sourceforge.net for terms of license - if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_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 ); - return 0; - } - else if( img_format == IMGFMT_YUY2 ) - { - int tmp_size, out_size; - int x, y, w = v_width, h = v_height; - - for( y = 0; y < h; y++ ) - { - for( x = 0; x < w; x++ ) - { - } - } - - if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_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 ); - - return 0; - } -#endif printf( "VO: [dxr3] Error in draw_frame(...)\n" ); return -1; @@ -549,67 +286,64 @@ static uint32_t draw_frame(uint8_t * src[]) static void flip_page (void) { + if( img_format == IMGFMT_YV12 ) + { + mp1e_buffer.data = picture_data[0]; + mp1e_buffer.time = vo_pts/90000.0; + mp1e_buffer.user_data = NULL; + rte_push_video_buffer( mp1e_context, &mp1e_buffer ); + } } static uint32_t draw_slice( uint8_t *srcimg[], int stride[], int w, int h, int x0, int y0 ) { - int y, pts; + int y; unsigned char* s; unsigned char* d; - int data_left; - vo_mpegpes_t *p = (vo_mpegpes_t *)srcimg[0]; - + if( img_format == IMGFMT_YV12 ) - { -#ifdef USE_LIBAVCODEC - int out_size, tmp_size; + { +#ifdef USE_MP1E x0+=d_pos_x; y0+=d_pos_y; - if(x0+w>picture.linesize[0]) w=picture.linesize[0]-x0; // !! - if(y0+h>codec_context.height) h=codec_context.height-y0; + if(x0+w>picture_linesize[0]) w=picture_linesize[0]-x0; + if(y0+h>c_height) h=c_height-y0; // Y s=srcimg[0]+s_pos_x+s_pos_y*stride[0]; - d=picture.data[0]+x0+y0*picture.linesize[0]; + d=picture_data[0]+x0+y0*picture_linesize[0]; for( y = 0; y < h; y++) { - memcpy(d,s,w); - s+=stride[0]; - d+=picture.linesize[0]; + memcpy(d,s,w); + s+=stride[0]; + d+=picture_linesize[0]; } w/=2;h/=2;x0/=2;y0/=2; // U s=srcimg[1]+(s_pos_x/2)+(s_pos_y/2)*stride[1]; - d=picture.data[1]+x0+y0*picture.linesize[1]; + d=picture_data[1]+x0+y0*picture_linesize[1]; for( y = 0; y < h; y++) { memcpy(d,s,w); s+=stride[1]; - d+=picture.linesize[1]; + d+=picture_linesize[1]; } // V s=srcimg[2]+(s_pos_x/2)+(s_pos_y/2)*stride[2]; - d=picture.data[2]+x0+y0*picture.linesize[2]; + d=picture_data[2]+x0+y0*picture_linesize[2]; for(y=0;y<h;y++) { memcpy(d,s,w); s+=stride[2]; - d+=picture.linesize[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 - printf( "VO: [dxr3] You need to install ffmpeg.so or libavcodec, read DOCS/DXR3\n" ); + printf( "VO: [dxr3] You need to install mp1e rte, read DOCS/DXR3\n" ); return -1; } @@ -621,15 +355,12 @@ static uint32_t query_format(uint32_t format) { if(format==IMGFMT_MPEGPES) return 1; -#ifdef USE_LIBAVCODEC +#ifdef USE_MP1E if(format==IMGFMT_YV12) return 1; -// if(format==IMGFMT_YUY2) return 0x1|0x4; - if(format==IMGFMT_BGR24) return 1; #else - 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 + if(format==IMGFMT_YV12) {printf("VO: [dxr3] You need to compile with mp1e rte to play this file! (http://zapping.sf.net)\n" ); return 0;} +#endif + else printf( "If this is a DivX add \"-vc odivx\" or if it is an mpeg add \"-vc mpegpes\" otherwise this video format is currently unsupported\n" ); return 0; } @@ -637,11 +368,14 @@ static void uninit(void) { printf( "VO: [dxr3] Uninitializing\n" ); - free(outbuf); - free(picture_buf); - free(spubuf); - close(fd_video); - close(fd_spu); +#ifdef USE_MP1E + if( mp1e_context ) rte_stop( mp1e_context ); + if( mp1e_context ) rte_context_delete( mp1e_context ); + if( picture_data[0] ) free(picture_data[0]); +#endif + if( spubuf ) free(spubuf); + if( fd_video ) close(fd_video); + if( fd_spu ) close(fd_spu); } |