SRCS_MPLAYER-$(DIRECTFB) += libvo/vo_directfb2.c
SRCS_MPLAYER-$(DXR3) += libvo/vo_dxr3.c
SRCS_MPLAYER-$(FBDEV) += libvo/vo_fbdev.c libvo/vo_fbdev2.c
+SRCS_MPLAYER-yes += libvo/vo_mem.c
SRCS_MPLAYER-$(GGI) += libvo/vo_ggi.c
SRCS_MPLAYER-$(GIF) += libvo/vo_gif89a.c
SRCS_MPLAYER-$(GL) += libvo/gl_common.c libvo/vo_gl.c \
LOCAL_CFLAGS =
LOCAL_SRC_FILES = MPlayer.cpp MPlayerMetadataRetriever.cpp MPlayerRenderer.cpp
LOCAL_SHARED_LIBRARIES := libz libasound libc libdl libutils libcutils \
- libmedia libui libandroid_runtime liblog
+ libbinder libmedia libui libandroid_runtime liblog
LOCAL_STATIC_LIBRARIES := libmplayer $(FFMPEGPARTS) libft2
include $(BUILD_SHARED_LIBRARY)
--- /dev/null
+#ifndef MEDIA_DEBUG_H_
+
+#define MEDIA_DEBUG_H_
+
+#include <cutils/log.h>
+
+#define LITERAL_TO_STRING_INTERNAL(x) #x
+#define LITERAL_TO_STRING(x) LITERAL_TO_STRING_INTERNAL(x)
+
+#define CHECK_EQ(x,y) \
+ LOG_ALWAYS_FATAL_IF( \
+ (x) != (y), \
+ __FILE__ ":" LITERAL_TO_STRING(__LINE__) " " #x " != " #y)
+
+#define CHECK(x) \
+ LOG_ALWAYS_FATAL_IF( \
+ !(x), \
+ __FILE__ ":" LITERAL_TO_STRING(__LINE__) " " #x)
+
+#endif // MEDIA_DEBUG_H_
#include "mplayer_lib.h"
#include "MPlayer.h"
-
+#include "MPlayerRenderer.h"
+#include "MPDebug.h"
#ifdef HAVE_GETTID
static pid_t myTid() { return gettid(); }
mAudioBuffer(NULL), mPlayTime(-1), mDuration(-1), mState(STATE_ERROR),
mStreamType(AudioSystem::MUSIC), mLoop(false), mAndroidLoop(false),
mExit(false), mPaused(false), mRender(false), mRenderTid(-1),
- mMPInitialized(false)
+ mMPInitialized(false), mVideoRenderer(NULL)
{
LOGE("constructor\n");
}
}
int argca;
- char * argva[30] = {"mplayer", "fd", "-vo", "null",
+ char * argva[30] = {"mplayer", "fd", "-vo", "mem",
"-ao", "pcm_mem", "-noconsolecontrols", "-nojoystick",
"-nolirc", "-nomouseinput", "-slave", "-zoom",
"-fs",
}
}
- status_t MPlayer::setVideoSurface(const sp<ISurface> &surface) {
+ void MPlayer::depopulateISurface() {
+ if (mVideoRenderer) {
+ delete mVideoRenderer;
+ mVideoRenderer = NULL;
+ }
+ }
+
+ void MPlayer::populateISurface() {
+ if (mState != STATE_OPEN) {
+ return;
+ }
+
+ int width, height;
+ int ret;
+ ret = mplayer_get_video_size(&mMPContext, &width, &height);
+ if (!ret)
+ mVideoRenderer = new MPlayerRenderer (mISurface, width, height);
+ else mVideoRenderer = NULL;
+ }
+
+ status_t MPlayer::setVideoSurface(const sp<ISurface> &isurface) {
LOGE("setVideoSurface");
Mutex::Autolock l(mMutex);
if (mState != STATE_INIT && mState != STATE_OPEN) {
return NO_INIT;
}
-
- size_t width, height;
- mplayer_get_video_dimension(&width, &height);
- mVideoRenderer = new MPlayerRenderer (surface, width, height);
+
+ depopulateISurface();
+
+ mISurface = isurface;
+
+ if (mISurface.get() != NULL) {
+ populateISurface();
+ }
return NO_ERROR;
}
bool audioStarted = false;
int mpresult;
int audio_pos;
+ char * video_buffer;
+ size_t video_buffer_size;
mAudioBuffer = new char[AUDIOBUFFER_SIZE];
audioStarted = true;
}
+ if (mVideoRenderer) {
+ mVideoRenderer->getBuffer (&video_buffer, &video_buffer_size);
+ }
//this function will decode video and sleep for video output timing
- mpresult |= mplayer_decode_video(&mMPContext, NULL);
+ mpresult |= mplayer_decode_video(&mMPContext, video_buffer);
if (mpresult) {
LOGI("mplayer_decode_video returned %d", mpresult);
break;
}
- /* render video */
+ if (mVideoRenderer) {
+ mVideoRenderer->renderBuffer();
+ }
mpresult |= mplayer_after_decode (&mMPContext);
if (mpresult) {
static int renderThread(void*);
status_t setdatasource(const char *path, int fd, int64_t offset,
int64_t length);
+ void populateISurface();
+ void depopulateISurface();
int render();
Mutex mMutex;
Condition mCondition;
status_t mState;
pid_t mRenderTid;
int mfd;
- sp<MPlayerRenderer> mVideoRenderer;
+ MPlayerRenderer *mVideoRenderer;
+ sp<ISurface> mISurface;
};
}; // namespace android
size_t displayWidth, size_t displayHeight)
: mISurface(surface),
mDisplayWidth(displayWidth),
- mDisplayHeight(displayHeight),
- mFrameSize(displayWidth * displayHeight * 2), //RGB565
- mIndex(0)
+ mDisplayHeight(displayHeight),
+ mFrameSize(displayWidth * displayHeight * 2), //RGB565
+ mMemoryHeap (new MemoryHeapBase(2 * mFrameSize)),
+ mIndex(0)
{
+ CHECK(mISurface.get() != NULL);
+ CHECK(mDisplayWidth > 0);
+ CHECK(mDisplayHeight >0);
+ CHECK(mMemoryHeap->heapID() >= 0);
+
+ LOGE("creator");
+
ISurface::BufferHeap bufferHeap (
mDisplayWidth, mDisplayHeight,
mDisplayWidth, mDisplayHeight,
PIXEL_FORMAT_RGB_565,
mMemoryHeap);
- CHECK(mISurface.get() != NULL);
- CHECK(mDisplayWidth > 0);
- CHECK(mDisplayHeight >0);
- CHECK(mMemoryHeap->heapID() >= 0);
+
status_t err = mISurface->registerBuffers(bufferHeap);
CHECK_EQ(err, OK);
bool MPlayerRenderer::getBuffer(char**pbuffer, size_t*size){
size_t offset = mIndex * mFrameSize;
*pbuffer = (char*)mMemoryHeap->getBase() + offset;
+ *size = mFrameSize;
+ LOGE("get buffer result pos%x, size%d", *pbuffer, size);
return true;
}
}
extern const vo_functions_t video_out_bl;
extern vo_functions_t video_out_fbdev;
extern const vo_functions_t video_out_fbdev2;
+#ifdef ANDROID
+extern vo_functions_t video_out_mem;
+#endif
extern vo_functions_t video_out_svga;
extern const vo_functions_t video_out_png;
extern const vo_functions_t video_out_ggi;
&video_out_fbdev,
&video_out_fbdev2,
#endif
+#ifdef ANDROID
+ &video_out_mem,
+#endif
#ifdef CONFIG_SVGALIB
&video_out_svga,
#endif
static const vo_info_t info = {
"memory buffer device"
"mem",
- "okkwon <pinebud@gmail.com> modified"
- ""
+ "okkwon <pinebud@gmail.com>",
+ "Modified from vo_fbdev code",
};
-LIBVO_EXTERN(fbdev)
+LIBVO_EXTERN(mem)
-static signed int pre_init_err = -2;
-
-static char * buffer = NULL;
-static size_t buffer_size = 0;
+static int pre_init_err;
+static size_t fb_size;
+static uint8_t *frame_buffer;
static uint8_t *center;
-static int mem_bpp; // 32: 32 24: 24 16: 16 15: 15
-static int mem_pixel_size;
-static int mem_line_len;
-static int mem_xres;
-static int mem_yres;
+static int fb_pixel_size; // 32: 4 24: 3 16: 2 15: 2
+static int fb_bpp; // 32: 32 24: 24 16: 16 15: 15
+static int fb_line_len;
+static void (*draw_alpha_p)(int w, int h, unsigned char *src,
+ unsigned char *srca, int stride,
+ unsigned char *dst, int dstride);
+
static int in_width;
static int in_height;
static int out_width;
static uint32_t pixel_format;
static int fs;
-
static int config(uint32_t width, uint32_t height, uint32_t d_width,
uint32_t d_height, uint32_t flags, char *title,
uint32_t format)
int zoom = flags & VOFLAG_SWSCALE;
fs = flags & VOFLAG_FULLSCREEN;
+ mp_msg(MSGT_VO, MSGL_INFO, "width%u, height%u, d_width%u, d_height%u, \
+ flags%u, title %s, format %u", width, height, d_width, d_height,
+ flags, title, format);
+
if (pre_init_err == -2) {
mp_msg(MSGT_VO, MSGL_ERR, "Internal fatal error: config() was called before preinit()\n");
return -1;
in_width = width;
in_height = height;
pixel_format = format;
-
- mem_pixel_size = fb_vinfo.bits_per_pixel / 8;
- fb_bpp = fb_vinfo.bits_per_pixel;
-
- switch (fb_bpp) {
- case 32:
- draw_alpha_p = vo_draw_alpha_rgb32;
- break;
- case 24:
- draw_alpha_p = vo_draw_alpha_rgb24;
- break;
- case 16:
- draw_alpha_p = vo_draw_alpha_rgb16;
- break;
- case 15:
- draw_alpha_p = vo_draw_alpha_rgb15;
- break;
- case 12:
- draw_alpha_p = vo_draw_alpha_rgb12;
- break;
- default:
- return 1;
- }
-
- fb_xres = fb_vinfo.xres;
- fb_yres = fb_vinfo.yres;
-
- if (vm || fs) {
- out_width = fb_xres;
- out_height = fb_yres;
- }
+ fb_bpp = 16;
first_row = (out_height - in_height) / 2;
last_row = (out_height + in_height) / 2;
- fb_line_len = fb_finfo.line_length;
+ fb_line_len = out_width * 2; //RGB565 -_-;;
{
int x_offset = 0, y_offset = 0;
- geometry(&x_offset, &y_offset, &out_width, &out_height, fb_xres, fb_yres);
-
- frame_buffer = mmap(0, fb_size, PROT_READ | PROT_WRITE,
- MAP_SHARED, fb_dev_fd, 0);
- if (frame_buffer == (uint8_t *) -1) {
- mp_msg(MSGT_VO, MSGL_ERR, "Can't mmap %s: %s\n", fb_dev_name, strerror(errno));
- return 1;
- }
-
+ geometry(&x_offset, &y_offset, &out_width, &out_height, out_width, out_height);
center = frame_buffer +
( (out_width - in_width) / 2 ) * fb_pixel_size +
( (out_height - in_height) / 2 ) * fb_line_len +
- x_offset * fb_pixel_size + y_offset * fb_line_len +
- fb_page * fb_yres * fb_line_len;
-
- mp_msg(MSGT_VO, MSGL_DBG2, "buffer @ %p\n", buffer);
+ x_offset * fb_pixel_size + y_offset * fb_line_len;
+ mp_msg(MSGT_VO, MSGL_DBG2, "buffer @ %p\n", frame_buffer);
mp_msg(MSGT_VO, MSGL_DBG2, "center @ %p\n", center);
- mp_msg(MSGT_VO, MSGL_V, "pixel per line: %d\n", fb_line_len / fb_pixel_size);
-
- if (fs || vm) {
- int clear_size = fb_line_len * fb_yres;
- if (vo_doublebuffering)
- clear_size <<= 1;
- memset(frame_buffer, 0, clear_size);
- }
}
+ frame_buffer = NULL;
+ center = NULL;
return 0;
}
+static int fb_preinit (int reset)
+{
+ static int fb_preinit_done = 0;
+
+ if (reset) {
+ fb_preinit_done = 0;
+ return 0;
+ }
+
+ vo_dbpp = 16; //??
+ fb_preinit_done = 1;
+ return 1;
+}
+
static int query_format(uint32_t format)
{
if (!fb_preinit(0))
return VO_TRUE;
}
+static uint32_t set_buffer(uint8_t* buff)
+{
+ frame_buffer = buff;
+ center = frame_buffer +
+ ( (out_width - in_width) / 2 ) * fb_pixel_size +
+ ( (out_height - in_height) / 2 ) * fb_line_len +
+ fb_pixel_size + fb_line_len;
+
+ return VO_TRUE;
+}
+
static int control(uint32_t request, void *data, ...)
{
switch (request) {
return get_image(data);
case VOCTRL_QUERY_FORMAT:
return query_format(*(uint32_t*)data);
+ case VOCTRL_UPDATE_SCREENINFO:
+ return set_buffer((uint8_t*)data);
}
return VO_NOTIMPL;
}
return 0;
}
+int mplayer_get_video_size(struct mplayer_context * con,
+ int *width, int *height) {
+ if (mpctx->sh_video) {
+ *width = mpctx->sh_video->disp_w;
+ *height = mpctx->sh_video->disp_h;
+ return 0;
+ } else {
+ *width = 0;
+ *height = 0;
+ return -1;
+ }
+}
+
/* This preprocessor directive is a hack to generate a mplayer-nomain.o object
* file for some tools to link against. */
/* DISABLE_MAIN */
int frame_time_remaining;
/*========================== PLAY VIDEO ============================*/
+ mpctx->video_out->control(VOCTRL_UPDATE_SCREENINFO, buffer);
+
if (mpctx->sh_video) {
vo_pts=mpctx->sh_video->timer*90000.0;
vo_fps=mpctx->sh_video->fps;
double a_pos;
};
+extern int mplayer_get_video_size(struct mplayer_context * con,
+ int *width, int *height);
extern int mplayer_seek (struct mplayer_context * con, int position);
extern int mplayer_get_pos (struct mplayer_context *con, int*v_pos);
extern int mplayer_get_duration (struct mplayer_context *con, int*duration);