psb_mds.cpp revision a7634d944fe745c4061b4b5c0d425cc585b923a2
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(
74        int32_t* width, int32_t* height,
75        int32_t* offX, int32_t* offY,
76        int32_t* bufW, int32_t* bufH) {
77    if (mListener.get() == NULL ||
78            width == NULL || height == NULL ||
79            offX == NULL || offY == NULL ||
80            bufW == NULL || bufH == NULL)
81        return false;
82    // only for WIDI video playback,
83    // TODO: HWC doesn't set the bit "MDS_WIDI_ON" rightly now
84    int mode = mListener->getDisplayMode(false);
85    if (!checkMode(mode, (MDS_VIDEO_ON | MDS_WIDI_ON)))
86        return false;
87    status_t ret = mListener->getDecoderOutputResolution(0, width, height, offX, offY, bufW, bufH);
88    return (ret == NO_ERROR ? 1 : 0);
89}
90
91bool psbMultiDisplayListener::getVppState() {
92    if (mListener.get() == NULL) {
93        ALOGE("MDS listener is null");
94        return false;
95    }
96    return mListener->getVppState();
97}
98
99}; // namespace android
100}; // namespace intel
101