virtual status_t attachAuxEffect(int effectId) = 0;
virtual status_t setParameter(int key, const Parcel& request) = 0;
virtual status_t getParameter(int key, Parcel* reply) = 0;
+ virtual status_t setMediaPlayerType(int playerType) = 0;
// Invoke a generic method on the player by using opaque parcels
// for the request and reply.
status_t attachAuxEffect(int effectId);
status_t setParameter(int key, const Parcel& request);
status_t getParameter(int key, Parcel* reply);
+ status_t setMediaPlayerType(int playerType);
private:
void clear_l();
int mVideoHeight;
int mAudioSessionId;
float mSendLevel;
+ bool mOverridePlayerType;
+ int mOverridePlayerTypeValue;
};
}; // namespace android
#include <aah_timesrv/cc_helper.h>
#include <media/IMediaPlayer.h>
#include <media/stagefright/foundation/AMessage.h>
+#include <media/stagefright/FileSource.h>
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MetaData.h>
}
status_t AAH_TXPlayer::setDataSource(int fd, int64_t offset, int64_t length) {
- return INVALID_OPERATION;
+ Mutex::Autolock autoLock(mLock);
+
+ reset_l();
+
+ sp<DataSource> dataSource = new FileSource(dup(fd), offset, length);
+
+ status_t err = dataSource->initCheck();
+
+ if (err != OK) {
+ return err;
+ }
+
+ mFileSource = dataSource;
+
+ sp<MediaExtractor> extractor = MediaExtractor::Create(dataSource);
+
+ if (extractor == NULL) {
+ return UNKNOWN_ERROR;
+ }
+
+ return setDataSource_l(extractor);
}
status_t AAH_TXPlayer::setVideoSurface(const sp<Surface>& surface) {
mAudioSource->getFormat()->findInt64(kKeyDuration, &mDurationUs);
- mAudioSource->start();
+ status_t err = mAudioSource->start();
+ if (err != OK) {
+ LOGI("failed to start audio source, err=%d", err);
+ abortPrepare(err);
+ return;
+ }
mFlags |= PREPARING_CONNECTED;
mUri.setTo("");
mUriHeaders.clear();
+ mFileSource.clear();
+
mBitrate = -1;
{
String8 mUri;
KeyedVector<String8, String8> mUriHeaders;
+ sp<DataSource> mFileSource;
+
sp<TimedEventQueue::Event> mAsyncPrepareEvent;
Condition mPreparedCondition;
status_t mPrepareResult;
SET_VIDEO_SURFACETEXTURE,
SET_PARAMETER,
GET_PARAMETER,
+ SET_MEDIA_PLAYER_TYPE,
};
class BpMediaPlayer: public BpInterface<IMediaPlayer>
return remote()->transact(GET_PARAMETER, data, reply);
}
+ status_t setMediaPlayerType(int playerType) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
+ data.writeInt32(playerType);
+ remote()->transact(SET_MEDIA_PLAYER_TYPE, data, &reply);
+ return reply.readInt32();
+ }
};
IMPLEMENT_META_INTERFACE(MediaPlayer, "android.media.IMediaPlayer");
CHECK_INTERFACE(IMediaPlayer, data, reply);
return getParameter(data.readInt32(), reply);
} break;
+ case SET_MEDIA_PLAYER_TYPE: {
+ CHECK_INTERFACE(IMediaPlayer, data, reply);
+ reply->writeInt32(setMediaPlayerType(data.readInt32()));
+ return NO_ERROR;
+ } break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
mAudioSessionId = AudioSystem::newAudioSessionId();
AudioSystem::acquireAudioSessionId(mAudioSessionId);
mSendLevel = 0;
+ mOverridePlayerType = false;
+ mOverridePlayerTypeValue = -1;
}
MediaPlayer::~MediaPlayer()
const sp<IMediaPlayerService>& service(getMediaPlayerService());
if (service != 0) {
sp<IMediaPlayer> player(service->create(getpid(), this, mAudioSessionId));
- if (NO_ERROR != player->setDataSource(url, headers)) {
+
+ if (mOverridePlayerType) {
+ if (NO_ERROR != player->setMediaPlayerType(mOverridePlayerTypeValue)) {
+ player.clear();
+ }
+ }
+
+ if (player != 0 && NO_ERROR != player->setDataSource(url, headers)) {
player.clear();
}
err = attachNewPlayer(player);
const sp<IMediaPlayerService>& service(getMediaPlayerService());
if (service != 0) {
sp<IMediaPlayer> player(service->create(getpid(), this, mAudioSessionId));
- if (NO_ERROR != player->setDataSource(fd, offset, length)) {
+
+ if (mOverridePlayerType) {
+ if (NO_ERROR != player->setMediaPlayerType(mOverridePlayerTypeValue)) {
+ player.clear();
+ }
+ }
+
+ if (player != 0 && NO_ERROR != player->setDataSource(fd, offset, length)) {
player.clear();
}
err = attachNewPlayer(player);
return INVALID_OPERATION;
}
+status_t MediaPlayer::setMediaPlayerType(int playerType) {
+ if (!((mCurrentState & MEDIA_PLAYER_IDLE) ||
+ (mCurrentState == MEDIA_PLAYER_STATE_ERROR))) {
+ LOGE("attachNewPlayer called in state %d", mCurrentState);
+ return INVALID_OPERATION;
+ }
+
+ mOverridePlayerType = true;
+ mOverridePlayerTypeValue = playerType;
+
+ return NO_ERROR;
+}
+
void MediaPlayer::notify(int msg, int ext1, int ext2, const Parcel *obj)
{
LOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
LOGD("create Antagonizer");
mAntagonizer = new Antagonizer(notify, this);
#endif
+
+ mOverridePlayerType = false;
+ mOverridePlayerTypeValue = static_cast<player_type>(-1);
}
MediaPlayerService::Client::~Client()
close(fd);
return mStatus;
} else {
- player_type playerType = getPlayerType(url);
+ player_type playerType = mOverridePlayerType ?
+ mOverridePlayerTypeValue : getPlayerType(url);
LOGV("player type = %d", playerType);
// create the right type of player
LOGV("calculated length = %lld", length);
}
- player_type playerType = getPlayerType(fd, offset, length);
+ player_type playerType = mOverridePlayerType ?
+ mOverridePlayerTypeValue : getPlayerType(fd, offset, length);
LOGV("player type = %d", playerType);
// create the right type of player
return p->getParameter(key, reply);
}
+status_t MediaPlayerService::Client::setMediaPlayerType(int playerType) {
+ mOverridePlayerType = true;
+ mOverridePlayerTypeValue = static_cast<player_type>(playerType);
+
+ return NO_ERROR;
+}
+
void MediaPlayerService::Client::notify(
void* cookie, int msg, int ext1, int ext2, const Parcel *obj)
{
virtual status_t attachAuxEffect(int effectId);
virtual status_t setParameter(int key, const Parcel &request);
virtual status_t getParameter(int key, Parcel *reply);
+ virtual status_t setMediaPlayerType(int playerType);
sp<MediaPlayerBase> createPlayer(player_type playerType);
// getMetadata clears this set.
media::Metadata::Filter mMetadataUpdated; // protected by mLock
+ bool mOverridePlayerType;
+ player_type mOverridePlayerTypeValue;
+
#if CALLBACK_ANTAGONIZER
Antagonizer* mAntagonizer;
#endif