OSDN Git Service

initial add of video output chain
authorOwen Kwon <pinebud77@hotmail.com>
Mon, 12 Jul 2010 02:15:17 +0000 (11:15 +0900)
committerOwen Kwon <pinebud77@hotmail.com>
Mon, 12 Jul 2010 02:15:17 +0000 (11:15 +0900)
Android.mk
MPDebug.h [new file with mode: 0644]
MPlayer.cpp
MPlayer.h
MPlayerRenderer.cpp
libvo/video_out.c
libvo/vo_mem.c
mplayer_lib.c
mplayer_lib.h

index 855dffa..cd010fa 100644 (file)
@@ -549,6 +549,7 @@ SRCS_MPLAYER-$(DIRECT3D)     += libvo/vo_direct3d.c libvo/w32_common.c
 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 \
@@ -725,7 +726,7 @@ LOCAL_MODULE = libandroidmplayer
 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)
 
diff --git a/MPDebug.h b/MPDebug.h
new file mode 100644 (file)
index 0000000..c8a8f00
--- /dev/null
+++ b/MPDebug.h
@@ -0,0 +1,20 @@
+#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_
index 54759f4..bf4f9e9 100644 (file)
@@ -18,7 +18,8 @@
 
 #include "mplayer_lib.h"
 #include "MPlayer.h"
-
+#include "MPlayerRenderer.h"
+#include "MPDebug.h"
 
 #ifdef HAVE_GETTID
 static pid_t myTid() { return gettid(); }
@@ -41,7 +42,7 @@ namespace android {
                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");
        }
@@ -112,7 +113,7 @@ namespace android {
                }
 
                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",
@@ -142,17 +143,41 @@ namespace android {
                }
        }
 
-       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;
        }
@@ -342,6 +367,8 @@ namespace android {
                bool audioStarted = false;
                int mpresult;
                int audio_pos;
+               char * video_buffer;
+               size_t video_buffer_size;
                
                mAudioBuffer = new char[AUDIOBUFFER_SIZE];
 
@@ -403,14 +430,19 @@ namespace android {
                                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) {
index b970c43..853cc08 100644 (file)
--- a/MPlayer.h
+++ b/MPlayer.h
@@ -53,6 +53,8 @@ namespace android {
                        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;
@@ -71,7 +73,8 @@ namespace android {
                        status_t        mState;
                        pid_t           mRenderTid;
                        int             mfd;
-                       sp<MPlayerRenderer> mVideoRenderer;
+                       MPlayerRenderer *mVideoRenderer;
+                       sp<ISurface> mISurface;
        };
 };     // namespace android
 
index 8ddd52e..d863f8c 100644 (file)
@@ -19,19 +19,24 @@ 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);
@@ -50,6 +55,8 @@ namespace android {
        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;
        }
 }
index 0318867..3bd97c1 100644 (file)
@@ -113,6 +113,9 @@ extern const vo_functions_t video_out_zr2;
 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;
@@ -214,6 +217,9 @@ const vo_functions_t* const video_out_drivers[] =
         &video_out_fbdev,
         &video_out_fbdev2,
 #endif
+#ifdef ANDROID
+        &video_out_mem,
+#endif
 #ifdef CONFIG_SVGALIB
         &video_out_svga,
 #endif
index 13b4fe0..5113059 100644 (file)
 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;
@@ -72,7 +73,6 @@ static int last_row;
 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)
@@ -80,6 +80,10 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width,
     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;
@@ -98,73 +102,41 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width,
     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))
@@ -250,6 +222,17 @@ static uint32_t get_image(mp_image_t *mpi)
     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) {
@@ -257,6 +240,8 @@ static int control(uint32_t request, void *data, ...)
         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;
 }
index a6f691c..2e9638a 100644 (file)
@@ -2689,6 +2689,19 @@ static int seek(MPContext *mpctx, double amount, int style)
     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 */
@@ -3868,6 +3881,8 @@ int mplayer_decode_video (struct mplayer_context *con, char *buffer)
        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;
index b5694fa..9ab6fb7 100644 (file)
@@ -14,6 +14,8 @@ struct mplayer_context {
        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);