Andreas Huber 69b8d69aad Squashed commit of the following:
commit 0d5694ba2d399dd0869532a4d6256448185a1be0
Author: Andreas Huber <andih@google.com>
Date:   Fri Oct 29 11:59:23 2010 -0700

    suspend() and resume() methods on VideoView are back but don't do anything.

    They need to be back because they were public before.

    Change-Id: Iddfd1021ffcf341f26e8d55ba761fd33701e2425

commit 16192891ed7d349ee97e47d1729d20a2d0d247b8
Author: Andreas Huber <andih@google.com>
Date:   Fri Oct 29 11:47:05 2010 -0700

    Revert "New API on VideoView widget to suspend/resume a session. Do not release the MediaPlayer client for video suspending/resuming."

    This reverts commit 2e1818a4d16c3309660f27286c77d8d1eee95a25.

    Conflicts:

    	api/current.xml

    Change-Id: I68dd1d05871044faf3f832d0838aa40bc7f890e5

commit 8f934dc1a3ae4e60f0790fcf97671e063fa20fad
Author: Andreas Huber <andih@google.com>
Date:   Fri Oct 29 11:44:16 2010 -0700

    Revert "Release mediaplayer if the current state is not suspending. Fix for bug 2480093."

    This reverts commit efb882cf75eef39ecaf9f8920ed302a019fa629f.

commit f2ed03550887986f39d36b5dabcd9e919949c7cf
Author: Andreas Huber <andih@google.com>
Date:   Fri Oct 29 11:44:08 2010 -0700

    Revert "Release MediaPlayer if suspend() returns false."

    This reverts commit 047212fd4ea360675e94d3ce83c7f5544f65b268.

commit 441ecce678bd24e9660a72c8627b5bd94433ff8b
Author: Andreas Huber <andih@google.com>
Date:   Fri Oct 29 11:40:46 2010 -0700

    manually.

    Change-Id: I4fdd43c9f7c8b3eedddb31a196da4984e1c58e87

Change-Id: I60d4b10e7a9e4ed8d9a796f1711618f557eb6e89
2010-10-29 13:20:06 -07:00

365 lines
11 KiB
C++

