summaryrefslogtreecommitdiffstats
path: root/cmds/hdmid/HDMIDaemon.h
blob: 6f63b95da5df8c0ed070c1064bb2e689155664c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Copyright (C) 2007 The Android Open Source Project
 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_HDMISERVICE_H
#define ANDROID_HDMISERVICE_H

#include <stdint.h>
#include <sys/types.h>

#include <utils/threads.h>
#include <utils/AssetManager.h>

#include <surfaceflinger/ISurfaceComposer.h>
#include <surfaceflinger/SurfaceComposerClient.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <pthread.h>

#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>

#include <cutils/config_utils.h>
#include <cutils/cpu_info.h>
#include <cutils/properties.h>
#include <cutils/sockets.h>

#include <linux/netlink.h>

#include <private/android_filesystem_config.h>


namespace android {

enum uevent_action { action_add, action_remove, action_change,
                                  action_online, action_offline, action_audio_on, action_audio_off, action_no_broadcast_online };
const int ueventParamMax = 32;
struct uevent {
    char *path;
    enum uevent_action action;
    char *subsystem;
    char *param[ueventParamMax];
    unsigned int seqnum;
    uevent() : path(NULL), subsystem(NULL) {
	for (int i = 0; i < ueventParamMax; i++)
	    param[i] = NULL;
    }
};

struct HDMIUeventQueue {
    HDMIUeventQueue* next;
    uevent mEvent;
    ~HDMIUeventQueue() {
        delete[] mEvent.path;
        delete[] mEvent.subsystem;
        for (int i = 0; i < ueventParamMax; i++) {
            if (!mEvent.param[i])
                break;
            delete[] mEvent.param[i];
        }
    }
};

class HDMIDaemon : public Thread, public IBinder::DeathRecipient
{
    virtual bool        threadLoop();
    virtual status_t    readyToRun();
    virtual void        onFirstRef();
    virtual void        binderDied(const wp<IBinder>& who);
    bool processUeventMessage(uevent& event);
    void queueUevent();
    void processUeventQueue();
    void processUevent();
    int processFrameworkCommand();
    bool sendCommandToFramework(uevent_action action = action_offline);
    bool cableConnected(bool defaultValue = true) const;
    bool readResolution();
    void setResolution(int ID);
    bool openFramebuffer();
    bool writeHPDOption(int userOption) const;
    inline bool isValidMode(int ID);
    bool checkHDCPPresent();

    int mFrameworkSock;
    int mAcceptedConnection;
    int mUeventSock;
    HDMIUeventQueue* mHDMIUeventQueueHead;
    sp<SurfaceComposerClient> mSession;
    int fd1;
    bool mDriverOnline;
    int mCurrentID;
    int mNxtMode;
    char mEDIDs[128];

public:
                HDMIDaemon();
    virtual     ~HDMIDaemon();

    sp<SurfaceComposerClient> session() const;
};

// ---------------------------------------------------------------------------

}; // namespace android

#endif