From ca47f85bf3274fc970650763398795fc5e8e666c Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 9 May 2005 16:40:20 +0000 Subject: Added optimize yuv conversion code --- src/mov_encoder.cc | 102 +++++++++++++++++++++++++++++++++++---------------- src/mov_encoder.h | 6 +++ src/server.cc | 14 ++++--- src/server_status.cc | 6 ++- 4 files changed, 90 insertions(+), 38 deletions(-) diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc index f9d47e7..0e2b935 100644 --- a/src/mov_encoder.cc +++ b/src/mov_encoder.cc @@ -39,6 +39,10 @@ /* * $Log$ + * Revision 1.15 2005/05/09 16:40:20 deva + * + * Added optimize yuv conversion code + * * Revision 1.14 2005/05/07 10:56:18 deva * Changed print outs * @@ -80,9 +84,9 @@ MovEncoder::MovEncoder(const char *filename) yuv.w = w; yuv.h = h; yuv.p = w; - yuv.y = new unsigned char [w*h]; - yuv.u = new unsigned char [w*h/4]; - yuv.v = new unsigned char [w*h/4]; + yuv.y = new unsigned char [w*h * 2]; + yuv.u = new unsigned char [w*h];// [w*h/4] + yuv.v = new unsigned char [w*h];// [w*h/4] ////////////LIBDV STUFF/////////////// @@ -132,7 +136,7 @@ MovEncoder::MovEncoder(const char *filename) fame_par.coding = coding; // quality is a percentage, which controls compression versus quality. - fame_par.quality = 100; + fame_par.quality = 100; // FIXME: This should be in config file! // slices_per_frame is the number of frame slices per frame. More slices provide // better error recovery. There must be at least one slice per frame, and at most @@ -150,7 +154,7 @@ MovEncoder::MovEncoder(const char *filename) // shape_quality is percentage determing the average binary shape accuracy in // video with arbitrary shape. - fame_par.shape_quality = 100; + fame_par.shape_quality = 1; // search_range specifies the motion estimation search range in pixel unit. // Small search ranges work best with slow motion videos, whereas larger search @@ -159,7 +163,7 @@ MovEncoder::MovEncoder(const char *filename) // verbose when set to 1 outputs information on copyright, modules used and // current frame on standard error. - fame_par.verbose = 1; + fame_par.verbose = 0; fame_init(fame_context, &fame_par, fame_buffer, FAME_BUFFER_SIZE); // FIXME: fame_init return a new context, or NULL if an error occurred. @@ -182,7 +186,9 @@ void MovEncoder::encode(Frame *dvframe) encode_audio(dvframe); } +//#define RGB +#ifdef RGB #define _CLAMP(x) (unsigned char) ((x)<0?0:(((x)>255)?255:(x))) inline void rgb_to_yuv(unsigned char *rgb, unsigned char &y, unsigned char &u, unsigned char &v) @@ -191,17 +197,18 @@ inline void rgb_to_yuv(unsigned char *rgb, unsigned char &y, unsigned char &u, u v = _CLAMP( 0.439 * rgb[0] - 0.368 * rgb[1] - 0.071 * rgb[2] + 128); u = _CLAMP(-0.148 * rgb[0] - 0.291 * rgb[1] + 0.439 * rgb[2] + 128); } +#endif void MovEncoder::encode_video(Frame *dvframe) { // Decode DV Frame to YUV int w = 720; int h = 576; - unsigned char rgb[720*576*4]; unsigned char *pixels[3]; int pitches[3]; +#ifdef RGB pixels[ 0 ] = rgb; pixels[ 1 ] = NULL; pixels[ 2 ] = NULL; @@ -209,6 +216,7 @@ void MovEncoder::encode_video(Frame *dvframe) pitches[ 0 ] = 720 * 3; pitches[ 1 ] = 0; pitches[ 2 ] = 0; +#endif if(!dvdecoder) { dvdecoder = dv_decoder_new(FALSE/*this value is unused*/, FALSE, FALSE); @@ -223,39 +231,69 @@ void MovEncoder::encode_video(Frame *dvframe) dvdecoder->num_dif_seqs = 12; } +#ifdef RGB dv_decode_full_frame(dvdecoder, dvframe->data, e_dv_color_rgb, pixels, pitches); - /* - e_dv_color_yuv, - (uint8_t**) &yuv.y, //pixels, - (int*) &yuv.w);//pitches); - */ // cvt rgb to yuv - for (int y=0; ydata, + e_dv_color_yuv, + pixels, + pitches); + + int w2 = w / 2; + uint8_t *y = yuv.y; + uint8_t *cb = yuv.u; + uint8_t *cr = yuv.v; + uint8_t *p = rgb; + + for ( int i = 0; i < h; i += 2 ) { + // process two scanlines (one from each field, interleaved) + for ( int j = 0; j < w2; j++ ) { + // packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] + *( y++ ) = *( p++ ); + *( cb++ ) = *( p++ ); + *( y++ ) = *( p++ ); + *( cr++ ) = *( p++ ); + } + + // process next two scanlines (one from each field, interleaved) + for ( int j = 0; j < w2; j++ ) { + // skip every second line for U and V + *( y++ ) = *( p++ ); + p++; + *( y++ ) = *( p++ ); + p++; + } + } +#endif // Encode YUV frame and write it to disk. fame_start_frame(fame_context, &yuv, 0); diff --git a/src/mov_encoder.h b/src/mov_encoder.h index 17412a2..457b577 100644 --- a/src/mov_encoder.h +++ b/src/mov_encoder.h @@ -36,6 +36,10 @@ /* * $Log$ + * Revision 1.7 2005/05/09 16:40:20 deva + * + * Added optimize yuv conversion code + * * Revision 1.6 2005/05/05 20:41:38 deva * * Removed the last pieces of ffmpeg... replaced it with libfame... @@ -89,6 +93,8 @@ class MovEncoder { // libdv decoder dv_decoder_t *dvdecoder; + + unsigned char rgb[720*576*4]; }; #endif diff --git a/src/server.cc b/src/server.cc index 7d6127d..76ba8c9 100644 --- a/src/server.cc +++ b/src/server.cc @@ -31,6 +31,10 @@ /* * $Log$ + * Revision 1.13 2005/05/09 16:40:20 deva + * + * Added optimize yuv conversion code + * * Revision 1.12 2005/05/07 10:56:18 deva * Changed print outs * @@ -294,11 +298,11 @@ void newConnection(Socket *socket) // printf("Read: %d bytes ", ret); // printf("typ: %d ", h.header_type); - fprintf(stdout, "cpr: %s ", cpr); - fprintf(stdout, "frz: %d ", h.header.h_data.freeze); - fprintf(stdout, "sht: %d ", h.header.h_data.snapshot); - fprintf(stdout, "save: %d ", h.header.h_data.savestate); - fflush(stdout); +// fprintf(stdout, "cpr: %s ", cpr); +// fprintf(stdout, "frz: %d ", h.header.h_data.freeze); +// fprintf(stdout, "sht: %d ", h.header.h_data.snapshot); +// fprintf(stdout, "save: %d ", h.header.h_data.savestate); +// fflush(stdout); if(h.header.h_data.snapshot) { if(freeze_frame) { diff --git a/src/server_status.cc b/src/server_status.cc index 66cc34c..1e58ee7 100644 --- a/src/server_status.cc +++ b/src/server_status.cc @@ -31,6 +31,10 @@ /* * $Log$ + * Revision 1.4 2005/05/09 16:40:20 deva + * + * Added optimize yuv conversion code + * * Revision 1.3 2005/05/03 08:31:59 deva * Removed the error object, and replaced it with a more generic info object. * @@ -72,7 +76,7 @@ void ServerStatus::checkPoint() for(int cnt = 0; cnt < BUFFERSIZE; cnt++) { total += (double)frametime[cnt]; } - fprintf(stderr, "[ms: %d, fps: %f]\t", frametime[0], 1000000.0 / (total / (double)BUFFERSIZE) ); + fprintf(stderr, "[ms: %d, fps: %f]\n", frametime[0], 1000000.0 / (total / (double)BUFFERSIZE) ); } -- cgit v1.2.3