Home | History | Annotate | Download | only in libmedia
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <stdint.h>
     18 #include <sys/types.h>
     19 
     20 #include <media/IRemoteDisplayClient.h>
     21 #include <gui/IGraphicBufferProducer.h>
     22 #include <utils/String8.h>
     23 
     24 namespace android {
     25 
     26 enum {
     27     ON_DISPLAY_CONNECTED = IBinder::FIRST_CALL_TRANSACTION,
     28     ON_DISPLAY_DISCONNECTED,
     29     ON_DISPLAY_ERROR,
     30 };
     31 
     32 class BpRemoteDisplayClient: public BpInterface<IRemoteDisplayClient>
     33 {
     34 public:
     35     explicit BpRemoteDisplayClient(const sp<IBinder>& impl)
     36         : BpInterface<IRemoteDisplayClient>(impl)
     37     {
     38     }
     39 
     40     void onDisplayConnected(const sp<IGraphicBufferProducer>& bufferProducer,
     41             uint32_t width, uint32_t height, uint32_t flags, uint32_t session)
     42     {
     43         Parcel data, reply;
     44         data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
     45         data.writeStrongBinder(IInterface::asBinder(bufferProducer));
     46         data.writeInt32(width);
     47         data.writeInt32(height);
     48         data.writeInt32(flags);
     49         data.writeInt32(session);
     50         remote()->transact(ON_DISPLAY_CONNECTED, data, &reply, IBinder::FLAG_ONEWAY);
     51     }
     52 
     53     void onDisplayDisconnected()
     54     {
     55         Parcel data, reply;
     56         data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
     57         remote()->transact(ON_DISPLAY_DISCONNECTED, data, &reply, IBinder::FLAG_ONEWAY);
     58     }
     59 
     60     void onDisplayError(int32_t error)
     61     {
     62         Parcel data, reply;
     63         data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
     64         data.writeInt32(error);
     65         remote()->transact(ON_DISPLAY_ERROR, data, &reply, IBinder::FLAG_ONEWAY);
     66     }
     67 };
     68 
     69 IMPLEMENT_META_INTERFACE(RemoteDisplayClient, "android.media.IRemoteDisplayClient");
     70 
     71 // ----------------------------------------------------------------------
     72 
     73 status_t BnRemoteDisplayClient::onTransact(
     74     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
     75 {
     76     switch (code) {
     77         case ON_DISPLAY_CONNECTED: {
     78             CHECK_INTERFACE(IRemoteDisplayClient, data, reply);
     79             sp<IGraphicBufferProducer> surfaceTexture(
     80                     interface_cast<IGraphicBufferProducer>(data.readStrongBinder()));
     81             uint32_t width = data.readInt32();
     82             uint32_t height = data.readInt32();
     83             uint32_t flags = data.readInt32();
     84             uint32_t session = data.readInt32();
     85             onDisplayConnected(surfaceTexture, width, height, flags, session);
     86             return NO_ERROR;
     87         }
     88         case ON_DISPLAY_DISCONNECTED: {
     89             CHECK_INTERFACE(IRemoteDisplayClient, data, reply);
     90             onDisplayDisconnected();
     91             return NO_ERROR;
     92         }
     93         case ON_DISPLAY_ERROR: {
     94             CHECK_INTERFACE(IRemoteDisplayClient, data, reply);
     95             int32_t error = data.readInt32();
     96             onDisplayError(error);
     97             return NO_ERROR;
     98         }
     99         default:
    100             return BBinder::onTransact(code, data, reply, flags);
    101     }
    102 }
    103 
    104 } // namespace android
    105