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     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)
     42     {
     43         Parcel data, reply;
     44         data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
     45         data.writeStrongBinder(bufferProducer->asBinder());
     46         data.writeInt32(width);
     47         data.writeInt32(height);
     48         data.writeInt32(flags);
     49         remote()->transact(ON_DISPLAY_CONNECTED, data, &reply, IBinder::FLAG_ONEWAY);
     50     }
     51 
     52     void onDisplayDisconnected()
     53     {
     54         Parcel data, reply;
     55         data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
     56         remote()->transact(ON_DISPLAY_DISCONNECTED, data, &reply, IBinder::FLAG_ONEWAY);
     57     }
     58 
     59     void onDisplayError(int32_t error)
     60     {
     61         Parcel data, reply;
     62         data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
     63         data.writeInt32(error);
     64         remote()->transact(ON_DISPLAY_ERROR, data, &reply, IBinder::FLAG_ONEWAY);
     65     }
     66 };
     67 
     68 IMPLEMENT_META_INTERFACE(RemoteDisplayClient, "android.media.IRemoteDisplayClient");
     69 
     70 // ----------------------------------------------------------------------
     71 
     72 status_t BnRemoteDisplayClient::onTransact(
     73     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
     74 {
     75     switch (code) {
     76         case ON_DISPLAY_CONNECTED: {
     77             CHECK_INTERFACE(IRemoteDisplayClient, data, reply);
     78             sp<IGraphicBufferProducer> surfaceTexture(
     79                     interface_cast<IGraphicBufferProducer>(data.readStrongBinder()));
     80             uint32_t width = data.readInt32();
     81             uint32_t height = data.readInt32();
     82             uint32_t flags = data.readInt32();
     83             onDisplayConnected(surfaceTexture, width, height, flags);
     84             return NO_ERROR;
     85         }
     86         case ON_DISPLAY_DISCONNECTED: {
     87             CHECK_INTERFACE(IRemoteDisplayClient, data, reply);
     88             onDisplayDisconnected();
     89             return NO_ERROR;
     90         }
     91         case ON_DISPLAY_ERROR: {
     92             CHECK_INTERFACE(IRemoteDisplayClient, data, reply);
     93             int32_t error = data.readInt32();
     94             onDisplayError(error);
     95             return NO_ERROR;
     96         }
     97         default:
     98             return BBinder::onTransact(code, data, reply, flags);
     99     }
    100 }
    101 
    102 }; // namespace android
    103