psb_mds.cpp revision 7cc51e5b8b53a547b4edf64d13969c5a73c2a253
1/*
2 * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 *    tianyang.zhu <tianyang.zhu@intel.com>
26 */
27
28//#define LOG_NDEBUG 0
29
30#define LOG_TAG "MultiDisplay"
31
32#include <utils/Log.h>
33#include "psb_mds.h"
34
35namespace android {
36namespace intel {
37
38psbMultiDisplayListener::psbMultiDisplayListener() {
39    // get mds service and register listener
40    sp<IServiceManager> sm = defaultServiceManager();
41    if (sm == NULL) {
42        LOGE("%s: Fail to get service manager", __func__);
43        return;
44    }
45    mMds = interface_cast<IMDService>(sm->getService(String16(INTEL_MDS_SERVICE_NAME)));
46    if (mMds == NULL) {
47        LOGE("%s: Failed to get Mds service", __func__);
48        return;
49    }
50    mListener = mMds->getInfoProvider();
51    return;
52}
53
54psbMultiDisplayListener::~psbMultiDisplayListener() {
55    mListener = NULL;
56    return;
57}
58
59int psbMultiDisplayListener::getMode() {
60    int mode = MDS_MODE_NONE;
61    if (mListener.get() == NULL) return MDS_INIT_VALUE;
62    mode = mListener->getDisplayMode(false);
63    if (checkMode(mode, (MDS_VIDEO_ON | MDS_HDMI_CONNECTED)))
64        mode = MDS_HDMI_VIDEO_ISPLAYING;
65    else if (checkMode(mode, (MDS_VIDEO_ON | MDS_WIDI_ON)))
66        mode = MDS_WIDI_VIDEO_ISPLAYING;
67    else
68        mode = MDS_INIT_VALUE;
69    //ALOGV("mds mode is %d", mode);
70    return mode;
71}
72
73bool psbMultiDisplayListener::getDecoderOutputResolution(int32_t* width, int32_t* height) {
74    if (mListener.get() == NULL ||
75            width == NULL || height == NULL)
76        return false;
77    // only for WIDI video playback,
78    // TODO: HWC doesn't set the bit "MDS_WIDI_ON" rightly now
79    int mode = mListener->getDisplayMode(false);
80    if (!checkMode(mode, (MDS_VIDEO_ON | MDS_WIDI_ON)))
81        return false;
82    status_t ret = mListener->getDecoderOutputResolution(0, width, height);
83    return (ret == NO_ERROR ? 1 : 0);
84}
85
86bool psbMultiDisplayListener::getVppState() {
87    if (mListener.get() == NULL) {
88        ALOGE("MDS listener is null");
89        return false;
90    }
91    return mListener->getVppState();
92}
93
94}; // namespace android
95}; // namespace intel
96