OSDN Git Service

made video out to full screen
authorOwen Kwon <pinebud77@hotmail.com>
Tue, 13 Jul 2010 03:17:11 +0000 (12:17 +0900)
committerOwen Kwon <pinebud77@hotmail.com>
Tue, 13 Jul 2010 03:17:11 +0000 (12:17 +0900)
Android.mk
MPlayer.cpp
MPlayer.h
MPlayerMetadataRetriever.cpp [deleted file]
MPlayerMetadataRetriever.h [deleted file]
MPlayerRenderer.cpp
MPlayerRenderer.h
config.h
libao2/ao_pcm_mem.c
libvo/vo_mem.c

index 2c86653..01d8dfe 100644 (file)
@@ -724,7 +724,7 @@ include $(BUILD_STATIC_LIBRARY)
 include $(CLEAR_VARS)
 LOCAL_MODULE = libandroidmplayer
 LOCAL_CFLAGS = 
-LOCAL_SRC_FILES = MPlayer.cpp MPlayerMetadataRetriever.cpp MPlayerRenderer.cpp
+LOCAL_SRC_FILES = MPlayer.cpp MPlayerRenderer.cpp
 LOCAL_SHARED_LIBRARIES := libz libasound libc libdl libutils libcutils \
        libbinder libmedia libui libandroid_runtime liblog
 LOCAL_STATIC_LIBRARIES := libmplayer $(FFMPEGPARTS) libft2
index e58ea6a..35bfe53 100644 (file)
@@ -43,8 +43,8 @@ namespace android {
        bool MPlayer::libInUse = false;
 
        MPlayer::MPlayer() :
-               mAudioBuffer(NULL), mPlayTime(-1), mDuration(-1), mState(STATE_ERROR),
-               mStreamType(AudioSystem::MUSIC), mLoop(false), mAndroidLoop(false),
+               mAudioBuffer(NULL), mState(STATE_ERROR),
+               mLoop(false), mAndroidLoop(false),
                mExit(false), mPaused(false), mRender(false), mRenderTid(-1),
                mMPInitialized(false), mVideoRenderer(NULL)
        {
@@ -62,6 +62,10 @@ namespace android {
                        LOGV("render thread(%d) started", mRenderTid);
                        mState = STATE_INIT;
                }
+
+               /* todo : need to decide this -_-? */
+               mDisplayWidth = 1024;
+               mDisplayHeight = 590;
        }
 
        status_t MPlayer ::initCheck()
@@ -112,24 +116,32 @@ namespace android {
                        return ERROR_OPEN_FAILED;
                }
                /* todo : need to handle offset and length */
-               if (sb.st_size > (length+offset)) {
-                       mLength = length;
-               } else {
-                       mLength = sb.st_size - offset;
-               }
 
                int argca;
-               const char * argva[30] = {"mplayer", "fd", "-vo", "mem",
+               const char * argva[30] = {"mplayer", "fd", 
+                       "-screenw", "1024", "-screenh", "550",
+                       "-vf", "dsize=x:y:0,scale",
+                       "-vo", "mem", "-framedrop",
                        "-ao", "pcm_mem", "-noconsolecontrols", "-nojoystick",
                        "-nolirc", "-nomouseinput", "-slave", "-zoom", "-fs",
                        0};
                char url_buffer[100];
+               char screenh_buffer[30];
+               char screenw_buffer[30];
+               char scale_buffer[30];
 
-
-               mfd = dup(fd);
+               int mfd = dup(fd);
 
                sprintf (url_buffer, "fd://%d", mfd);
                argva[1] = url_buffer;
+               sprintf (screenw_buffer, "%d", mDisplayWidth);
+               argva[3] = screenw_buffer;
+               sprintf (screenh_buffer, "%d", mDisplayHeight);
+               argva[5] = screenh_buffer;
+               sprintf (scale_buffer, "dsize=%d:%d:0,scale",
+                               mDisplayWidth, mDisplayHeight);
+               argva[7] = scale_buffer;
+
                for (argca=0; argca<30; argca++) {
                        if (argva[argca] == 0)
                                break;
@@ -145,8 +157,8 @@ namespace android {
                        mState = STATE_OPEN;
                        return NO_ERROR;
                } else {
-                       libInUse = false;
                        mplayer_close (&mMPContext);
+                       libInUse = false;
                        return ERROR_OPEN_FAILED;
                }
        }
@@ -163,13 +175,20 @@ namespace android {
                        return;
                }
 
-               int width, height;
-               int ret;
-               ret = mplayer_get_video_size(&mMPContext, &width, &height);
-               LOGE("video size w%d h%d", width, height);
-               if (!ret) 
-                       mVideoRenderer = new MPlayerRenderer (mISurface, width, height);
-               else mVideoRenderer = NULL;
+               mVideoRenderer = new MPlayerRenderer (mISurface, mDisplayWidth,
+                               mDisplayHeight);
+               /*
+               if (mVideoRenderer) {
+                       int ret;
+                       int width, height;
+                       ret = mplayer_get_video_size(&mMPContext, &width, &height);
+                       if (ret) {
+                               mVideoRenderer->getVideoOutSize (width, height,
+                                               &mVideoOutWidth, &mVideoOutHeight);
+                               LOGE("video size w%d h%d", mVideoOutWidth, mVideoOutHeight);
+                       }
+               }
+               */
        }
 
        status_t MPlayer::setVideoSurface(const sp<ISurface> &isurface) {
@@ -320,6 +339,7 @@ namespace android {
        {
                LOGE("reset\n");
                Mutex::Autolock l(mMutex);
+
                return reset_nosync();
        }
 
@@ -332,8 +352,6 @@ namespace android {
                mState = STATE_ERROR;
                libInUse = false;
 
-               mPlayTime = -1;
-               mDuration = -1;
                mLoop = false;
                mAndroidLoop = false;
                mPaused = false;
@@ -368,7 +386,7 @@ namespace android {
                return ((MPlayer*)p)->render();
        }
 
-#define AUDIOBUFFER_SIZE (4096*6)
+#define AUDIOBUFFER_SIZE (4096*10)
 
        int MPlayer::render() {
                int result = -1;
index e369356..60b02e0 100644 (file)
--- a/MPlayer.h
+++ b/MPlayer.h
@@ -56,25 +56,26 @@ namespace android {
                        void            populateISurface();
                        void            depopulateISurface();
                        int                     render();
+
+                       int                     mDisplayWidth;
+                       int             mDisplayHeight;
+                       int             mVideoOutWidth;
+                       int             mVideoOutHeight;
                        Mutex           mMutex;
                        Condition       mCondition;
                        bool            mMPInitialized;
-                       int64_t         mOffset;
-                       int64_t         mLength;
                        char *          mAudioBuffer;
-                       int                     mPlayTime;
-                       int                     mDuration;
                        bool            mLoop;
                        bool            mAndroidLoop;
-                       int                     mStreamType;
                        volatile bool           mExit;
                        bool            mPaused;
                        volatile bool mRender;
                        status_t        mState;
                        pid_t           mRenderTid;
-                       int             mfd;
                        MPlayerRenderer *mVideoRenderer;
                        sp<ISurface> mISurface;
+
+                       /* we don't support more than one thread at a time */
                        static  bool    libInUse;
        };
 };     // namespace android
diff --git a/MPlayerMetadataRetriever.cpp b/MPlayerMetadataRetriever.cpp
deleted file mode 100644 (file)
index 71fb329..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
-**
-** Copyright 2009, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-/* copied from Vorbis player */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "MPlayerMetadataRetriever"
-#include <utils/Log.h>
-
-#include "MPlayerMetadataRetriever.h"
-#include <media/mediametadataretriever.h>
-#
-
-namespace android {
-
-void MPlayerMetadataRetriever::clearMetadataValues()
-{
-    LOGV("cleearMetadataValues");
-    mMetadataValues[0][0] = '\0';
-}
-
-status_t MPlayerMetadataRetriever::setDataSource(const char *url)
-{
-    LOGV("setDataSource: url(%s)", url? url: "NULL pointer");
-    Mutex::Autolock lock(mLock);
-    clearMetadataValues();
-    if (mMPlayerPlayer == 0) {
-        mMPlayerPlayer = new MPlayer();
-    }
-    return mMPlayerPlayer->setDataSource(url);
-}
-
-status_t MPlayerMetadataRetriever::setDataSource(int fd, int64_t offset, int64_t length)
-{
-    LOGV("setDataSource: fd(%d), offset(%lld), and length(%lld)", fd, offset, length);
-    Mutex::Autolock lock(mLock);
-    clearMetadataValues();
-    if (mMPlayerPlayer == 0) {
-        mMPlayerPlayer = new MPlayer();
-    }
-    return mMPlayerPlayer->setDataSource(fd, offset, length);
-}
-
-const char* MPlayerMetadataRetriever::extractMetadata(int keyCode)
-{
-    LOGV("extractMetadata: key(%d)", keyCode);
-    Mutex::Autolock lock(mLock);
-    if (mMPlayerPlayer == 0 || mMPlayerPlayer->initCheck() != NO_ERROR) {
-        LOGE("no vorbis player is initialized yet");
-        return NULL;
-    }
-    switch (keyCode) {
-    case METADATA_KEY_DURATION:
-        {
-            if (mMetadataValues[0][0] == '\0') {
-                int duration = -1;
-                if (mMPlayerPlayer->getDuration(&duration) != NO_ERROR) {
-                    LOGE("failed to get duration");
-                    return NULL;
-                }
-                snprintf(mMetadataValues[0], MAX_METADATA_STRING_LENGTH, "%d", duration);
-            }
-            LOGV("duration: %s ms", mMetadataValues[0]);
-            return mMetadataValues[0];
-        }
-    default:
-        LOGE("Unsupported key code (%d)", keyCode);
-        return NULL;
-    }
-    return NULL;
-}
-
-};
-
diff --git a/MPlayerMetadataRetriever.h b/MPlayerMetadataRetriever.h
deleted file mode 100644 (file)
index db76cd0..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef ANDROID_MPLAYERMETADATARETRIEVER_H
-#define ANDROID_MPLAYERMETADATARETRIEVER_H
-
-#include <utils/threads.h>
-#include <utils/Errors.h>
-#include <media/MediaMetadataRetrieverInterface.h>
-
-#include "MPlayer.h"
-
-namespace android {
-
-       class MPlayerMetadataRetriever : public MediaMetadataRetrieverInterface {
-               public:
-                       MPlayerMetadataRetriever() {}
-                       ~MPlayerMetadataRetriever() {}
-
-                       virtual status_t                setDataSource(const char *url);
-                       virtual status_t                setDataSource(int fd, int64_t offset, int64_t length);
-                       virtual const char*             extractMetadata(int keyCode);
-
-               private:
-                       static const uint32_t MAX_METADATA_STRING_LENGTH = 128;
-                       void clearMetadataValues();
-
-                       Mutex               mLock;
-                       sp<MPlayer>    mMPlayerPlayer;
-                       char                mMetadataValues[1][MAX_METADATA_STRING_LENGTH];
-       };
-
-}; // namespace android
-
-#endif
index 08bf294..35e3a64 100644 (file)
@@ -37,6 +37,9 @@ namespace android {
                                PIXEL_FORMAT_RGB_565,
                                mMemoryHeap);
 
+               char * buffer = (char*) mMemoryHeap->getBase();
+               memset (buffer, 0, mFrameSize * 2);
+
                status_t err = mISurface->registerBuffers(bufferHeap);
                CHECK_EQ(err, OK);
        }
@@ -45,6 +48,22 @@ namespace android {
                mISurface->unregisterBuffers();
        }
 
+       void MPlayerRenderer::getVideoOutSize (int orig_w, int orig_h,
+                       int *new_w, int *new_h)
+       {
+               float ratio;
+
+               ratio = (float)mDisplayWidth / (float)orig_w;
+               if (orig_h * ratio < mDisplayHeight) {
+                       *new_w = mDisplayWidth;
+                       *new_h = (int)((float)orig_h * ratio);
+               } else {
+                       ratio = (float)mDisplayHeight / (float)orig_h;
+                       *new_w = (int)((float)orig_w * ratio);
+                       *new_h = mDisplayHeight;
+               }
+       }
+
        void MPlayerRenderer::renderBuffer() {
                size_t offset = mIndex * mFrameSize;
                mISurface->postBuffer(offset);
index 8c964f4..ea8f36e 100644 (file)
@@ -23,6 +23,8 @@ namespace android {
                        ~MPlayerRenderer();
                        void renderBuffer();
                        bool getBuffer(char **pbuffer, size_t *size);
+                       void getVideoOutSize (int orig_w, int orig_h,
+                                       int *new_w, int *new_h);
 
                private:
                        sp<ISurface> mISurface;
index e4d7756..7e0c1a1 100644 (file)
--- a/config.h
+++ b/config.h
 /* configurable options */
 #define MSG_CHARSET "UTF-8"
 #undef CONFIG_CRASH_DEBUG
-#define MP_DEBUG 1
+#undef MP_DEBUG
 #undef CONFIG_DYNAMIC_PLUGINS
 #define CONFIG_FASTMEMCPY 1
 #undef CONFIG_MENU
index 6fef827..7b59467 100644 (file)
@@ -136,7 +136,7 @@ static int init(int rate,int channels,int format,int flags){
     format = AF_FORMAT_S16_LE;
        int samplesize = af_fmt2bits(format) / 8;
 
-       ao_data.outburst = 64 * channels * samplesize;
+       ao_data.outburst = 128 * channels * samplesize;
        // A "buffer" for about 0.2 seconds of audio
        ao_data.buffersize = (int)(rate * 0.2 / 256 + 1) * ao_data.outburst;
        ao_data.channels=channels;
index ccb6569..6a9af45 100644 (file)
@@ -73,11 +73,16 @@ static int last_row;
 static uint32_t pixel_format;
 static int fs;
 
+extern int vo_screenwidth;
+extern int vo_screenheight;
+
 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;
+       int fb_xres, fb_yres;
+
     fs = flags & VOFLAG_FULLSCREEN;
 
        mp_msg(MSGT_VO, MSGL_INFO, "width%u, height%u, d_width%u, d_height%u, \
@@ -102,12 +107,19 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width,
        fb_bpp          = 16;
        fb_pixel_size = 2;
 
+       if (fs) {
+               out_width = vo_screenwidth;
+               out_height = vo_screenheight;
+       }
+
     first_row = (out_height - in_height) / 2;
     last_row  = (out_height + in_height) / 2;
+       
     fb_line_len = out_width * 2; //RGB565 -_-;;
     {
         int x_offset = 0, y_offset = 0;
-        geometry(&x_offset, &y_offset, &out_width, &out_height, out_width, out_height);
+        geometry(&x_offset, &y_offset, &out_width, &out_height, 
+                               vo_screenwidth, vo_screenheight);
         center = frame_buffer +
                  ( (out_width  - in_width)  / 2 ) * fb_pixel_size +
                  ( (out_height - in_height) / 2 ) * fb_line_len +
@@ -228,7 +240,7 @@ static uint32_t set_buffer(uint8_t* buff)
        int y_offset = 0;
        
        mp_dbg(MSGT_VO, MSGL_ERR, "set_buffer");
-       geometry(&x_offset, &y_offset, &out_width, &out_height, out_width, out_height);
+       geometry(&x_offset, &y_offset, &out_width, &out_height, vo_screenwidth, vo_screenheight);
        frame_buffer = buff;
        center = frame_buffer +
                ( (out_width  - in_width)  / 2 ) * fb_pixel_size +