class NotifyHandler : public MessageHandler {
public:
NotifyHandler(JTvInputHal* hal, const tv_input_event_t* event);
+ ~NotifyHandler();
virtual void handleMessage(const Message& message);
static void notify(
tv_input_device_t* dev, tv_input_event_t* event, void* data);
+ static void cloneTvInputEvent(
+ tv_input_event_t* dstEvent, const tv_input_event_t* srcEvent);
+
Mutex mLock;
jweak mThiz;
tv_input_device_t* mDevice;
thiz->mLooper->sendMessage(new NotifyHandler(thiz, event), event->type);
}
+// static
+void JTvInputHal::cloneTvInputEvent(
+ tv_input_event_t* dstEvent, const tv_input_event_t* srcEvent) {
+ memcpy(dstEvent, srcEvent, sizeof(tv_input_event_t));
+ if ((srcEvent->type == TV_INPUT_EVENT_DEVICE_AVAILABLE ||
+ srcEvent->type == TV_INPUT_EVENT_DEVICE_UNAVAILABLE ||
+ srcEvent->type == TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED) &&
+ srcEvent->device_info.audio_address != NULL){
+ char* audio_address = new char[strlen(srcEvent->device_info.audio_address) + 1];
+ strcpy(audio_address, srcEvent->device_info.audio_address);
+ dstEvent->device_info.audio_address = audio_address;
+ }
+}
+
void JTvInputHal::onDeviceAvailable(const tv_input_device_info_t& info) {
{
Mutex::Autolock autoLock(&mLock);
JTvInputHal::NotifyHandler::NotifyHandler(JTvInputHal* hal, const tv_input_event_t* event) {
mHal = hal;
- memcpy(&mEvent, event, sizeof(mEvent));
+ cloneTvInputEvent(&mEvent, event);
+}
+
+JTvInputHal::NotifyHandler::~NotifyHandler() {
+ if ((mEvent.type == TV_INPUT_EVENT_DEVICE_AVAILABLE ||
+ mEvent.type == TV_INPUT_EVENT_DEVICE_UNAVAILABLE ||
+ mEvent.type == TV_INPUT_EVENT_STREAM_CONFIGURATIONS_CHANGED) &&
+ mEvent.device_info.audio_address != NULL) {
+ delete mEvent.device_info.audio_address;
+ }
}
void JTvInputHal::NotifyHandler::handleMessage(const Message& message) {