/*
**
** Copyright 2008, 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.
*/
#include <stdint.h>
#include <sys/types.h>
#include <binder/Parcel.h>
#include <media/IMediaPlayer.h>
#include <surfaceflinger/ISurface.h>
#include <surfaceflinger/Surface.h>
namespace android {
enum {
DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
SET_VIDEO_SURFACE,
SET_VIDEO_ISURFACE,
PREPARE_ASYNC,
START,
STOP,
IS_PLAYING,
PAUSE,
SEEK_TO,
GET_CURRENT_POSITION,
GET_DURATION,
RESET,
SET_AUDIO_STREAM_TYPE,
SET_LOOPING,
SET_VOLUME,
INVOKE,
SET_METADATA_FILTER,
GET_METADATA,
SET_AUX_EFFECT_SEND_LEVEL,
ATTACH_AUX_EFFECT
};
class BpMediaPlayer: public BpInterface<IMediaPlayer>
{
public:
BpMediaPlayer(const sp<IBinder>& impl)
: BpInterface<IMediaPlayer>(impl)
{
}
// disconnect from media player service
void disconnect()
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
remote()->transact(DISCONNECT, data, &reply);
}
status_t setVideoISurface(const sp<ISurface>& surface)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
data.writeStrongBinder(surface->asBinder());
remote()->transact(SET_VIDEO_ISURFACE, data, &reply);
return reply.readInt32();
}
status_t setVideoSurface(const sp<Surface>& surface)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
Surface::writeToParcel(surface, &data);
remote()->transact(SET_VIDEO_SURFACE, data, &reply);
return reply.readInt32();
}
status_t prepareAsync()
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
remote()->transact(PREPARE_ASYNC, data, &reply);
return reply.readInt32();
}
status_t start()
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
remote()->transact(START, data, &reply);
return reply.readInt32();
}
status_t stop()
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
remote()->transact(STOP, data, &reply);
return reply.readInt32();
}
status_t isPlaying(bool* state)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
remote()->transact(IS_PLAYING, data, &reply);
*state = reply.readInt32();
return reply.readInt32();
}
status_t pause()
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
remote()->transact(PAUSE, data, &reply);
return reply.readInt32();
}
status_t seekTo(int msec)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
data.writeInt32(msec);
remote()->transact(SEEK_TO, data, &reply);
return reply.readInt32();
}
status_t getCurrentPosition(int* msec)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
remote()->transact(GET_CURRENT_POSITION, data, &reply);
*msec = reply.readInt32();
return reply.readInt32();
}
status_t getDuration(int* msec)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
remote()->transact(GET_DURATION, data, &reply);
*msec = reply.readInt32();
return reply.readInt32();
}
status_t reset()
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
remote()->transact(RESET, data, &reply);
return reply.readInt32();
}
status_t setAudioStreamType(int type)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
data.writeInt32(type);
remote()->transact(SET_AUDIO_STREAM_TYPE, data, &reply);
return reply.readInt32();
}
status_t setLooping(int loop)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
data.writeInt32(loop);
remote()->transact(SET_LOOPING, data, &reply);
return reply.readInt32();
}
status_t setVolume(float leftVolume, float rightVolume)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
data.writeFloat(leftVolume);
data.writeFloat(rightVolume);
remote()->transact(SET_VOLUME, data, &reply);
return reply.readInt32();
}
status_t invoke(const Parcel& request, Parcel *reply)
{ // Avoid doing any extra copy. The interface descriptor should
// have been set by MediaPlayer.java.
return remote()->transact(INVOKE, request, reply);
}
status_t setMetadataFilter(const Parcel& request)
{
Parcel reply;
// Avoid doing any extra copy of the request. The interface
// descriptor should have been set by MediaPlayer.java.
remote()->transact(SET_METADATA_FILTER, request, &reply);
return reply.readInt32();
}
status_t getMetadata(bool update_only, bool apply_filter, Parcel *reply)
{
Parcel request;
request.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
// TODO: Burning 2 ints for 2 boolean. Should probably use flags in an int here.
request.writeInt32(update_only);
request.writeInt32(apply_filter);
remote()->transact(GET_METADATA, request, reply);
return reply->readInt32();
}
status_t setAuxEffectSendLevel(float level)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
data.writeFloat(level);
remote()->transact(SET_AUX_EFFECT_SEND_LEVEL, data, &reply);
return reply.readInt32();
}
status_t attachAuxEffect(int effectId)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
data.writeInt32(effectId);
remote()->transact(ATTACH_AUX_EFFECT, data, &reply);
return reply.readInt32();
}
};
IMPLEMENT_META_INTERFACE(MediaPlayer, "android.media.IMediaPlayer");
// ----------------------------------------------------------------------
status_t BnMediaPlayer::onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
switch(code) {
case DISCONNECT: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
disconnect();
return NO_ERROR;
} break;
case SET_VIDEO_ISURFACE: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
sp<ISurface> surface = interface_cast<ISurface>(data.readStrongBinder());
reply->writeInt32(setVideoISurface(surface));
return NO_ERROR;
} break;
case SET_VIDEO_SURFACE: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
sp<Surface> surface = Surface::readFromParcel(data);
reply->writeInt32(setVideoSurface(surface));
return NO_ERROR;
} break;
case PREPARE_ASYNC: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(prepareAsync());
return NO_ERROR;
} break;
case START: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(start());
return NO_ERROR;
} break;
case STOP: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(stop());
return NO_ERROR;
} break;
case IS_PLAYING: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
bool state;
status_t ret = isPlaying(&state);
reply->writeInt32(state);
reply->writeInt32(ret);
return NO_ERROR;
} break;
case PAUSE: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(pause());
return NO_ERROR;
} break;
case SEEK_TO: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(seekTo(data.readInt32()));
return NO_ERROR;
} break;
case GET_CURRENT_POSITION: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
int msec;
status_t ret = getCurrentPosition(&msec);
reply->writeInt32(msec);
reply->writeInt32(ret);
return NO_ERROR;
} break;
case GET_DURATION: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
int msec;
status_t ret = getDuration(&msec);
reply->writeInt32(msec);
reply->writeInt32(ret);
return NO_ERROR;
} break;
case RESET: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(reset());
return NO_ERROR;
} break;
case SET_AUDIO_STREAM_TYPE: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(setAudioStreamType(data.readInt32()));
return NO_ERROR;
} break;
case SET_LOOPING: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(setLooping(data.readInt32()));
return NO_ERROR;
} break;
case SET_VOLUME: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(setVolume(data.readFloat(), data.readFloat()));
return NO_ERROR;
} break;
case INVOKE: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
invoke(data, reply);
return NO_ERROR;
} break;
case SET_METADATA_FILTER: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(setMetadataFilter(data));
return NO_ERROR;
} break;
case GET_METADATA: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
const status_t retcode = getMetadata(data.readInt32(), data.readInt32(), reply);
reply->setDataPosition(0);
reply->writeInt32(retcode);
reply->setDataPosition(0);
return NO_ERROR;
} break;
case SET_AUX_EFFECT_SEND_LEVEL: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(setAuxEffectSendLevel(data.readFloat()));
return NO_ERROR;
} break;
case ATTACH_AUX_EFFECT: {
CHECK_INTERFACE(IMediaPlayer, data, reply);
reply->writeInt32(attachAuxEffect(data.readInt32()));
return NO_ERROR;
} break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
}
// ----------------------------------------------------------------------------
}; // namespace android