场景:
1)IMediaPlayer.cpp
Bn -> Bp
sp<IGraphicBufferProducer> bufferProducer =
interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
reply->writeInt32(setVideoSurfaceTexture(bufferProducer));
在mediaplayerservice中使用
sp<IGraphicBufferProducer>& bufferProducer 该Bp 与Bn 交互
2) 将mediaplayerservice进程中该Bp对象传递给另外一个进程中使用
virtual status_t connect(const sp<IGraphicBufferProducer> &bufferProduce, sp<IRemoteDisplayClient> &sinkClient)
{
Parcel data, reply;
data.writeInterfaceToken(IRemoteDisplay::getInterfaceDescriptor());
data.writeStrongBinder(IInterface::asBinder(bufferProduce));
data.writeStrongBinder(IInterface::asBinder(sinkClient));
remote()->transact(CONNECT, data, &reply);
return reply.readInt32();
}
status_t BnRemoteDisplay::onTransact(..........){.........
case CONNECT:{
CHECK_INTERFACE(IRemoteDisplay, data, reply);
sp<IGraphicBufferProducer> bufferproducer = IGraphicBufferProducer::asInterface(data.readStrongBinder()); //从mediaplayerservice进程中获取到的Bp对象在这边也可以被使用
sp<IRemoteDisplayClient> clientsink = interface_cast<IRemoteDisplayClient>(data.readStrongBinder());
reply->writeInt32(connect(bufferproducer,clientsink));
return NO_ERROR;
}
3) 一个BnXX 可以被多个类继承,然后在不同接口处 得到的Bp
return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
自身能够区分出来对应是哪个类的Bn
<IRemoteDisplay> 与RemoteDisplay 不是一一对应, IRemoteDisplay 可能对应多个类