Home | History | Annotate | Download | only in observers
      1 /*
      2 // Copyright(c)2014 IntelCorporation
      3 //
      4 // LicensedundertheApacheLicense,Version2.0(the"License");
      5 // youmaynotusethisfileexceptincompliancewiththeLicense.
      6 // YoumayobtainacopyoftheLicenseat
      7 //
      8 // http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unlessrequiredbyapplicablelaworagreedtoinwriting,software
     11 // distributedundertheLicenseisdistributedonan"ASIS"BASIS,
     12 // WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
     13 // SeetheLicenseforthespecificlanguagegoverningpermissionsand
     14 // limitationsundertheLicense.
     15 */
     16 #ifndef __MULTIDISPLAY_OBSERVER_H
     17 #define __MULTIDISPLAY_OBSERVER_H
     18 
     19 #ifdef TARGET_HAS_MULTIPLE_DISPLAY
     20 #include <display/MultiDisplayService.h>
     21 #include <SimpleThread.h>
     22 #else
     23 #include <utils/Errors.h>
     24 #endif
     25 #include <string.h>
     26 
     27 namespace android {
     28 namespace intel {
     29 
     30 struct VideoSourceInfo {
     31     VideoSourceInfo() {
     32         memset(this, 0, sizeof(VideoSourceInfo));
     33     }
     34     int width;
     35     int height;
     36     int frameRate;
     37     bool isProtected;
     38 };
     39 
     40 
     41 #ifdef TARGET_HAS_MULTIPLE_DISPLAY
     42 
     43 class MultiDisplayObserver;
     44 
     45 class MultiDisplayCallback : public BnMultiDisplayCallback {
     46 public:
     47     MultiDisplayCallback(MultiDisplayObserver *observer);
     48     virtual ~MultiDisplayCallback();
     49 
     50     status_t blankSecondaryDisplay(bool blank);
     51     status_t updateVideoState(int sessionId, MDS_VIDEO_STATE state);
     52     status_t setHdmiTiming(const MDSHdmiTiming& timing);
     53     status_t setHdmiScalingType(MDS_SCALING_TYPE type);
     54     status_t setHdmiOverscan(int hValue, int vValue);
     55     status_t updateInputState(bool state);
     56 
     57 private:
     58     MultiDisplayObserver *mDispObserver;
     59     MDS_VIDEO_STATE mVideoState;
     60 };
     61 
     62 class MultiDisplayObserver {
     63 public:
     64     MultiDisplayObserver();
     65     virtual ~MultiDisplayObserver();
     66 
     67 public:
     68     bool initialize();
     69     void deinitialize();
     70     status_t notifyHotPlug(bool connected);
     71     status_t getVideoSourceInfo(int sessionID, VideoSourceInfo* info);
     72     int  getVideoSessionNumber();
     73     bool isExternalDeviceTimingFixed() const;
     74     status_t notifyWidiConnectionStatus(bool connected);
     75     status_t setDecoderOutputResolution(int sessionID,
     76             int32_t width, int32_t height,
     77             int32_t offX,  int32_t offY,
     78             int32_t bufWidth, int32_t bufHeight);
     79 
     80 private:
     81     bool isMDSRunning();
     82     bool initMDSClient();
     83     bool initMDSClientAsync();
     84     void deinitMDSClient();
     85     status_t blankSecondaryDisplay(bool blank);
     86     status_t updateVideoState(int sessionId, MDS_VIDEO_STATE state);
     87     status_t setHdmiTiming(const MDSHdmiTiming& timing);
     88     status_t updateInputState(bool active);
     89     friend class MultiDisplayCallback;
     90 
     91 private:
     92     enum {
     93         THREAD_LOOP_DELAY = 10, // 10 ms
     94         THREAD_LOOP_BOUND = 2000, // 20s
     95     };
     96 
     97 private:
     98     sp<IMultiDisplayCallbackRegistrar> mMDSCbRegistrar;
     99     sp<IMultiDisplayInfoProvider> mMDSInfoProvider;
    100     sp<IMultiDisplayConnectionObserver> mMDSConnObserver;
    101     sp<IMultiDisplayDecoderConfig> mMDSDecoderConfig;
    102     sp<MultiDisplayCallback> mMDSCallback;
    103     mutable Mutex mLock;
    104     Condition mCondition;
    105     int mThreadLoopCount;
    106     bool mDeviceConnected;
    107     // indicate external devices's timing is set
    108     bool mExternalHdmiTiming;
    109     bool mInitialized;
    110 
    111 private:
    112     DECLARE_THREAD(MDSClientInitThread, MultiDisplayObserver);
    113 };
    114 
    115 #else
    116 
    117 // dummy declaration and implementation of MultiDisplayObserver
    118 class MultiDisplayObserver {
    119 public:
    120     MultiDisplayObserver() {}
    121     virtual ~MultiDisplayObserver() {}
    122 
    123     bool initialize() { return true; }
    124     void deinitialize() {}
    125     status_t notifyHotPlug(bool connected) { return NO_ERROR; }
    126     status_t getVideoSourceInfo(int sessionID, VideoSourceInfo* info) { return INVALID_OPERATION; }
    127     int  getVideoSessionNumber() { return 0; }
    128     bool isExternalDeviceTimingFixed() const { return false; }
    129     status_t notifyWidiConnectionStatus(bool connected) { return NO_ERROR; }
    130     status_t setDecoderOutputResolution(
    131             int sessionID,
    132             int32_t width, int32_t height,
    133             int32_t, int32_t, int32_t, int32_t) { return NO_ERROR; }
    134 };
    135 
    136 #endif //TARGET_HAS_MULTIPLE_DISPLAY
    137 
    138 } // namespace intel
    139 } // namespace android
    140 
    141 #endif /* __MULTIMultiDisplayObserver_H_ */
    142