[Drdivx-commits] SF.net SVN: drdivx: [589] DrDivX/trunk/drffmpeg
Brought to you by:
harikrishnan_v,
seabass089
From: <har...@us...> - 2006-10-04 23:29:01
|
Revision: 589 http://svn.sourceforge.net/drdivx/?rev=589&view=rev Author: harikrishnan_v Date: 2006-10-04 16:28:57 -0700 (Wed, 04 Oct 2006) Log Message: ----------- Add support for DivX codec under os x Modified Paths: -------------- DrDivX/trunk/drffmpeg/Makefile DrDivX/trunk/drffmpeg/libavcodec/Makefile DrDivX/trunk/drffmpeg/libavcodec/divx.c DrDivX/trunk/drffmpeg/libavformat/Makefile Modified: DrDivX/trunk/drffmpeg/Makefile =================================================================== --- DrDivX/trunk/drffmpeg/Makefile 2006-10-04 22:05:23 UTC (rev 588) +++ DrDivX/trunk/drffmpeg/Makefile 2006-10-04 23:28:57 UTC (rev 589) @@ -9,6 +9,10 @@ CFLAGS=$(OPTFLAGS) -I. -I$(SRC_PATH) -I$(SRC_PATH)/export/drffmpeg -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE LDFLAGS+= -g +ifeq ($(CONFIG_DARWIN),yes) +LDFLAGS+=-framework CoreFoundation +endif + ifeq ($(TARGET_GPROF),yes) CFLAGS+=-p LDFLAGS+=-p Modified: DrDivX/trunk/drffmpeg/libavcodec/Makefile =================================================================== --- DrDivX/trunk/drffmpeg/libavcodec/Makefile 2006-10-04 22:05:23 UTC (rev 588) +++ DrDivX/trunk/drffmpeg/libavcodec/Makefile 2006-10-04 23:28:57 UTC (rev 589) @@ -285,6 +285,9 @@ ifeq ($(CONFIG_DIVX),yes) OBJS+= divx.o +#ifeq ($(CONFIG_DARWIN),yes) +#CFLAGS+= -framework CoreFoundation +#endif endif ifeq ($(CONFIG_XSUB),yes) Modified: DrDivX/trunk/drffmpeg/libavcodec/divx.c =================================================================== --- DrDivX/trunk/drffmpeg/libavcodec/divx.c 2006-10-04 22:05:23 UTC (rev 588) +++ DrDivX/trunk/drffmpeg/libavcodec/divx.c 2006-10-04 23:28:57 UTC (rev 589) @@ -48,12 +48,43 @@ BITMAPINFO *outputBmp; } divx_context_t; +#elif defined __MACH__ +#include <CoreFoundation/CoreFoundation.h> + +#define FRAMEWORK "/Library/Frameworks/DivXEncoder.framework" +#define FUNC_NAME "DivXEncoderYUV420" + +#define DIVXENCODER_SUCCESS 0 + +#define DIVXENCODER_OPT_INIT 0 +#define DIVXENCODER_OPT_CONFIG 1 +#define DIVXENCODER_OPT_COMPRESS 2 +#define DIVXENCODER_OPT_DEALLOC 3 + +typedef struct { + char* outputSettings; + int width; + int height; + int timebaserate; + int timebasescale; + int framecount; + int keyframe; + char* inputBuffer; + char* outputBuffer; + int outputBufferSize; +} divx_context_t; + +typedef int (*DivXEncoderYUVFunctionPtr)(divx_context_t *divxContext, int DivXEncoderOpt); + +static DivXEncoderYUVFunctionPtr sDivXEncoderYUVPtr = nil; + #endif #include "avcodec.h" #define MAX_CONFIG_SIZE 1024 +#ifdef _WIN32 static int divx_win32_encode_init(AVCodecContext *avctx) { LRESULT result, size; divx_context_t *x; @@ -211,7 +242,117 @@ return 0; } +#endif +#ifdef __MACH__ +static int divx_macosx_encode_init(AVCodecContext *avctx) { + + int result, size; + divx_context_t *x; + CFBundleRef divxFramework = nil; + CFURLRef divxFrameworkURL = nil; + + av_log(avctx, AV_LOG_DEBUG, "Loaded '%s'\n", FRAMEWORK); + + av_log(avctx, AV_LOG_DEBUG, "divx_encode_init()\n"); + + if (avctx->pix_fmt != PIX_FMT_YUV420P) + { + av_log(avctx, AV_LOG_ERROR, "Color spaces other than 420p not supported\n"); + return -1; + } + + x = avctx->priv_data; // <- ? + + divxFrameworkURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(FRAMEWORK), kCFURLPOSIXPathStyle, true); + divxFramework = CFBundleCreate(kCFAllocatorDefault, divxFrameworkURL); + if (divxFramework == nil) + { + av_log(avctx, AV_LOG_ERROR, "Could not load module '%s'\n", + FRAMEWORK); + + return -1; + } + + sDivXEncoderYUVPtr = (DivXEncoderYUVFunctionPtr)CFBundleGetFunctionPointerForName(divxFramework, CFSTR(FUNC_NAME)); + + if ( sDivXEncoderYUVPtr == nil) + { + CFRelease(divxFramework); + CFRelease(divxFrameworkURL); + av_log(avctx, AV_LOG_ERROR, "Could not lookup function '%s'\n", + FUNC_NAME); + + return -1; + } + + + av_log(avctx, AV_LOG_DEBUG, "Looked up '%s'\n", FUNC_NAME); + + /* no idea what the state stuff means */ + + // we're not showing the window right now, I'll skip this since... whatever + + if ( avctx->opaque) + { + x->outputSettings = avctx->opaque; + } + else + { + char *newState = av_malloc(MAX_CONFIG_SIZE); + char tmp[255]; + + memset(newState, 0, MAX_CONFIG_SIZE); + + if( avctx->flags & CODEC_FLAG_PASS1 ) { + snprintf(tmp, 255, "-bvn1 %d ", avctx->bit_rate); + } else if( avctx->flags & CODEC_FLAG_PASS2 ) { + snprintf(tmp, 255, "-bvnn %d ", avctx->bit_rate); + } else { + snprintf(tmp, 255, "-bv1 %d ", avctx->bit_rate); + } + + strncat(newState, tmp, MAX_CONFIG_SIZE); + strncat(newState, "-vbv 4854000,3145728,2359296 -dir \"/tmp\" -b 1 -nf -profile=3", MAX_CONFIG_SIZE); + + av_log(avctx, AV_LOG_INFO, "codec custom parameters: '%s'\n", newState); + x->outputSettings = newState; + + av_free(newState); + } + + // fps don't know how to handle yet + + // guessing + x->timebaserate = avctx->time_base.den; + x->timebasescale = avctx->time_base.num; + + x->width = avctx->width; + x->height = avctx->height; + + // now check errors and all that crap + result = sDivXEncoderYUVPtr(x, DIVXENCODER_OPT_INIT); + + /* + if (result != DIVXENCODER_SUCCESS) + { + av_log(avctx, AV_LOG_ERROR, "error initializing divx encoder\n"); + return -1; + } + */ + + //x->compressionStarted = 1; + + avctx->extradata = NULL; + avctx->extradata_size = 0; + avctx->codec_tag = ff_get_fourcc("DX50"); + avctx->coded_frame= avcodec_alloc_frame(); + + return 0; +} +#endif + +#ifdef _WIN32 static int divx_win32_encode_frame(AVCodecContext *avctx, unsigned char *frame, int buf_size, void *data) { divx_context_t *x; @@ -284,7 +425,70 @@ return iccompress.lpbiOutput->biSizeImage; } +#endif +#ifdef __MACH__ + +static int divx_macosx_encode_frame(AVCodecContext *avctx, + unsigned char *frame, int buf_size, void *data) { + + divx_context_t *x; + AVFrame *picture; + int size; + char *picture_buf; + int result; + + av_log(avctx, AV_LOG_DEBUG, + "divx_encode_frame(): %d, %d, %d\n", frame, buf_size, data); + + if (avctx->pix_fmt != PIX_FMT_YUV420P) { + av_log(avctx, AV_LOG_ERROR, "Color spaces other than 420p not supported\n"); + return -1; + } + + x = avctx->priv_data; + picture = data; + + size = (avctx->width * avctx->height * 3) / 2; + picture_buf = av_malloc(size); + + avpicture_layout(picture, PIX_FMT_YUV420P, avctx->width, avctx->height, + picture_buf, size); + + x->inputBuffer = picture_buf; + x->outputBuffer = frame; + + result = sDivXEncoderYUVPtr(x, DIVXENCODER_OPT_COMPRESS); + + av_free(picture_buf); + + if (result != DIVXENCODER_SUCCESS) + { + av_log(avctx, AV_LOG_ERROR, "Could not compress frame\n"); + return -1; + } + + av_log(avctx, AV_LOG_DEBUG, "Compressed video frame size: %d\n", x->outputBufferSize); + + // Ignore "lag for B-frame" byte + if ((x->outputBufferSize == 1) && (x->outputBuffer[0] == 0x7f)) + { + return 0; + } + + if (x->keyframe) { + avctx->coded_frame->key_frame = 1; + } else { + avctx->coded_frame->key_frame = 0; + } + + x->framecount++; + + return x->outputBufferSize; +} +#endif + +#ifdef _WIN32 static int divx_win32_encode_close(AVCodecContext *avctx) { divx_context_t *x = avctx->priv_data; @@ -316,12 +520,29 @@ return 0; } +#endif +#ifdef __MACH__ +static int divx_macosx_encode_close(AVCodecContext *avctx) { + + divx_context_t *x = avctx->priv_data; + + av_log(avctx, AV_LOG_DEBUG, + "divx_encode_close()\n"); + + sDivXEncoderYUVPtr(x, DIVXENCODER_OPT_DEALLOC); + + av_free(avctx->coded_frame); + + return 0; +} +#endif + static int divx_encode_init(AVCodecContext *avctx) { #ifdef CONFIG_WIN32 return divx_win32_encode_init(avctx); -#else -#error "Support for Win32 only" +#elif defined __MACH__ + return divx_macosx_encode_init(avctx); #endif } @@ -329,8 +550,8 @@ unsigned char *frame, int buf_size, void *data) { #ifdef CONFIG_WIN32 return divx_win32_encode_frame(avctx, frame, buf_size, data); -#else -#error "Support for Win32 only" +#elif defined __MACH__ + return divx_macosx_encode_frame(avctx, frame, buf_size, data); #endif } Modified: DrDivX/trunk/drffmpeg/libavformat/Makefile =================================================================== --- DrDivX/trunk/drffmpeg/libavformat/Makefile 2006-10-04 22:05:23 UTC (rev 588) +++ DrDivX/trunk/drffmpeg/libavformat/Makefile 2006-10-04 23:28:57 UTC (rev 589) @@ -113,7 +113,9 @@ AVCLIBS+=-lavcodec$(BUILDSUF) -L../libavcodec -lavutil$(BUILDSUF) -L../libavutil endif +ifeq ($(CONFIG_WIN32),yes) EXTRALIB = $(DRFF) +endif include $(SRC_PATH)/common.mak This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |