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
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)
{
LOGV("render thread(%d) started", mRenderTid);
mState = STATE_INIT;
}
+
+ /* todo : need to decide this -_-? */
+ mDisplayWidth = 1024;
+ mDisplayHeight = 590;
}
status_t MPlayer ::initCheck()
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;
mState = STATE_OPEN;
return NO_ERROR;
} else {
- libInUse = false;
mplayer_close (&mMPContext);
+ libInUse = false;
return ERROR_OPEN_FAILED;
}
}
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) {
{
LOGE("reset\n");
Mutex::Autolock l(mMutex);
+
return reset_nosync();
}
mState = STATE_ERROR;
libInUse = false;
- mPlayTime = -1;
- mDuration = -1;
mLoop = false;
mAndroidLoop = false;
mPaused = false;
return ((MPlayer*)p)->render();
}
-#define AUDIOBUFFER_SIZE (4096*6)
+#define AUDIOBUFFER_SIZE (4096*10)
int MPlayer::render() {
int result = -1;
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
+++ /dev/null
-/*
-**
-** 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;
-}
-
-};
-
+++ /dev/null
-#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
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);
}
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);
~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;
/* 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
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;
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, \
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 +
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 +