From f54b0e7becc68d37d38012dc1be3446e4344042b Mon Sep 17 00:00:00 2001 From: vanhofen Date: Mon, 17 May 2021 23:47:39 +0200 Subject: [PATCH] formatting code using astyle Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/bc17c13de46ad68a75aa909370872da539596096 Author: vanhofen Date: 2021-05-17 (Mon, 17 May 2021) Origin message was: ------------------ - formatting code using astyle ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- common/ca_ci.cpp | 271 +- common/hal_debug.cpp | 17 +- common/hal_debug.h | 22 +- common/proc_tools.c | 12 +- common/pwrmngr.cpp | 23 +- common/version_hal.cpp | 2 +- include/ca.h | 140 +- include/ca_ci.h | 364 +- include/cs_api.h | 26 +- include/cs_frontpanel.h | 94 +- include/cs_types.h | 16 +- include/dmx_hal.h | 26 +- include/glfb.h | 56 +- include/hardware_caps.h | 12 +- include/mmi.h | 21 +- include/pwrmngr.h | 30 +- include/version_hal.h | 14 +- libarmbox/audio.cpp | 126 +- libarmbox/audio_lib.h | 46 +- libarmbox/dmx.cpp | 78 +- libarmbox/hardware_caps.c | 48 +- libarmbox/hdmi_cec.cpp | 522 +- libarmbox/hdmi_cec.h | 128 +- libarmbox/hdmi_cec_types.h | 864 +- libarmbox/hisilicon.h | 26 +- libarmbox/init.cpp | 2 +- libarmbox/linux-uapi-cec.h | 995 +- libarmbox/playback_gst.cpp | 641 +- libarmbox/playback_gst.h | 104 +- libarmbox/playback_hisilicon.cpp | 1172 +-- libarmbox/playback_hisilicon.h | 260 +- libarmbox/playback_libeplayer3.cpp | 178 +- libarmbox/playback_libeplayer3.h | 17 +- libarmbox/record.cpp | 50 +- libarmbox/record_lib.h | 19 +- libarmbox/video.cpp | 602 +- libarmbox/video_lib.h | 91 +- libduckbox/init.cpp | 2 +- libdvbci/_dh_params.h | 6 +- libdvbci/aes_xcbc_mac.cpp | 16 +- libdvbci/aes_xcbc_mac.h | 3 +- libdvbci/descrambler.cpp | 19 +- libdvbci/dh_rsa_misc.cpp | 43 +- libdvbci/dvbci_appmgr.cpp | 27 +- libdvbci/dvbci_appmgr.h | 29 +- libdvbci/dvbci_camgr.cpp | 8 +- libdvbci/dvbci_camgr.h | 26 +- libdvbci/dvbci_ccmgr.cpp | 337 +- libdvbci/dvbci_ccmgr.h | 35 +- libdvbci/dvbci_datetimemgr.cpp | 6 +- libdvbci/dvbci_datetimemgr.h | 19 +- libdvbci/dvbci_mmi.cpp | 36 +- libdvbci/dvbci_mmi.h | 27 +- libdvbci/dvbci_resmgr.cpp | 40 +- libdvbci/dvbci_resmgr.h | 19 +- libdvbci/dvbci_session.cpp | 32 +- libdvbci/dvbci_session.h | 89 +- libdvbci/misc.cpp | 20 +- libeplayer3-sh4/include/input.h | 8 +- libeplayer3-sh4/include/manager.h | 12 +- libeplayer3-sh4/include/misc.h | 12 +- libeplayer3-sh4/include/output.h | 2 +- libeplayer3-sh4/include/pes.h | 38 +- libeplayer3-sh4/include/player.h | 29 +- libeplayer3-sh4/include/writer.h | 14 +- libeplayer3-sh4/input.cpp | 281 +- libeplayer3-sh4/manager.cpp | 96 +- libeplayer3-sh4/output.cpp | 88 +- libeplayer3-sh4/player.cpp | 134 +- libeplayer3-sh4/writer/aac.cpp | 13 +- libeplayer3-sh4/writer/ac3.cpp | 5 +- libeplayer3-sh4/writer/divx.cpp | 15 +- libeplayer3-sh4/writer/dts.cpp | 11 +- libeplayer3-sh4/writer/h263.cpp | 2 +- libeplayer3-sh4/writer/h264.cpp | 85 +- libeplayer3-sh4/writer/misc.cpp | 22 +- libeplayer3-sh4/writer/mp3.cpp | 5 +- libeplayer3-sh4/writer/mpeg2.cpp | 5 +- libeplayer3-sh4/writer/pcm.cpp | 171 +- libeplayer3-sh4/writer/pes.cpp | 50 +- libeplayer3-sh4/writer/vc1.cpp | 44 +- libeplayer3-sh4/writer/wmv.cpp | 35 +- libeplayer3-sh4/writer/writer.cpp | 20 +- libeplayer3/container/buff_ffmpeg.c | 4 +- libeplayer3/container/container_ffmpeg.c | 60 +- libeplayer3/external/ffmpeg/get_bits.h | 154 +- libeplayer3/external/ffmpeg/mpeg4audio.h | 2 +- libeplayer3/external/ffmpeg/put_bits.h | 6 +- libeplayer3/external/ffmpeg/src/mpeg4audio.c | 10 +- .../external/flv2mpeg4/src/flv2mpeg4.c | 16 +- .../external/flv2mpeg4/src/m4vencode.c | 4 +- libeplayer3/include/misc.h | 8 +- libeplayer3/include/pes.h | 4 +- libeplayer3/include/playback.h | 3 +- libeplayer3/main/exteplayer.c | 24 +- libeplayer3/manager/audio.c | 7 +- libeplayer3/manager/chapter.c | 4 +- libeplayer3/manager/video.c | 4 +- libeplayer3/output/linuxdvb_fake.c | 2 +- libeplayer3/output/linuxdvb_mipsel.c | 2 +- libeplayer3/output/linuxdvb_sh4.c | 2 +- libeplayer3/output/writer/common/misc.c | 2 +- libeplayer3/output/writer/mipsel/aac.c | 4 +- libeplayer3/output/writer/mipsel/divx3.c | 6 +- libeplayer3/output/writer/mipsel/h264.c | 4 +- libeplayer3/output/writer/mipsel/pcm.c | 6 +- libeplayer3/output/writer/mipsel/writer.c | 4 +- libeplayer3/output/writer/sh4/aac.c | 4 +- libeplayer3/output/writer/sh4/h264.c | 6 +- libeplayer3/output/writer/sh4/mpeg2.c | 2 +- libeplayer3/output/writer/sh4/pcm.c | 10 +- libeplayer3/output/writer/sh4/vc1.c | 2 +- libeplayer3/output/writer/sh4/wmv.c | 6 +- libeplayer3/output/writer/sh4/writer.c | 2 +- libeplayer3/playback/playback.c | 18 +- libgeneric-pc/audio.cpp | 145 +- libgeneric-pc/audio_lib.h | 46 +- libgeneric-pc/clutterfb.cpp | 120 +- libgeneric-pc/dmx.cpp | 260 +- libgeneric-pc/glfb.cpp | 154 +- libgeneric-pc/glfb_priv.h | 176 +- libgeneric-pc/hardware_caps.c | 7 +- libgeneric-pc/init.cpp | 6 +- libgeneric-pc/playback.cpp | 8 +- libgeneric-pc/playback_gst.h | 104 +- libgeneric-pc/playback_gst_01.cpp | 430 +- libgeneric-pc/playback_gst_10.cpp | 687 +- libgeneric-pc/playback_lib.h | 35 +- libgeneric-pc/video.cpp | 273 +- libgeneric-pc/video_lib.h | 172 +- libmipsbox/hardware_caps.c | 2 +- libraspi/audio.cpp | 10 +- libraspi/audio_lib.h | 41 +- libraspi/dmx.cpp | 252 +- libraspi/dmx_lib.h | 26 +- libraspi/glfb.cpp | 55 +- libraspi/glfb.h | 54 +- libraspi/hardware_caps.c | 2 +- libraspi/init.cpp | 70 +- libraspi/video.cpp | 8 +- libraspi/video_lib.h | 159 +- libspark/audio.cpp | 97 +- libspark/audio_lib.h | 56 +- libspark/audio_mixer.cpp | 15 +- libspark/audio_mixer.h | 2 +- libspark/dmx.cpp | 96 +- libspark/hardware_caps.c | 25 +- libspark/init.cpp | 155 +- libspark/irmp.c | 8758 +++++++++-------- libspark/irmp.h | 1056 +- libspark/irmpconfig.h | 382 +- libspark/lirmp_input.cpp | 105 +- libspark/playback_libeplayer3.cpp | 93 +- libspark/playback_libeplayer3.h | 11 +- libspark/record.cpp | 48 +- libspark/record_lib.h | 19 +- libspark/video.cpp | 453 +- libspark/video_lib.h | 115 +- libtest.cpp | 9 +- tools/pic2m2v.c | 4 +- tools/spark_fp.c | 38 +- 161 files changed, 13025 insertions(+), 11357 deletions(-) diff --git a/common/ca_ci.cpp b/common/ca_ci.cpp index f726863..396e42f 100644 --- a/common/ca_ci.cpp +++ b/common/ca_ci.cpp @@ -36,7 +36,7 @@ #define hal_debug(args...) _hal_debug(HAL_DEBUG_CA, this, args) -static const char * FILENAME = "[ca_ci]"; +static const char *FILENAME = "[ca_ci]"; #if HAVE_DUCKBOX_HARDWARE const char ci_path[] = "/dev/dvb/adapter0/ci%d"; ca_slot_info_t info; @@ -48,9 +48,10 @@ static int last_source = -1; static bool checkLiveSlot = false; static bool CertChecked = false; static bool Cert_OK = false; -static uint8_t NullPMT[50]={0x9F,0x80,0x32,0x2E,0x03,0x6E,0xA7,0x37,0x00,0x00,0x1B,0x15,0x7D,0x00,0x00,0x03,0x15,0x7E,0x00,0x00,0x03,0x15,0x7F,0x00, -0x00,0x06,0x15,0x80,0x00,0x00,0x06,0x15,0x82,0x00,0x00,0x0B,0x08,0x7B,0x00,0x00,0x05,0x09,0x42,0x00,0x00,0x06,0x15,0x81,0x00,0x00}; -static cCA* pcCAInstance = NULL; +static uint8_t NullPMT[50] = {0x9F, 0x80, 0x32, 0x2E, 0x03, 0x6E, 0xA7, 0x37, 0x00, 0x00, 0x1B, 0x15, 0x7D, 0x00, 0x00, 0x03, 0x15, 0x7E, 0x00, 0x00, 0x03, 0x15, 0x7F, 0x00, + 0x00, 0x06, 0x15, 0x80, 0x00, 0x00, 0x06, 0x15, 0x82, 0x00, 0x00, 0x0B, 0x08, 0x7B, 0x00, 0x00, 0x05, 0x09, 0x42, 0x00, 0x00, 0x06, 0x15, 0x81, 0x00, 0x00 + }; +static cCA *pcCAInstance = NULL; /* für callback */ /* nur diese Message wird vom CI aus neutrinoMessages.h benutzt */ @@ -82,7 +83,7 @@ cCA::~cCA() printf("%s -> %s\n", FILENAME, __func__); } -cCA * cCA::GetInstance() +cCA *cCA::GetInstance() { if (pcCAInstance == NULL) { @@ -94,7 +95,7 @@ cCA * cCA::GetInstance() return pcCAInstance; } -bool cCA::checkQueueSize(eDVBCISlot* slot) +bool cCA::checkQueueSize(eDVBCISlot *slot) { return (slot->sendqueue.size() > 0); } @@ -106,11 +107,11 @@ void cCA::write_ci_info(int slot, CaIdVector caids) char mname[200]; char fname[20]; int count, cx, cy, i; - snprintf(fname, sizeof(fname), "/tmp/ci-slot%d" , slot); + snprintf(fname, sizeof(fname), "/tmp/ci-slot%d", slot); ModuleName(CA_SLOT_TYPE_CI, slot, mname); - FILE* fd = fopen(fname, "w"); + FILE *fd = fopen(fname, "w"); if (fd == NULL) return; - snprintf(buf, sizeof(buf), "%s\n" , mname); + snprintf(buf, sizeof(buf), "%s\n", mname); fputs(buf, fd); if (caids.size() > 40) count = 40; @@ -130,22 +131,22 @@ void cCA::write_ci_info(int slot, CaIdVector caids) void cCA::del_ci_info(int slot) { char fname[20]; - snprintf(fname, sizeof(fname), "/tmp/ci-slot%d" , slot); + snprintf(fname, sizeof(fname), "/tmp/ci-slot%d", slot); if (access(fname, F_OK) == 0) remove(fname); } /* helper function to call the cpp thread loop */ -void* execute_thread(void *c) +void *execute_thread(void *c) { - eDVBCISlot* slot = (eDVBCISlot*) c; - cCA *obj = (cCA*)slot->pClass; + eDVBCISlot *slot = (eDVBCISlot *) c; + cCA *obj = (cCA *)slot->pClass; obj->slot_pollthread(c); return NULL; } /* from dvb-apps */ -int asn_1_decode(uint16_t * length, unsigned char * asn_1_array, - uint32_t asn_1_array_len) +int asn_1_decode(uint16_t *length, unsigned char *asn_1_array, + uint32_t asn_1_array_len) { uint8_t length_field; @@ -180,7 +181,7 @@ int asn_1_decode(uint16_t * length, unsigned char * asn_1_array, } //wait for a while for some data und read it if some -eData waitData(int fd, unsigned char* buffer, int* len) +eData waitData(int fd, unsigned char *buffer, int *len) { int retval; struct pollfd fds; @@ -203,7 +204,7 @@ eData waitData(int fd, unsigned char* buffer, int* len) { if (fds.revents & POLLIN) { - int n = read (fd, buffer, *len); + int n = read(fd, buffer, *len); if (n > 0) { *len = n; @@ -234,7 +235,7 @@ eData waitData(int fd, unsigned char* buffer, int* len) return eDataError; } -static bool transmitData(eDVBCISlot* slot, unsigned char* d, int len) +static bool transmitData(eDVBCISlot *slot, unsigned char *d, int len) { printf("%s -> %s len(%d)\n", FILENAME, __func__, len); @@ -265,19 +266,20 @@ static bool transmitData(eDVBCISlot* slot, unsigned char* d, int len) } //send some data on an fd, for a special slot and connection_id -eData sendData(eDVBCISlot* slot, unsigned char* data, int len) +eData sendData(eDVBCISlot *slot, unsigned char *data, int len) { #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE - unsigned char *d = (unsigned char*) malloc(len); - memcpy(d, data, len); - transmitData(slot, d, len); + unsigned char *d = (unsigned char *) malloc(len); + memcpy(d, data, len); + transmitData(slot, d, len); #else // only poll connection if we are not awaiting an answer slot->pollConnection = false; //send data_last and data - if (len < 127) { - unsigned char *d = (unsigned char*) malloc(len + 5); + if (len < 127) + { + unsigned char *d = (unsigned char *) malloc(len + 5); memcpy(d + 5, data, len); d[0] = slot->slot; d[1] = slot->connection_id; @@ -287,8 +289,9 @@ eData sendData(eDVBCISlot* slot, unsigned char* data, int len) len += 5; transmitData(slot, d, len); } - else if (len > 126 && len < 255) { - unsigned char *d = (unsigned char*) malloc(len + 6); + else if (len > 126 && len < 255) + { + unsigned char *d = (unsigned char *) malloc(len + 6); memcpy(d + 6, data, len); d[0] = slot->slot; d[1] = slot->connection_id; @@ -299,8 +302,9 @@ eData sendData(eDVBCISlot* slot, unsigned char* data, int len) len += 6; transmitData(slot, d, len); } - else if (len > 254) { - unsigned char *d = (unsigned char*) malloc(len + 7); + else if (len > 254) + { + unsigned char *d = (unsigned char *) malloc(len + 7); memcpy(d + 7, data, len); d[0] = slot->slot; d[1] = slot->connection_id; @@ -320,14 +324,14 @@ eData sendData(eDVBCISlot* slot, unsigned char* data, int len) #if HAVE_DUCKBOX_HARDWARE //send a transport connection create request -bool sendCreateTC(eDVBCISlot* slot) +bool sendCreateTC(eDVBCISlot *slot) { unsigned char data[5]; data[0] = slot->slot; - data[1] = slot->slot + 1; /* conid */ + data[1] = slot->slot + 1; /* conid */ data[2] = T_CREATE_T_C; data[3] = 1; - data[4] = slot->slot + 1 /* conid */; + data[4] = slot->slot + 1 /* conid */; printf("Create TC: "); for (int i = 0; i < 5; i++) printf("%02x ", data[i]); @@ -336,7 +340,7 @@ bool sendCreateTC(eDVBCISlot* slot) return true; } -static bool sendDataLast(eDVBCISlot* slot) +static bool sendDataLast(eDVBCISlot *slot) { unsigned char data[5]; slot->pollConnection = false; @@ -356,7 +360,7 @@ static bool sendDataLast(eDVBCISlot* slot) return true; } -static bool sendRCV(eDVBCISlot* slot) +static bool sendRCV(eDVBCISlot *slot) { unsigned char send_data[5]; slot->pollConnection = false; @@ -376,7 +380,7 @@ static bool sendRCV(eDVBCISlot* slot) return true; } -void cCA::process_tpdu(eDVBCISlot* slot, unsigned char tpdu_tag, __u8* data, int asn_data_length, int /*con_id*/) +void cCA::process_tpdu(eDVBCISlot *slot, unsigned char tpdu_tag, __u8 *data, int asn_data_length, int /*con_id*/) { switch (tpdu_tag) { @@ -402,7 +406,7 @@ void cCA::process_tpdu(eDVBCISlot* slot, unsigned char tpdu_tag, __u8* data, int { int new_data_length = slot->receivedLen + asn_data_length; printf("%s %s Got \"Data More\" from Module\n", FILENAME, __FUNCTION__); - __u8 *new_data_buffer = (__u8*) realloc(slot->receivedData, new_data_length); + __u8 *new_data_buffer = (__u8 *) realloc(slot->receivedData, new_data_length); slot->receivedData = new_data_buffer; memcpy(slot->receivedData + slot->receivedLen, data, asn_data_length); slot->receivedLen = new_data_length; @@ -428,11 +432,11 @@ void cCA::process_tpdu(eDVBCISlot* slot, unsigned char tpdu_tag, __u8* data, int } else { - /* chained package + /* chained package ?? DBO: I never have seen one */ int new_data_length = slot->receivedLen + asn_data_length; printf("%s -> chained data\n", FILENAME); - __u8 *new_data_buffer = (__u8*) realloc(slot->receivedData, new_data_length); + __u8 *new_data_buffer = (__u8 *) realloc(slot->receivedData, new_data_length); slot->receivedData = new_data_buffer; memcpy(slot->receivedData + slot->receivedLen, data, asn_data_length); slot->receivedLen = new_data_length; @@ -482,7 +486,7 @@ void cCA::process_tpdu(eDVBCISlot* slot, unsigned char tpdu_tag, __u8* data, int bool cCA::SendMessage(const CA_MESSAGE *msg) { hal_debug("%s\n", __func__); - if(cam_messenger) + if (cam_messenger) #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE cam_messenger(EVT_CA_MESSAGE, (uintptr_t) msg); #else @@ -503,7 +507,7 @@ void cCA::MenuEnter(enum CA_SLOT_TYPE, uint32_t bSlotIndex) { printf("%s -> %s Slot(%d)\n", FILENAME, __func__, bSlotIndex); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -531,7 +535,7 @@ void cCA::MenuAnswer(enum CA_SLOT_TYPE, uint32_t bSlotIndex, uint32_t choice) { printf("%s -> %s Slot(%d) choice(%d)\n", FILENAME, __func__, bSlotIndex, choice); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -543,18 +547,18 @@ void cCA::MenuAnswer(enum CA_SLOT_TYPE, uint32_t bSlotIndex, uint32_t choice) } } -void cCA::InputAnswer(enum CA_SLOT_TYPE, uint32_t bSlotIndex, uint8_t * pBuffer, int nLength) +void cCA::InputAnswer(enum CA_SLOT_TYPE, uint32_t bSlotIndex, uint8_t *pBuffer, int nLength) { printf("%s -> %s Slot(%d)\n", FILENAME, __func__, bSlotIndex); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { if ((*it)->slot == bSlotIndex) { if ((*it)->hasMMIManager) - (*it)->mmiSession->answerEnq((char*) pBuffer, nLength); + (*it)->mmiSession->answerEnq((char *) pBuffer, nLength); break; } } @@ -564,7 +568,7 @@ void cCA::MenuClose(enum CA_SLOT_TYPE, uint32_t bSlotIndex) { printf("%s -> %s Slot(%d)\n", FILENAME, __func__, bSlotIndex); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -589,9 +593,9 @@ uint32_t cCA::GetNumberSmartCardSlots(void) return 0; } -void cCA::ModuleName(enum CA_SLOT_TYPE, uint32_t slot, char * Name) +void cCA::ModuleName(enum CA_SLOT_TYPE, uint32_t slot, char *Name) { - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { if ((*it)->slot == slot) @@ -604,7 +608,7 @@ void cCA::ModuleName(enum CA_SLOT_TYPE, uint32_t slot, char * Name) bool cCA::ModulePresent(enum CA_SLOT_TYPE, uint32_t slot) { - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -619,7 +623,7 @@ bool cCA::ModulePresent(enum CA_SLOT_TYPE, uint32_t slot) int cCA::GetCAIDS(CaIdVector &Caids) { - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { if ((*it)->camIsReady) @@ -631,10 +635,10 @@ int cCA::GetCAIDS(CaIdVector &Caids) return 0; } -bool cCA::StopLiveCI( u64 TP, u16 SID, u8 source, u32 calen) +bool cCA::StopLiveCI(u64 TP, u16 SID, u8 source, u32 calen) { printf("%s -> %s\n", FILENAME, __func__); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { for (int j = 0; j < CI_MAX_MULTI; j++) @@ -650,10 +654,10 @@ bool cCA::StopLiveCI( u64 TP, u16 SID, u8 source, u32 calen) return false; } -bool cCA::StopRecordCI( u64 TP, u16 SID, u8 source, u32 calen) +bool cCA::StopRecordCI(u64 TP, u16 SID, u8 source, u32 calen) { printf("%s -> %s\n", FILENAME, __func__); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { for (int j = 0; j < CI_MAX_MULTI; j++) @@ -672,7 +676,7 @@ bool cCA::StopRecordCI( u64 TP, u16 SID, u8 source, u32 calen) SlotIt cCA::FindFreeSlot(u64 TP, u8 source, u16 SID, ca_map_t camap, u8 scrambled) { printf("%s -> %s\n", FILENAME, __func__); - std::list::iterator it; + std::list::iterator it; ca_map_iterator_t caIt; unsigned int i; int count = 0; @@ -680,7 +684,10 @@ SlotIt cCA::FindFreeSlot(u64 TP, u8 source, u16 SID, ca_map_t camap, u8 scramble for (it = slot_data.begin(); it != slot_data.end(); ++it) { - if (!scrambled) { continue; } + if (!scrambled) + { + continue; + } if ((*it)->init) count++; @@ -721,8 +728,15 @@ SlotIt cCA::FindFreeSlot(u64 TP, u8 source, u16 SID, ca_map_t camap, u8 scramble if ((*it)->bsids.size()) { for (i = 0; i < (*it)->bsids.size(); i++) - if ((*it)->bsids[i] == SID) {tmpSidBlackListed = true; break;} - if (i == (*it)->bsids.size()) {(*it)->SidBlackListed = false;} + if ((*it)->bsids[i] == SID) + { + tmpSidBlackListed = true; + break; + } + if (i == (*it)->bsids.size()) + { + (*it)->SidBlackListed = false; + } } for (int j = 0; j < CI_MAX_MULTI; j++) @@ -743,7 +757,7 @@ SlotIt cCA::FindFreeSlot(u64 TP, u8 source, u16 SID, ca_map_t camap, u8 scramble { if ((*it)->source == source && (!checkLiveSlot || !liveUse_found)) { - SendNullPMT((eDVBCISlot*)(*it)); + SendNullPMT((eDVBCISlot *)(*it)); (*it)->SidBlackListed = true; for (int j = 0; j < CI_MAX_MULTI; j++) (*it)->SID[j] = 0; @@ -786,7 +800,7 @@ SlotIt cCA::FindFreeSlot(u64 TP, u8 source, u16 SID, ca_map_t camap, u8 scramble } /* erstmal den capmt wie er von Neutrino kommt in den Slot puffern */ -bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, u32 calen, const unsigned char * /*rawpmt*/, u32 /*rawlen*/, enum CA_SLOT_TYPE /*SlotType*/, unsigned char scrambled, ca_map_t cm, int mode, bool enabled) +bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char *cabuf, u32 calen, const unsigned char * /*rawpmt*/, u32 /*rawlen*/, enum CA_SLOT_TYPE /*SlotType*/, unsigned char scrambled, ca_map_t cm, int mode, bool enabled) { u16 SID = (u16)(tpid & 0xFFFF); u64 TP = tpid >> 16; @@ -794,7 +808,7 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, bool sid_found = false; bool recordUse_found = false; printf("%s -> %s\n", FILENAME, __func__); - if (!num_slots) return true; /* stb's without ci-slots */ + if (!num_slots) return true; /* stb's without ci-slots */ #if x_debug printf("TP: %llX\n", TP); printf("SID: %04X\n", SID); @@ -846,7 +860,7 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, } else { - SendNullPMT((eDVBCISlot*)(*It2)); + SendNullPMT((eDVBCISlot *)(*It2)); (*It2)->scrambled = 0; (*It2)->TP = 0; for (int j = 0; j < CI_MAX_MULTI; j++) @@ -869,14 +883,14 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, (*It)->ci_use_count++; if (!(cabuf[pos] & 0x80)) - pos +=1; + pos += 1; else pos += ((cabuf[pos] & 0x7F) + 1); (*It)->pmtlen = calen; for (i = 0; i < calen; i++) (*It)->pmtdata[i] = cabuf[i]; - (*It)->pmtdata[pos] = 0x04; // CAPMT_ADD + (*It)->pmtdata[pos] = 0x04; // CAPMT_ADD (*It)->newCapmt = true; } @@ -888,8 +902,8 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, (*It)->ci_use_count = 1; (*It)->TP = TP; #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE - if(!checkLiveSlot && mode && (*It)->source != source) - setInputSource((eDVBCISlot*)(*It), false); + if (!checkLiveSlot && mode && (*It)->source != source) + setInputSource((eDVBCISlot *)(*It), false); #endif (*It)->source = source; (*It)->pmtlen = calen; @@ -900,7 +914,7 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE if ((*It)->newCapmt) - extractPids((eDVBCISlot*)(*It)); + extractPids((eDVBCISlot *)(*It)); #endif if ((*It)->scrambled && !(*It)->SidBlackListed) { @@ -910,7 +924,7 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, { if (mode) { - if(!checkLiveSlot) + if (!checkLiveSlot) (*It)->liveUse[j] = false; (*It)->recordUse[j] = true; } @@ -921,13 +935,13 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, } if (!(*It)->newCapmt && (*It)->ccmgr_ready && (*It)->hasCCManager && (*It)->scrambled && !(*It)->SidBlackListed) - (*It)->ccmgrSession->resendKey((eDVBCISlot*)(*It)); + (*It)->ccmgrSession->resendKey((eDVBCISlot *)(*It)); } else { #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE - std::list::iterator it; + std::list::iterator it; recordUse_found = false; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -940,7 +954,7 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, } if (!recordUse_found && (*it)->init) { - setInputSource((eDVBCISlot*)(*it), false); + setInputSource((eDVBCISlot *)(*it), false); } } if (!(*it)->init) @@ -968,17 +982,17 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, } #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE -void cCA::extractPids(eDVBCISlot* slot) +void cCA::extractPids(eDVBCISlot *slot) { u32 prg_info_len; u32 es_info_len = 0; u16 pid; - u8 * data = slot->pmtdata; + u8 *data = slot->pmtdata; u32 len = slot->pmtlen; int pos = 3; slot->pids.clear(); - + if (!(data[pos] & 0x80)) pos += 5; else @@ -987,8 +1001,9 @@ void cCA::extractPids(eDVBCISlot* slot) prg_info_len = ((data[pos] << 8) | data[pos + 1]) & 0xFFF; pos += prg_info_len + 2; - for (u32 i = pos; i < len; i += es_info_len + 5) { - pid = (data[i+1] << 8 | data[i+2]) & 0x1FFF; + for (u32 i = pos; i < len; i += es_info_len + 5) + { + pid = (data[i + 1] << 8 | data[i + 2]) & 0x1FFF; es_info_len = ((data[i + 3] << 8) | data[i + 4]) & 0xfff; slot->pids.push_back(pid); } @@ -1004,13 +1019,13 @@ void cCA::extractPids(eDVBCISlot* slot) } #endif -void cCA::setSource(eDVBCISlot* slot) +void cCA::setSource(eDVBCISlot *slot) { char buf[64]; snprintf(buf, 64, "/proc/stb/tsmux/ci%d_input", slot->slot); FILE *ci = fopen(buf, "wb"); - if (ci > (void*)0) + if (ci > (void *)0) { switch (slot->source) { @@ -1096,13 +1111,16 @@ void cCA::setSource(eDVBCISlot* slot) } #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE -static std::string getTunerLetter(int number) { return std::string(1, char(65 + number)); } +static std::string getTunerLetter(int number) +{ + return std::string(1, char(65 + number)); +} void cCA::setInputs() { char input[64]; char choices[64]; - FILE * fd = 0; + FILE *fd = 0; #if BOXMODEL_VUULTIMO4K for (int number = 0; number < 24; number++) // tuner A to X, input 0 to 23 @@ -1115,7 +1133,7 @@ void cCA::setInputs() #endif { snprintf(choices, 64, "/proc/stb/tsmux/input%d_choices", number); - if(access(choices, R_OK) < 0) + if (access(choices, R_OK) < 0) { printf("no choices for input%d\n", number); continue; @@ -1126,7 +1144,7 @@ void cCA::setInputs() if (fd) { printf("set input%d to tuner %s\n", number, getTunerLetter(number).c_str()); - fprintf(fd,"%s", getTunerLetter(number).c_str()); + fprintf(fd, "%s", getTunerLetter(number).c_str()); fclose(fd); } else @@ -1136,14 +1154,14 @@ void cCA::setInputs() } } -void cCA::setInputSource(eDVBCISlot* slot, bool ci) +void cCA::setInputSource(eDVBCISlot *slot, bool ci) { char buf[64]; printf("%s set input%d to %s%d\n", FILENAME, slot->source, ci ? "ci" : "tuner", ci ? slot->slot : slot->source); snprintf(buf, 64, "/proc/stb/tsmux/input%d", slot->source); FILE *input = fopen(buf, "wb"); - if (input > (void*)0) + if (input > (void *)0) { if (ci) { @@ -1255,7 +1273,7 @@ cCA::cCA(int Slots) for (int i = 0; i < Slots; i++) { - eDVBCISlot* slot = (eDVBCISlot*) malloc(sizeof(eDVBCISlot)); + eDVBCISlot *slot = (eDVBCISlot *) malloc(sizeof(eDVBCISlot)); slot->slot = i; slot->fd = -1; slot->connection_id = 0; @@ -1318,7 +1336,7 @@ cCA::cCA(int Slots) /* create a thread for each slot */ if (slot->fd > 0) { - if (pthread_create(&slot->slot_thread, 0, execute_thread, (void*)slot)) + if (pthread_create(&slot->slot_thread, 0, execute_thread, (void *)slot)) { printf("pthread_create"); } @@ -1330,7 +1348,7 @@ void cCA::ModuleReset(enum CA_SLOT_TYPE, uint32_t slot) { printf("%s -> %s\n", FILENAME, __func__); - std::list::iterator it; + std::list::iterator it; bool haveFound = false; for (it = slot_data.begin(); it != slot_data.end(); ++it) @@ -1347,11 +1365,11 @@ void cCA::ModuleReset(enum CA_SLOT_TYPE, uint32_t slot) usleep(200000); #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE last_source = (int)(*it)->source; - setInputSource((eDVBCISlot*)(*it), false); + setInputSource((eDVBCISlot *)(*it), false); #endif if ((*it)->hasCCManager) - (*it)->ccmgrSession->ci_ccmgr_doClose((eDVBCISlot*)(*it)); - eDVBCISession::deleteSessions((eDVBCISlot*)(*it)); + (*it)->ccmgrSession->ci_ccmgr_doClose((eDVBCISlot *)(*it)); + eDVBCISession::deleteSessions((eDVBCISlot *)(*it)); (*it)->mmiSession = NULL; (*it)->hasMMIManager = false; (*it)->hasCAManager = false; @@ -1389,9 +1407,9 @@ void cCA::ModuleReset(enum CA_SLOT_TYPE, uint32_t slot) (*it)->camask = 0; memset((*it)->pmtdata, 0, sizeof((*it)->pmtdata)); - while((*it)->sendqueue.size()) + while ((*it)->sendqueue.size()) { - delete [] (*it)->sendqueue.top().data; + delete [](*it)->sendqueue.top().data; (*it)->sendqueue.pop(); } @@ -1406,7 +1424,7 @@ void cCA::ModuleReset(enum CA_SLOT_TYPE, uint32_t slot) } } -void cCA::ci_inserted(eDVBCISlot* slot) +void cCA::ci_inserted(eDVBCISlot *slot) { printf("1. cam (%d) status changed ->cam now present\n", slot->slot); @@ -1425,7 +1443,7 @@ void cCA::ci_inserted(eDVBCISlot* slot) slot->connection_id = slot->slot + 1; #endif /* Send a message to Neutrino cam_menu handler */ - CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE)); + CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE)); memset(pMsg, 0, sizeof(CA_MESSAGE)); pMsg->MsgId = CA_MESSAGE_MSG_INSERTED; pMsg->SlotType = CA_SLOT_TYPE_CI; @@ -1435,12 +1453,12 @@ void cCA::ci_inserted(eDVBCISlot* slot) slot->camIsReady = true; } -void cCA::ci_removed(eDVBCISlot* slot) +void cCA::ci_removed(eDVBCISlot *slot) { printf("cam (%d) status changed ->cam now _not_ present\n", slot->slot); #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE - last_source = (int)slot->source; - setInputSource(slot, false); + last_source = (int)slot->source; + setInputSource(slot, false); #endif if (slot->hasCCManager) slot->ccmgrSession->ci_ccmgr_doClose(slot); @@ -1485,14 +1503,14 @@ void cCA::ci_removed(eDVBCISlot* slot) /* delete ci info file */ del_ci_info(slot->slot); /* Send a message to Neutrino cam_menu handler */ - CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE)); + CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE)); memset(pMsg, 0, sizeof(CA_MESSAGE)); pMsg->MsgId = CA_MESSAGE_MSG_REMOVED; pMsg->SlotType = CA_SLOT_TYPE_CI; pMsg->Slot = slot->slot; SendMessage(pMsg); - while(slot->sendqueue.size()) + while (slot->sendqueue.size()) { delete [] slot->sendqueue.top().data; slot->sendqueue.pop(); @@ -1504,14 +1522,14 @@ void cCA::ci_removed(eDVBCISlot* slot) void cCA::slot_pollthread(void *c) { unsigned char data[1024 * 4]; - eDVBCISlot* slot = (eDVBCISlot*) c; + eDVBCISlot *slot = (eDVBCISlot *) c; bool wait = false; while (1) { #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE /* Armbox/Mipsbox */ - int len = 1024 *4; + int len = 1024 * 4; eData status; switch (slot->status) @@ -1531,7 +1549,8 @@ void cCA::slot_pollthread(void *c) { #if y_debug // test was kommt - if (len) { + if (len) + { printf("1. received : > "); for (int i = 0; i < len; i++) printf("%02x ", data[i]); @@ -1546,7 +1565,7 @@ void cCA::slot_pollthread(void *c) /* slow down the loop, if no CI cam present */ // printf("***sleep\n"); sleep(1); - } /* case statusnone */ + } /* case statusnone */ break; case eStatusWait: { @@ -1594,9 +1613,9 @@ FROM_FIRST: printf("unknown state %d\n", slot->status); break; } /* switch(slot->status) */ -#else /* Duckbox */ - int len = 1024 *4; - unsigned char* d; +#else /* Duckbox */ + int len = 1024 * 4; + unsigned char *d; eData status; switch (slot->status) @@ -1639,7 +1658,7 @@ FROM_FIRST: } } } - } /* case statusnone */ + } /* case statusnone */ break; case eStatusWait: { @@ -1649,7 +1668,8 @@ FROM_FIRST: slot->pollConnection = false; d = data; #if z_debug - if ((len == 6 && d[4] == 0x80) || len > 6) { + if ((len == 6 && d[4] == 0x80) || len > 6) + { printf("slot: %d con-id: %d tpdu-tag: %02X len: %d\n", d[0], d[1], d[2], len); printf("received data: >"); for (int i = 0; i < len; i++) @@ -1749,7 +1769,7 @@ FROM_FIRST: printf("unknown state %d\n", slot->status); break; } /* switch(slot->status) */ -#endif /* end Duckbox */ +#endif /* end Duckbox */ #if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE if (!slot->init && slot->camIsReady && last_source > -1) { @@ -1776,7 +1796,7 @@ FROM_FIRST: write_ci_info(slot->slot, slot->cam_caids); /* Send a message to Neutrino cam_menu handler */ - CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE)); + CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE)); memset(pMsg, 0, sizeof(CA_MESSAGE)); pMsg->MsgId = CA_MESSAGE_MSG_INIT_OK; pMsg->SlotType = CA_SLOT_TYPE_CI; @@ -1784,7 +1804,7 @@ FROM_FIRST: SendMessage(pMsg); /* resend a capmt if we have one. this is not very proper but I cant any mechanism in neutrino currently. so if a cam is inserted a pmt is not resend */ - /* not necessary: the arrived capmt will be automaticly send */ + /* not necessary: the arrived capmt will be automaticly send */ //SendCaPMT(slot); } if (slot->hasCAManager && slot->hasAppManager && slot->newCapmt) @@ -1800,7 +1820,7 @@ FROM_FIRST: } } -bool cCA::SendCaPMT(eDVBCISlot* slot) +bool cCA::SendCaPMT(eDVBCISlot *slot) { printf("%s -> %s\n", FILENAME, __func__); if (slot->fd > 0) @@ -1863,14 +1883,14 @@ void cCA::SetInitMask(enum CA_INIT_MASK p) SlotIt cCA::GetSlot(unsigned int slot) { - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) if ((*it)->slot == slot && (*it)->init) return it; return it; } -bool cCA::SendNullPMT(eDVBCISlot* slot) +bool cCA::SendNullPMT(eDVBCISlot *slot) { printf("%s > %s >**\n", FILENAME, __func__); if ((slot->fd > 0) && (slot->camIsReady) && (slot->hasCAManager)) @@ -1882,7 +1902,7 @@ bool cCA::SendNullPMT(eDVBCISlot* slot) bool cCA::CheckCerts(void) { - if(!CertChecked) + if (!CertChecked) { if (access(ROOT_CERT, F_OK) == 0 && access(ROOT_CERT, F_OK) == 0 && access(ROOT_CERT, F_OK) == 0) Cert_OK = true; @@ -1893,7 +1913,7 @@ bool cCA::CheckCerts(void) bool cCA::checkChannelID(u64 chanID) { - std::list::iterator it; + std::list::iterator it; u16 SID = (u16)(chanID & 0xFFFF); u64 TP = chanID >> 16; for (it = slot_data.begin(); it != slot_data.end(); ++it) @@ -1917,16 +1937,16 @@ void cCA::setCheckLiveSlot(int check) void cCA::SetTSClock(u32 Speed, int slot) { -/* TODO: - * For now using the coolstream values from neutrino cam_menu - * where 6 ( == 6000000 Hz ) means : 'normal' - * and other values mean : 'high' - * also only ci0 will be changed - * for more than one ci slot code must be changed in neutrino cam_menu - * and in zapit where ci_clock is set during start. - * and here too. - * On the other hand: or ci_clock will be set here for all ci slots ???? - */ + /* TODO: + * For now using the coolstream values from neutrino cam_menu + * where 6 ( == 6000000 Hz ) means : 'normal' + * and other values mean : 'high' + * also only ci0 will be changed + * for more than one ci slot code must be changed in neutrino cam_menu + * and in zapit where ci_clock is set during start. + * and here too. + * On the other hand: or ci_clock will be set here for all ci slots ???? + */ char buf[64]; snprintf(buf, 64, "/proc/stb/tsmux/ci%d_tsclk", slot); FILE *ci = fopen(buf, "wb"); @@ -1935,8 +1955,7 @@ void cCA::SetTSClock(u32 Speed, int slot) { if (Speed > 9 * 1000000) fprintf(ci, "extra_high"); - else - if (Speed > 6 * 1000000) + else if (Speed > 6 * 1000000) fprintf(ci, "high"); else fprintf(ci, "normal"); diff --git a/common/hal_debug.cpp b/common/hal_debug.cpp index 9679bb5..376b160 100644 --- a/common/hal_debug.cpp +++ b/common/hal_debug.cpp @@ -12,7 +12,8 @@ int cnxt_debug = 0; /* compat, unused */ int debuglevel = -1; -static const char* hal_facility[] = { +static const char *hal_facility[] = +{ "audio ", "video ", "demux ", @@ -40,7 +41,7 @@ void _hal_debug(int facility, const void *func, const char *fmt, ...) if (debuglevel < 0) fprintf(stderr, "hal_debug: debuglevel not initialized!\n"); - if (! ((1 << facility) & debuglevel)) + if (!((1 << facility) & debuglevel)) return; fprintf(stderr, "[HAL:%08lx:%s] ", (long)func, hal_facility[facility]); @@ -63,14 +64,18 @@ void hal_debug_init(void) { fprintf(stderr, "libstb-hal debug options can be set by exporting HAL_DEBUG.\n"); fprintf(stderr, "The following values (or bitwise OR combinations) are valid:\n"); - while (hal_facility[i]) { + while (hal_facility[i]) + { fprintf(stderr, "\tcomponent: %s 0x%02x\n", hal_facility[i], 1 << i); i++; } fprintf(stderr, "\tall components: 0x%02x\n", (1 << i) - 1); - } else { + } + else + { fprintf(stderr, "libstb-hal debug is active for the following components:\n"); - while (hal_facility[i]) { + while (hal_facility[i]) + { if (debuglevel & (1 << i)) fprintf(stderr, "%s ", hal_facility[i]); i++; @@ -84,5 +89,5 @@ void hal_set_threadname(const char *name) char threadname[17]; strncpy(threadname, name, sizeof(threadname)); threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); + prctl(PR_SET_NAME, (unsigned long)&threadname); } diff --git a/common/hal_debug.h b/common/hal_debug.h index 7c3fc2a..35bf876 100644 --- a/common/hal_debug.h +++ b/common/hal_debug.h @@ -1,20 +1,20 @@ #ifndef __HAL_DEBUG_H__ #define __HAL_DEBUG_H__ -#define HAL_DEBUG_AUDIO 0 -#define HAL_DEBUG_VIDEO 1 -#define HAL_DEBUG_DEMUX 2 -#define HAL_DEBUG_PLAYBACK 3 -#define HAL_DEBUG_PWRMNGR 4 -#define HAL_DEBUG_INIT 5 -#define HAL_DEBUG_CA 6 -#define HAL_DEBUG_RECORD 7 -#define HAL_DEBUG_ALL ((1<<8)-1) +#define HAL_DEBUG_AUDIO 0 +#define HAL_DEBUG_VIDEO 1 +#define HAL_DEBUG_DEMUX 2 +#define HAL_DEBUG_PLAYBACK 3 +#define HAL_DEBUG_PWRMNGR 4 +#define HAL_DEBUG_INIT 5 +#define HAL_DEBUG_CA 6 +#define HAL_DEBUG_RECORD 7 +#define HAL_DEBUG_ALL ((1<<8)-1) extern int debuglevel; -void _hal_debug(int facility, const void *, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); -void _hal_info(int facility, const void *, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); +void _hal_debug(int facility, const void *, const char *fmt, ...) __attribute__((format(printf, 3, 4))); +void _hal_info(int facility, const void *, const char *fmt, ...) __attribute__((format(printf, 3, 4))); void hal_debug_init(void); void hal_set_threadname(const char *name); diff --git a/common/proc_tools.c b/common/proc_tools.c index 0983de9..74761ce 100644 --- a/common/proc_tools.c +++ b/common/proc_tools.c @@ -10,8 +10,8 @@ #include #include #include -#include /* isspace */ -#include /* sscanf */ +#include /* isspace */ +#include /* sscanf */ #include "proc_tools.h" @@ -35,12 +35,12 @@ int proc_get(const char *path, char *value, const int len) if (pfd < 0) return pfd; ret = read(pfd, value, len); - value[len-1] = '\0'; /* make sure string is terminated */ + value[len - 1] = '\0'; /* make sure string is terminated */ if (ret >= 0) { - while (ret > 0 && isspace(value[ret-1])) - ret--; /* remove trailing whitespace */ - value[ret] = '\0'; /* terminate, even if ret = 0 */ + while (ret > 0 && isspace(value[ret - 1])) + ret--; /* remove trailing whitespace */ + value[ret] = '\0'; /* terminate, even if ret = 0 */ } ret2 = close(pfd); if (ret2 < 0) diff --git a/common/pwrmngr.cpp b/common/pwrmngr.cpp index 98e9ed2..f9c7494 100644 --- a/common/pwrmngr.cpp +++ b/common/pwrmngr.cpp @@ -61,11 +61,14 @@ unsigned long cCpuFreqManager::GetDelta(void) } #if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE -unsigned long cCpuFreqManager::GetCpuFreq(void) { +unsigned long cCpuFreqManager::GetCpuFreq(void) +{ int freq = 0; - if (FILE *pll0 = fopen("/proc/cpu_frequ/pll0_ndiv_mdiv", "r")) { + if (FILE *pll0 = fopen("/proc/cpu_frequ/pll0_ndiv_mdiv", "r")) + { char buffer[120]; - while(fgets(buffer, sizeof(buffer), pll0)) { + while (fgets(buffer, sizeof(buffer), pll0)) + { if (1 == sscanf(buffer, "SH4 = %d MHZ", &freq)) break; } @@ -84,14 +87,16 @@ unsigned long cCpuFreqManager::GetCpuFreq(void) bool cCpuFreqManager::SetCpuFreq(unsigned long f) { - hal_info("%s(%lu) => set standby = %s\n", __func__, f, f?"true":"false"); + hal_info("%s(%lu) => set standby = %s\n", __func__, f, f ? "true" : "false"); #if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE - if (f) { - FILE *pll0 = fopen ("/proc/cpu_frequ/pll0_ndiv_mdiv", "w"); - if (pll0) { + if (f) + { + FILE *pll0 = fopen("/proc/cpu_frequ/pll0_ndiv_mdiv", "w"); + if (pll0) + { f /= 1000000; - fprintf(pll0, "%lu\n", (f/10 << 8) | 3); - fclose (pll0); + fprintf(pll0, "%lu\n", (f / 10 << 8) | 3); + fclose(pll0); return false; } } diff --git a/common/version_hal.cpp b/common/version_hal.cpp index d1a5729..822658a 100644 --- a/common/version_hal.cpp +++ b/common/version_hal.cpp @@ -25,7 +25,7 @@ void hal_get_lib_version(hal_libversion_t *ver) return; //init struct - *ver = {"",0,0,0,"","",""}; + *ver = {"", 0, 0, 0, "", "", ""}; #ifdef VERSION ver->vVersion = VERSION; diff --git a/include/ca.h b/include/ca.h index 02c3947..36505ee 100644 --- a/include/ca.h +++ b/include/ca.h @@ -5,49 +5,53 @@ #include "cs_types.h" #include #include -typedef std::vector CaIdVector; -typedef std::vector::iterator CaIdVectorIterator; -typedef std::vector::const_iterator CaIdVectorConstIterator; +typedef std::vector CaIdVector; +typedef std::vector::iterator CaIdVectorIterator; +typedef std::vector::const_iterator CaIdVectorConstIterator; -enum CA_INIT_MASK { +enum CA_INIT_MASK +{ CA_INIT_SC = 1, CA_INIT_CI, CA_INIT_BOTH }; -enum CA_SLOT_TYPE { +enum CA_SLOT_TYPE +{ CA_SLOT_TYPE_SMARTCARD, CA_SLOT_TYPE_CI, CA_SLOT_TYPE_ALL }; -enum CA_MESSAGE_FLAGS { - CA_MESSAGE_EMPTY = (1 << 0), - CA_MESSAGE_HAS_PARAM1_DATA = (1 << 1), // Free after use! - CA_MESSAGE_HAS_PARAM1_INT = (1 << 2), - CA_MESSAGE_HAS_PARAM1_PTR = (1 << 3), - CA_MESSAGE_HAS_PARAM2_INT = (1 << 4), - CA_MESSAGE_HAS_PARAM2_PTR = (1 << 5), - CA_MESSAGE_HAS_PARAM2_DATA = (1 << 6), - CA_MESSAGE_HAS_PARAM3_DATA = (1 << 7), // Free after use! - CA_MESSAGE_HAS_PARAM3_INT = (1 << 8), - CA_MESSAGE_HAS_PARAM3_PTR = (1 << 9), - CA_MESSAGE_HAS_PARAM4_INT = (1 << 10), - CA_MESSAGE_HAS_PARAM4_PTR = (1 << 11), - CA_MESSAGE_HAS_PARAM4_DATA = (1 << 12), - CA_MESSAGE_HAS_PARAM5_INT = (1 << 13), - CA_MESSAGE_HAS_PARAM5_PTR = (1 << 14), - CA_MESSAGE_HAS_PARAM5_DATA = (1 << 15), - CA_MESSAGE_HAS_PARAM6_INT = (1 << 16), - CA_MESSAGE_HAS_PARAM6_PTR = (1 << 17), - CA_MESSAGE_HAS_PARAM6_DATA = (1 << 18), - CA_MESSAGE_HAS_PARAM1_LONG = (1 << 19), - CA_MESSAGE_HAS_PARAM2_LONG = (1 << 20), - CA_MESSAGE_HAS_PARAM3_LONG = (1 << 21), - CA_MESSAGE_HAS_PARAM4_LONG = (1 << 22) +enum CA_MESSAGE_FLAGS +{ + CA_MESSAGE_EMPTY = (1 << 0), + CA_MESSAGE_HAS_PARAM1_DATA = (1 << 1), // Free after use! + CA_MESSAGE_HAS_PARAM1_INT = (1 << 2), + CA_MESSAGE_HAS_PARAM1_PTR = (1 << 3), + CA_MESSAGE_HAS_PARAM2_INT = (1 << 4), + CA_MESSAGE_HAS_PARAM2_PTR = (1 << 5), + CA_MESSAGE_HAS_PARAM2_DATA = (1 << 6), + CA_MESSAGE_HAS_PARAM3_DATA = (1 << 7), // Free after use! + CA_MESSAGE_HAS_PARAM3_INT = (1 << 8), + CA_MESSAGE_HAS_PARAM3_PTR = (1 << 9), + CA_MESSAGE_HAS_PARAM4_INT = (1 << 10), + CA_MESSAGE_HAS_PARAM4_PTR = (1 << 11), + CA_MESSAGE_HAS_PARAM4_DATA = (1 << 12), + CA_MESSAGE_HAS_PARAM5_INT = (1 << 13), + CA_MESSAGE_HAS_PARAM5_PTR = (1 << 14), + CA_MESSAGE_HAS_PARAM5_DATA = (1 << 15), + CA_MESSAGE_HAS_PARAM6_INT = (1 << 16), + CA_MESSAGE_HAS_PARAM6_PTR = (1 << 17), + CA_MESSAGE_HAS_PARAM6_DATA = (1 << 18), + CA_MESSAGE_HAS_PARAM1_LONG = (1 << 19), + CA_MESSAGE_HAS_PARAM2_LONG = (1 << 20), + CA_MESSAGE_HAS_PARAM3_LONG = (1 << 21), + CA_MESSAGE_HAS_PARAM4_LONG = (1 << 22) }; -enum CA_MESSAGE_MSGID { +enum CA_MESSAGE_MSGID +{ CA_MESSAGE_MSG_INSERTED, CA_MESSAGE_MSG_REMOVED, CA_MESSAGE_MSG_INIT_OK, @@ -73,12 +77,14 @@ enum CA_MESSAGE_MSGID { typedef std::set ca_map_t; typedef ca_map_t::iterator ca_map_iterator_t; -typedef struct CA_MESSAGE { +typedef struct CA_MESSAGE +{ uint32_t MsgId; enum CA_SLOT_TYPE SlotType; int Slot; uint32_t Flags; - union { + union + { uint8_t *Data[4]; uint32_t Param[4]; void *Ptr[4]; @@ -86,34 +92,50 @@ typedef struct CA_MESSAGE { } Msg; } CA_MESSAGE; -class cCA { -private: - cCA(void); -public: - uint32_t GetNumberCISlots(void); - uint32_t GetNumberSmartCardSlots(void); - static cCA *GetInstance(void); - bool SendPMT(int Unit, unsigned char *Data, int Len, CA_SLOT_TYPE SlotType = CA_SLOT_TYPE_ALL); +class cCA +{ + private: + cCA(void); + public: + uint32_t GetNumberCISlots(void); + uint32_t GetNumberSmartCardSlots(void); + static cCA *GetInstance(void); + bool SendPMT(int Unit, unsigned char *Data, int Len, CA_SLOT_TYPE SlotType = CA_SLOT_TYPE_ALL); // bool SendCAPMT(u64 /*Source*/, u8 /*DemuxSource*/, u8 /*DemuxMask*/, const unsigned char * /*CAPMT*/, u32 /*CAPMTLen*/, const unsigned char * /*RawPMT*/, u32 /*RawPMTLen*/) { return true; }; - bool SendCAPMT(u64 /*Source*/, u8 /*DemuxSource*/, u8 /*DemuxMask*/, const unsigned char * /*CAPMT*/, u32 /*CAPMTLen*/, const unsigned char * /*RawPMT*/, u32 /*RawPMTLen*/, enum CA_SLOT_TYPE - /*SlotType*/, unsigned char /*scrambled = 0*/, ca_map_t /*camap = std::set()*/, int /*mode = 0*/, bool /*enabled = false*/) { return true; }; - bool SendMessage(const CA_MESSAGE *Msg); - void SetInitMask(enum CA_INIT_MASK InitMask); - int GetCAIDS(CaIdVector & /*Caids*/) { return 0; }; - bool Start(void); - void Stop(void); - void Ready(bool Set); - void ModuleReset(enum CA_SLOT_TYPE, uint32_t Slot); - bool ModulePresent(enum CA_SLOT_TYPE, uint32_t Slot); - void ModuleName(enum CA_SLOT_TYPE, uint32_t Slot, char *Name); - void MenuEnter(enum CA_SLOT_TYPE, uint32_t Slot); - void MenuAnswer(enum CA_SLOT_TYPE, uint32_t Slot, uint32_t choice); - void InputAnswer(enum CA_SLOT_TYPE, uint32_t Slot, uint8_t * Data, int Len); - void MenuClose(enum CA_SLOT_TYPE, uint32_t Slot); - void SetTSClock(u32 /*Speed*/, int /*slot*/) { return; }; - bool checkChannelID(u64 /*chanID*/) { return false; }; - void setCheckLiveSlot(int /*check*/) { return; }; - virtual ~cCA(); + bool SendCAPMT(u64 /*Source*/, u8 /*DemuxSource*/, u8 /*DemuxMask*/, const unsigned char * /*CAPMT*/, u32 /*CAPMTLen*/, const unsigned char * /*RawPMT*/, u32 /*RawPMTLen*/, enum CA_SLOT_TYPE + /*SlotType*/, unsigned char /*scrambled = 0*/, ca_map_t /*camap = std::set()*/, int /*mode = 0*/, bool /*enabled = false*/) + { + return true; + }; + bool SendMessage(const CA_MESSAGE *Msg); + void SetInitMask(enum CA_INIT_MASK InitMask); + int GetCAIDS(CaIdVector & /*Caids*/) + { + return 0; + }; + bool Start(void); + void Stop(void); + void Ready(bool Set); + void ModuleReset(enum CA_SLOT_TYPE, uint32_t Slot); + bool ModulePresent(enum CA_SLOT_TYPE, uint32_t Slot); + void ModuleName(enum CA_SLOT_TYPE, uint32_t Slot, char *Name); + void MenuEnter(enum CA_SLOT_TYPE, uint32_t Slot); + void MenuAnswer(enum CA_SLOT_TYPE, uint32_t Slot, uint32_t choice); + void InputAnswer(enum CA_SLOT_TYPE, uint32_t Slot, uint8_t *Data, int Len); + void MenuClose(enum CA_SLOT_TYPE, uint32_t Slot); + void SetTSClock(u32 /*Speed*/, int /*slot*/) + { + return; + }; + bool checkChannelID(u64 /*chanID*/) + { + return false; + }; + void setCheckLiveSlot(int /*check*/) + { + return; + }; + virtual ~cCA(); }; #endif // __CA_H__ diff --git a/include/ca_ci.h b/include/ca_ci.h index 1011f60..88de516 100644 --- a/include/ca_ci.h +++ b/include/ca_ci.h @@ -15,60 +15,64 @@ #include "cs_api.h" /* constants taken from dvb-apps */ -#define T_SB 0x80 // sb primitive h<--m -#define T_RCV 0x81 // receive primitive h-->m -#define T_CREATE_T_C 0x82 // create transport connection primitive h-->m -#define T_C_T_C_REPLY 0x83 // ctc reply primitive h<--m -#define T_DELETE_T_C 0x84 // delete tc primitive h<->m -#define T_D_T_C_REPLY 0x85 // dtc reply primitive h<->m -#define T_REQUEST_T_C 0x86 // request transport connection primitive h<--m -#define T_NEW_T_C 0x87 // new tc / reply to t_request primitive h-->m -#define T_T_C_ERROR 0x77 // error creating tc primitive h-->m -#define T_DATA_LAST 0xA0 // convey data from higher constructed h<->m -#define T_DATA_MORE 0xA1 // convey data from higher constructed h<->m +#define T_SB 0x80 // sb primitive h<--m +#define T_RCV 0x81 // receive primitive h-->m +#define T_CREATE_T_C 0x82 // create transport connection primitive h-->m +#define T_C_T_C_REPLY 0x83 // ctc reply primitive h<--m +#define T_DELETE_T_C 0x84 // delete tc primitive h<->m +#define T_D_T_C_REPLY 0x85 // dtc reply primitive h<->m +#define T_REQUEST_T_C 0x86 // request transport connection primitive h<--m +#define T_NEW_T_C 0x87 // new tc / reply to t_request primitive h-->m +#define T_T_C_ERROR 0x77 // error creating tc primitive h-->m +#define T_DATA_LAST 0xA0 // convey data from higher constructed h<->m +#define T_DATA_MORE 0xA1 // convey data from higher constructed h<->m /* max multi decrypt per ci-cam */ -#define CI_MAX_MULTI 5 +#define CI_MAX_MULTI 5 -enum CA_INIT_MASK { +enum CA_INIT_MASK +{ CA_INIT_SC = 1, CA_INIT_CI, CA_INIT_BOTH }; -enum CA_SLOT_TYPE { +enum CA_SLOT_TYPE +{ CA_SLOT_TYPE_SMARTCARD, CA_SLOT_TYPE_CI, CA_SLOT_TYPE_ALL }; -enum CA_MESSAGE_FLAGS { - CA_MESSAGE_EMPTY = (1 << 0), - CA_MESSAGE_HAS_PARAM1_DATA = (1 << 1), /// Free after use! - CA_MESSAGE_HAS_PARAM1_INT = (1 << 2), - CA_MESSAGE_HAS_PARAM1_PTR = (1 << 3), - CA_MESSAGE_HAS_PARAM2_INT = (1 << 4), - CA_MESSAGE_HAS_PARAM2_PTR = (1 << 5), - CA_MESSAGE_HAS_PARAM2_DATA = (1 << 6), - CA_MESSAGE_HAS_PARAM3_DATA = (1 << 7), /// Free after use! - CA_MESSAGE_HAS_PARAM3_INT = (1 << 8), - CA_MESSAGE_HAS_PARAM3_PTR = (1 << 9), - CA_MESSAGE_HAS_PARAM4_INT = (1 << 10), - CA_MESSAGE_HAS_PARAM4_PTR = (1 << 11), - CA_MESSAGE_HAS_PARAM4_DATA = (1 << 12), - CA_MESSAGE_HAS_PARAM5_INT = (1 << 13), - CA_MESSAGE_HAS_PARAM5_PTR = (1 << 14), - CA_MESSAGE_HAS_PARAM5_DATA = (1 << 15), - CA_MESSAGE_HAS_PARAM6_INT = (1 << 16), - CA_MESSAGE_HAS_PARAM6_PTR = (1 << 17), - CA_MESSAGE_HAS_PARAM6_DATA = (1 << 18), - CA_MESSAGE_HAS_PARAM1_LONG = (1 << 19), - CA_MESSAGE_HAS_PARAM2_LONG = (1 << 20), - CA_MESSAGE_HAS_PARAM3_LONG = (1 << 21), - CA_MESSAGE_HAS_PARAM4_LONG = (1 << 22) +enum CA_MESSAGE_FLAGS +{ + CA_MESSAGE_EMPTY = (1 << 0), + CA_MESSAGE_HAS_PARAM1_DATA = (1 << 1), /// Free after use! + CA_MESSAGE_HAS_PARAM1_INT = (1 << 2), + CA_MESSAGE_HAS_PARAM1_PTR = (1 << 3), + CA_MESSAGE_HAS_PARAM2_INT = (1 << 4), + CA_MESSAGE_HAS_PARAM2_PTR = (1 << 5), + CA_MESSAGE_HAS_PARAM2_DATA = (1 << 6), + CA_MESSAGE_HAS_PARAM3_DATA = (1 << 7), /// Free after use! + CA_MESSAGE_HAS_PARAM3_INT = (1 << 8), + CA_MESSAGE_HAS_PARAM3_PTR = (1 << 9), + CA_MESSAGE_HAS_PARAM4_INT = (1 << 10), + CA_MESSAGE_HAS_PARAM4_PTR = (1 << 11), + CA_MESSAGE_HAS_PARAM4_DATA = (1 << 12), + CA_MESSAGE_HAS_PARAM5_INT = (1 << 13), + CA_MESSAGE_HAS_PARAM5_PTR = (1 << 14), + CA_MESSAGE_HAS_PARAM5_DATA = (1 << 15), + CA_MESSAGE_HAS_PARAM6_INT = (1 << 16), + CA_MESSAGE_HAS_PARAM6_PTR = (1 << 17), + CA_MESSAGE_HAS_PARAM6_DATA = (1 << 18), + CA_MESSAGE_HAS_PARAM1_LONG = (1 << 19), + CA_MESSAGE_HAS_PARAM2_LONG = (1 << 20), + CA_MESSAGE_HAS_PARAM3_LONG = (1 << 21), + CA_MESSAGE_HAS_PARAM4_LONG = (1 << 22) }; -enum CA_MESSAGE_MSGID { +enum CA_MESSAGE_MSGID +{ CA_MESSAGE_MSG_INSERTED, CA_MESSAGE_MSG_REMOVED, CA_MESSAGE_MSG_INIT_OK, @@ -91,12 +95,14 @@ enum CA_MESSAGE_MSGID { CA_MESSAGE_MSG_EXIT }; -typedef struct CA_MESSAGE { +typedef struct CA_MESSAGE +{ uint32_t MsgId; enum CA_SLOT_TYPE SlotType; int Slot; uint32_t Flags; - union { + union + { uint8_t *Data[4]; uint32_t Param[4]; void *Ptr[4]; @@ -107,22 +113,23 @@ typedef struct CA_MESSAGE { typedef std::set ca_map_t; typedef ca_map_t::iterator ca_map_iterator_t; -typedef std::vector bSIDVector; +typedef std::vector bSIDVector; -typedef std::vector CaIdVector; -typedef std::vector::iterator CaIdVectorIterator; -typedef std::vector::const_iterator CaIdVectorConstIterator; +typedef std::vector CaIdVector; +typedef std::vector::iterator CaIdVectorIterator; +typedef std::vector::const_iterator CaIdVectorConstIterator; -#define CA_MESSAGE_SIZE sizeof(CA_MESSAGE) -#define CA_MESSAGE_ENTRIES 256 -#define CA_MESSAGE_ENTRIES_CI 128 -#define CA_MESSAGE_ENTRIES_SC 64 +#define CA_MESSAGE_SIZE sizeof(CA_MESSAGE) +#define CA_MESSAGE_ENTRIES 256 +#define CA_MESSAGE_ENTRIES_CI 128 +#define CA_MESSAGE_ENTRIES_SC 64 #ifndef CS_CA_PDATA -#define CS_CA_PDATA void +#define CS_CA_PDATA void #endif -typedef enum { +typedef enum +{ TUNER_A, TUNER_B, TUNER_C, @@ -153,7 +160,8 @@ typedef enum { #endif } source_t; -typedef enum { +typedef enum +{ eDataTimeout, eDataError, eDataReady, @@ -161,7 +169,8 @@ typedef enum { eDataStatusChanged } eData; -typedef enum { +typedef enum +{ eStatusNone, eStatusWait, eStatusReset @@ -173,11 +182,11 @@ struct queueData unsigned char *data; unsigned int len; queueData(unsigned char *_data, unsigned int _len, __u8 _prio = 0) - :prio(_prio), data(_data), len(_len) + : prio(_prio), data(_data), len(_len) { } - bool operator < ( const struct queueData &a ) const + bool operator < (const struct queueData &a) const { return prio < a.prio; } @@ -197,17 +206,17 @@ typedef struct eStatus status; int receivedLen; - unsigned char* receivedData; + unsigned char *receivedData; - void* pClass; + void *pClass; bool pollConnection; bool camIsReady; - eDVBCIMMISession* mmiSession; - eDVBCIApplicationManagerSession* appSession; - eDVBCICAManagerSession* camgrSession; - eDVBCIContentControlManagerSession* ccmgrSession; + eDVBCIMMISession *mmiSession; + eDVBCIApplicationManagerSession *appSession; + eDVBCICAManagerSession *camgrSession; + eDVBCIContentControlManagerSession *ccmgrSession; bool hasAppManager; bool hasMMIManager; @@ -253,131 +262,132 @@ typedef struct } eDVBCISlot; -eData sendData(eDVBCISlot *slot, unsigned char* data, int len); +eData sendData(eDVBCISlot *slot, unsigned char *data, int len); -typedef std::list::iterator SlotIt; +typedef std::list::iterator SlotIt; /// CA module class -class cCA { -private: - /// Static instance of the CA module +class cCA +{ + private: + /// Static instance of the CA module // static cCA *inst; - /// Private constructor (singleton method) - cCA(void); - /// Private data for the CA module - CS_CA_PDATA *privateData; - /// set inputs with tuner letter in tsmux - void setInputs(); - /// write ci info file to /tmp - void write_ci_info(int slot, CaIdVector caids); - /// delete ci info file - void del_ci_info(int slot); - /// extract audio / video pids from capmt - void extractPids(eDVBCISlot* slot); - /// ci module is detected - void ci_inserted(eDVBCISlot* slot); - /// ci module is removed - void ci_removed(eDVBCISlot* slot); - /// decode the tpdu tag - void process_tpdu(eDVBCISlot* slot, unsigned char tpdu_tag, __u8* data, int asn_data_length, int con_id); - /// set flag of running ci record to false - bool StopRecordCI( u64 TP, u16 SID, u8 source, u32 calen); - /// set flag of running ci live-tv to false - bool StopLiveCI( u64 TP, u16 SID, u8 source, u32 calen); - /// find an unused ci slot for use with service - SlotIt FindFreeSlot(u64 tpid, u8 source, u16 sid, ca_map_t camap, u8 scrambled); - /// get slot iterator by slot number - SlotIt GetSlot(unsigned int slot); - /// send buffered capmt to ci modul - bool SendCaPMT(eDVBCISlot* slot); - /// send a dummy capmt to ci for deactivating - bool SendNullPMT(eDVBCISlot* slot); - /// set ci source - void setSource(eDVBCISlot* slot); - /// set demux source - void setInputSource(eDVBCISlot* slot, bool ci); - /// check if data in queue - bool checkQueueSize(eDVBCISlot* slot); - enum CA_INIT_MASK initMask; - int num_slots; - bool init; - void SendPMT(); - pthread_mutex_t ciMutex; - std::list slot_data; - pthread_t slot_thread; + /// Private constructor (singleton method) + cCA(void); + /// Private data for the CA module + CS_CA_PDATA *privateData; + /// set inputs with tuner letter in tsmux + void setInputs(); + /// write ci info file to /tmp + void write_ci_info(int slot, CaIdVector caids); + /// delete ci info file + void del_ci_info(int slot); + /// extract audio / video pids from capmt + void extractPids(eDVBCISlot *slot); + /// ci module is detected + void ci_inserted(eDVBCISlot *slot); + /// ci module is removed + void ci_removed(eDVBCISlot *slot); + /// decode the tpdu tag + void process_tpdu(eDVBCISlot *slot, unsigned char tpdu_tag, __u8 *data, int asn_data_length, int con_id); + /// set flag of running ci record to false + bool StopRecordCI(u64 TP, u16 SID, u8 source, u32 calen); + /// set flag of running ci live-tv to false + bool StopLiveCI(u64 TP, u16 SID, u8 source, u32 calen); + /// find an unused ci slot for use with service + SlotIt FindFreeSlot(u64 tpid, u8 source, u16 sid, ca_map_t camap, u8 scrambled); + /// get slot iterator by slot number + SlotIt GetSlot(unsigned int slot); + /// send buffered capmt to ci modul + bool SendCaPMT(eDVBCISlot *slot); + /// send a dummy capmt to ci for deactivating + bool SendNullPMT(eDVBCISlot *slot); + /// set ci source + void setSource(eDVBCISlot *slot); + /// set demux source + void setInputSource(eDVBCISlot *slot, bool ci); + /// check if data in queue + bool checkQueueSize(eDVBCISlot *slot); + enum CA_INIT_MASK initMask; + int num_slots; + bool init; + void SendPMT(); + pthread_mutex_t ciMutex; + std::list slot_data; + pthread_t slot_thread; -public: - /// sh4 unused - bool Init(void); - /// init ci and start the loop - cCA(int Slots); - /// Returns the number of CI slots - uint32_t GetNumberCISlots(void); - /// Returns the number of Smartcard slots - uint32_t GetNumberSmartCardSlots(void); - /// Singleton - static cCA *GetInstance(void); - /// Send PMT to a individual or to all available modules (DEPRECATED) - bool SendPMT(int Unit, unsigned char *Data, int Len, enum CA_SLOT_TYPE SlotType = CA_SLOT_TYPE_ALL); - /// Sends a message to the CA thread - bool SendMessage(const CA_MESSAGE *Msg); - /// Sets which modules to initialize. It is only - /// possible to change this once! - /// sh4 unused - void SetInitMask(enum CA_INIT_MASK InitMask); - /// Sets the frequency (in Hz) of the TS stream input (only valid for CI) - /// sh4 unused - void SetTSClock(u32 Speed, int slot = 0); + public: + /// sh4 unused + bool Init(void); + /// init ci and start the loop + cCA(int Slots); + /// Returns the number of CI slots + uint32_t GetNumberCISlots(void); + /// Returns the number of Smartcard slots + uint32_t GetNumberSmartCardSlots(void); + /// Singleton + static cCA *GetInstance(void); + /// Send PMT to a individual or to all available modules (DEPRECATED) + bool SendPMT(int Unit, unsigned char *Data, int Len, enum CA_SLOT_TYPE SlotType = CA_SLOT_TYPE_ALL); + /// Sends a message to the CA thread + bool SendMessage(const CA_MESSAGE *Msg); + /// Sets which modules to initialize. It is only + /// possible to change this once! + /// sh4 unused + void SetInitMask(enum CA_INIT_MASK InitMask); + /// Sets the frequency (in Hz) of the TS stream input (only valid for CI) + /// sh4 unused + void SetTSClock(u32 Speed, int slot = 0); #if BOXMODEL_VUPLUS_ALL - /// dvb wait delay for ci response - void SetCIDelay(int Delay); - /// relevant pids routing - void SetCIRelevantPidsRouting(int RPR, int slot = 0); + /// dvb wait delay for ci response + void SetCIDelay(int Delay); + /// relevant pids routing + void SetCIRelevantPidsRouting(int RPR, int slot = 0); #endif - /// Start the CA module - /// sh4 unused - bool Start(void); - /// Stops the CA module - /// sh4 unused - void Stop(void); - /// Notify that the GUI is ready to receive messages - /// (CA messages coming from a module) - /// sh4 unused - void Ready(bool Set); - /// Resets a module (if possible) - /// sh4 unused - void ModuleReset(enum CA_SLOT_TYPE, uint32_t Slot); - /// Checks if a module is present - bool ModulePresent(enum CA_SLOT_TYPE, uint32_t Slot); - /// Returns the module name in array Name - void ModuleName(enum CA_SLOT_TYPE, uint32_t Slot, char *Name); - /// Notify the module we want to enter menu - void MenuEnter(enum CA_SLOT_TYPE, uint32_t Slot); - /// Notify the module with our answer (choice nr) - void MenuAnswer(enum CA_SLOT_TYPE, uint32_t Slot, uint32_t choice); - /// Notify the module with our answer (binary) - void InputAnswer(enum CA_SLOT_TYPE, uint32_t Slot, uint8_t * Data, int Len); - /// Notify the module we closed the menu - void MenuClose(enum CA_SLOT_TYPE, uint32_t Slot); - /// Get the supported CAIDs - int GetCAIDS(CaIdVector &Caids); - /// Send a CA-PMT object and Raw unparsed PMT to the CA layer - bool SendCAPMT(u64 /*Source*/, u8 /*DemuxSource*/, u8 /*DemuxMask*/, const unsigned char * /*CAPMT*/, u32 /*CAPMTLen*/, const unsigned char * /*RawPMT*/, u32 /*RawPMTLen*/, enum CA_SLOT_TYPE SlotType = CA_SLOT_TYPE_ALL, - unsigned char scrambled = 0, ca_map_t camap = std::set(), int mode = 0, bool enabled = false); - /// sh4 unused - bool SendDateTime(void); - /// the main loop - void slot_pollthread(void *c); - /// check if current channel uses any ci module - bool checkChannelID(u64 chanID); - /// set checking for live-tv use ci to true - void setCheckLiveSlot(int check); - /// as the name says - bool CheckCerts(void); - /// Virtual destructor - virtual ~cCA(); + /// Start the CA module + /// sh4 unused + bool Start(void); + /// Stops the CA module + /// sh4 unused + void Stop(void); + /// Notify that the GUI is ready to receive messages + /// (CA messages coming from a module) + /// sh4 unused + void Ready(bool Set); + /// Resets a module (if possible) + /// sh4 unused + void ModuleReset(enum CA_SLOT_TYPE, uint32_t Slot); + /// Checks if a module is present + bool ModulePresent(enum CA_SLOT_TYPE, uint32_t Slot); + /// Returns the module name in array Name + void ModuleName(enum CA_SLOT_TYPE, uint32_t Slot, char *Name); + /// Notify the module we want to enter menu + void MenuEnter(enum CA_SLOT_TYPE, uint32_t Slot); + /// Notify the module with our answer (choice nr) + void MenuAnswer(enum CA_SLOT_TYPE, uint32_t Slot, uint32_t choice); + /// Notify the module with our answer (binary) + void InputAnswer(enum CA_SLOT_TYPE, uint32_t Slot, uint8_t *Data, int Len); + /// Notify the module we closed the menu + void MenuClose(enum CA_SLOT_TYPE, uint32_t Slot); + /// Get the supported CAIDs + int GetCAIDS(CaIdVector &Caids); + /// Send a CA-PMT object and Raw unparsed PMT to the CA layer + bool SendCAPMT(u64 /*Source*/, u8 /*DemuxSource*/, u8 /*DemuxMask*/, const unsigned char * /*CAPMT*/, u32 /*CAPMTLen*/, const unsigned char * /*RawPMT*/, u32 /*RawPMTLen*/, enum CA_SLOT_TYPE SlotType = CA_SLOT_TYPE_ALL, + unsigned char scrambled = 0, ca_map_t camap = std::set(), int mode = 0, bool enabled = false); + /// sh4 unused + bool SendDateTime(void); + /// the main loop + void slot_pollthread(void *c); + /// check if current channel uses any ci module + bool checkChannelID(u64 chanID); + /// set checking for live-tv use ci to true + void setCheckLiveSlot(int check); + /// as the name says + bool CheckCerts(void); + /// Virtual destructor + virtual ~cCA(); }; #endif // __CA_CI_H__ diff --git a/include/cs_api.h b/include/cs_api.h index 38134f6..1336743 100644 --- a/include/cs_api.h +++ b/include/cs_api.h @@ -7,7 +7,7 @@ #include "init.h" #include -typedef void (*cs_messenger) (unsigned int msg, unsigned int data); +typedef void (*cs_messenger)(unsigned int msg, unsigned int data); inline void cs_api_init() { @@ -19,8 +19,8 @@ inline void cs_api_exit() hal_api_exit(); }; -#define cs_malloc_uncached malloc -#define cs_free_uncached free +#define cs_malloc_uncached malloc +#define cs_free_uncached free // Callback function helpers #if HAVE_DUCKBOX_HARDWARE \ @@ -32,13 +32,25 @@ inline void cs_api_exit() ) void cs_register_messenger(cs_messenger messenger); #else -static inline void cs_register_messenger(cs_messenger) { return; }; +static inline void cs_register_messenger(cs_messenger) +{ + return; +}; #endif -static inline void cs_deregister_messenger(void) { return; }; +static inline void cs_deregister_messenger(void) +{ + return; +}; /* compat... HD1 seems to be version 6. everything newer ist > 6... */ -static inline unsigned int cs_get_revision(void) { return 1; }; -static inline unsigned int cs_get_chip_type(void) { return 0; }; +static inline unsigned int cs_get_revision(void) +{ + return 1; +}; +static inline unsigned int cs_get_chip_type(void) +{ + return 0; +}; extern int cnxt_debug; #endif // __CS_API_H__ diff --git a/include/cs_frontpanel.h b/include/cs_frontpanel.h index f5fee15..df3cfd1 100644 --- a/include/cs_frontpanel.h +++ b/include/cs_frontpanel.h @@ -26,7 +26,8 @@ #define VFDSETTIMEMODE 0xc0425b03 #define VFDDISPLAYCLR 0xc0425b00 -typedef enum { +typedef enum +{ #if defined(BOXMODEL_OCTAGON1008) ICON_DOLBY = 0x10, ICON_DTS, @@ -248,42 +249,47 @@ typedef enum { #endif } fp_icon; -typedef enum { - FP_FLAG_NONE = 0x00, - FP_FLAG_SCROLL_ON = 0x01, /* switch scrolling on */ - FP_FLAG_SCROLL_LTR = 0x02, /* scroll from left to rightinstead of default right to left direction (i.e. for arabic text) */ - FP_FLAG_SCROLL_SIO = 0x04, /* start/stop scrolling with empty screen (scroll in/out) */ - FP_FLAG_SCROLL_DELAY = 0x08, /* delayed scroll start */ - FP_FLAG_ALIGN_LEFT = 0x10, /* align the text in display from the left (default) */ - FP_FLAG_ALIGN_RIGHT = 0x20, /* align the text in display from the right (arabic) */ - FP_FLAG_UPDATE_SCROLL_POS = 0x40, /* update the current position for scrolling */ +typedef enum +{ + FP_FLAG_NONE = 0x00, + FP_FLAG_SCROLL_ON = 0x01, /* switch scrolling on */ + FP_FLAG_SCROLL_LTR = 0x02, /* scroll from left to rightinstead of default right to left direction (i.e. for arabic text) */ + FP_FLAG_SCROLL_SIO = 0x04, /* start/stop scrolling with empty screen (scroll in/out) */ + FP_FLAG_SCROLL_DELAY = 0x08, /* delayed scroll start */ + FP_FLAG_ALIGN_LEFT = 0x10, /* align the text in display from the left (default) */ + FP_FLAG_ALIGN_RIGHT = 0x20, /* align the text in display from the right (arabic) */ + FP_FLAG_UPDATE_SCROLL_POS = 0x40, /* update the current position for scrolling */ } fp_flag; -typedef struct { - unsigned char brightness; - unsigned char flags; - unsigned char current_hour; - unsigned char current_minute; - unsigned char timer_minutes_hi; - unsigned char timer_minutes_lo; +typedef struct +{ + unsigned char brightness; + unsigned char flags; + unsigned char current_hour; + unsigned char current_minute; + unsigned char timer_minutes_hi; + unsigned char timer_minutes_lo; } fp_standby_data_t; -typedef enum { - FP_LED_1_ON = 0x81, - FP_LED_2_ON = 0x82, - FP_LED_3_ON = 0x83, - FP_LED_1_OFF = 0x01, - FP_LED_2_OFF = 0x02, - FP_LED_3_OFF = 0x03 +typedef enum +{ + FP_LED_1_ON = 0x81, + FP_LED_2_ON = 0x82, + FP_LED_3_ON = 0x83, + FP_LED_1_OFF = 0x01, + FP_LED_2_OFF = 0x02, + FP_LED_3_OFF = 0x03 } fp_led_ctrl_t; -typedef struct { - unsigned char source; - unsigned char time_minutes_hi; - unsigned char time_minutes_lo; +typedef struct +{ + unsigned char source; + unsigned char time_minutes_hi; + unsigned char time_minutes_lo; } fp_wakeup_data_t; -typedef enum { +typedef enum +{ FP_WAKEUP_SOURCE_TIMER = 0x01, FP_WAKEUP_SOURCE_BUTTON = 0x02, FP_WAKEUP_SOURCE_REMOTE = 0x04, @@ -291,30 +297,34 @@ typedef enum { FP_WAKEUP_SOURCE_POWER = 0xFF } fp_wakeup_source; -typedef struct { - unsigned short addr; - unsigned short cmd; +typedef struct +{ + unsigned short addr; + unsigned short cmd; } fp_standby_cmd_data_t; -typedef enum { - FP_DISPLAY_TEXT_NONE = 0, +typedef enum +{ + FP_DISPLAY_TEXT_NONE = 0, FP_DISPLAY_TEXT_LIMITED, FP_DISPLAY_TEXT_ALL, } fp_display_text_type_t; -typedef enum { - FP_DISPLAY_TYPE_NONE = 0, +typedef enum +{ + FP_DISPLAY_TYPE_NONE = 0, FP_DISPLAY_TYPE_VFD, FP_DISPLAY_TYPE_OLED, FP_DISPLAY_TYPE_LED_SEGMENT } fp_display_type_t; -typedef struct { - fp_display_type_t display_type; - unsigned short xres, yres; - unsigned int segment_count; - fp_display_text_type_t text_support; - bool number_support; +typedef struct +{ + fp_display_type_t display_type; + unsigned short xres, yres; + unsigned int segment_count; + fp_display_text_type_t text_support; + bool number_support; } fp_display_caps_t; #endif // __CS_FRONTPANEL_H__ diff --git a/include/cs_types.h b/include/cs_types.h index 60a50fc..5cf52a6 100644 --- a/include/cs_types.h +++ b/include/cs_types.h @@ -11,13 +11,13 @@ typedef enum AVSYNC_AUDIO_IS_MASTER } AVSYNC_TYPE; -typedef unsigned long long u64; -typedef unsigned int u32; -typedef unsigned short u16; -typedef unsigned char u8; -typedef signed long long s64; -typedef signed int s32; -typedef signed short s16; -typedef signed char s8; +typedef unsigned long long u64; +typedef unsigned int u32; +typedef unsigned short u16; +typedef unsigned char u8; +typedef signed long long s64; +typedef signed int s32; +typedef signed short s16; +typedef signed char s8; #endif // __CS_TYPES_H__ diff --git a/include/dmx_hal.h b/include/dmx_hal.h index 8cf9797..b5476fd 100644 --- a/include/dmx_hal.h +++ b/include/dmx_hal.h @@ -80,30 +80,36 @@ class cRecord; class cPlayback; class cDemux { - friend class cRecord; - friend class cPlayback; + friend class cRecord; + friend class cPlayback; public: - bool Open(DMX_CHANNEL_TYPE pes_type, void * x = NULL, int y = 0); + bool Open(DMX_CHANNEL_TYPE pes_type, void *x = NULL, int y = 0); void Close(void); bool Start(bool record = false); bool Stop(void); int Read(unsigned char *buff, int len, int Timeout = 0); - bool sectionFilter(unsigned short pid, const unsigned char * const filter, const unsigned char * const mask, int len, int Timeout = 0, const unsigned char * const negmask = NULL); + bool sectionFilter(unsigned short pid, const unsigned char *const filter, const unsigned char *const mask, int len, int Timeout = 0, const unsigned char *const negmask = NULL); bool pesFilter(const unsigned short pid); void SetSyncMode(AVSYNC_TYPE mode); - void * getBuffer(); - void * getChannel(); - DMX_CHANNEL_TYPE getChannelType(void) { return dmx_type; }; + void *getBuffer(); + void *getChannel(); + DMX_CHANNEL_TYPE getChannelType(void) + { + return dmx_type; + }; bool addPid(unsigned short pid); - void getSTC(int64_t * STC); + void getSTC(int64_t *STC); int getUnit(void); static bool SetSource(int unit, int source); static int GetSource(int unit); - int getFD(void) { return fd; }; /* needed by cPlayback class */ + int getFD(void) + { + return fd; + }; /* needed by cPlayback class */ cDemux(int num = 0); ~cDemux(); private: - void removePid(unsigned short Pid); /* needed by cRecord class */ + void removePid(unsigned short Pid); /* needed by cRecord class */ int num; int fd; int buffersize; diff --git a/include/glfb.h b/include/glfb.h index f7c51de..1d2259a 100644 --- a/include/glfb.h +++ b/include/glfb.h @@ -1,19 +1,19 @@ /* - Copyright 2010 Carsten Juttner - Copyright 2012,2013 Stefan Seyfried + Copyright 2010 Carsten Juttner + Copyright 2012,2013 Stefan Seyfried - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #ifndef __GLFB_H__ @@ -25,20 +25,26 @@ class GLFramebuffer : public OpenThreads::Thread { -public: - GLFramebuffer(int x, int y); - ~GLFramebuffer(); - std::vector *getOSDBuffer() { return &osd_buf; } /* pointer to OSD bounce buffer */ - void blit(); - fb_var_screeninfo getScreenInfo() { return si; } + public: + GLFramebuffer(int x, int y); + ~GLFramebuffer(); + std::vector *getOSDBuffer() + { + return &osd_buf; /* pointer to OSD bounce buffer */ + } + void blit(); + fb_var_screeninfo getScreenInfo() + { + return si; + } -private: - fb_var_screeninfo si; - std::vector osd_buf; /* silly bounce buffer */ - void run(); /* for OpenThreads::Thread */ - void setup(); - void blit_osd(); - void *pdata; /* not yet used */ + private: + fb_var_screeninfo si; + std::vector osd_buf; /* silly bounce buffer */ + void run(); /* for OpenThreads::Thread */ + void setup(); + void blit_osd(); + void *pdata; /* not yet used */ }; #endif // __GLFB_H__ diff --git a/include/hardware_caps.h b/include/hardware_caps.h index 6fda622..50144db 100644 --- a/include/hardware_caps.h +++ b/include/hardware_caps.h @@ -16,8 +16,8 @@ typedef enum { HW_DISPLAY_NONE, HW_DISPLAY_LED_ONLY, - HW_DISPLAY_LED_NUM, /* simple 7 segment LED display */ - HW_DISPLAY_LINE_TEXT, /* 1 line text display */ + HW_DISPLAY_LED_NUM, /* simple 7 segment LED display */ + HW_DISPLAY_LINE_TEXT, /* 1 line text display */ HW_DISPLAY_GFX } display_type_t; @@ -33,11 +33,11 @@ typedef struct hw_caps int can_cpufreq; int can_shutdown; int can_cec; - int can_ar_14_9; /* video drivers have 14:9 aspect ratio mode */ - int can_ps_14_9; /* video drivers have 14:9 panscan mode */ - int force_tuner_2G; /* force DVB-S2 even though driver may not advertise it */ + int can_ar_14_9; /* video drivers have 14:9 aspect ratio mode */ + int can_ps_14_9; /* video drivers have 14:9 panscan mode */ + int force_tuner_2G; /* force DVB-S2 even though driver may not advertise it */ display_type_t display_type; - int display_xres; /* x resolution or chars per line */ + int display_xres; /* x resolution or chars per line */ int display_yres; int display_can_deepstandby; int display_can_set_brightness; diff --git a/include/mmi.h b/include/mmi.h index 4d0884b..e46c5cf 100644 --- a/include/mmi.h +++ b/include/mmi.h @@ -1,11 +1,12 @@ #ifndef __MMI_H__ #define __MMI_H__ -#define MAX_MMI_ITEMS 40 -#define MAX_MMI_TEXT_LEN 255 -#define MAX_MMI_CHOICE_TEXT_LEN 255 +#define MAX_MMI_ITEMS 40 +#define MAX_MMI_TEXT_LEN 255 +#define MAX_MMI_CHOICE_TEXT_LEN 255 -typedef enum { +typedef enum +{ MMI_TOP_MENU_SUBS = 1, MMI_TOP_MENU_EVENTS, MMI_TOP_MENU_TOKENS, @@ -14,20 +15,23 @@ typedef enum { MMI_TOP_MENU_ABOUT } MMI_MENU_CURRENT; -typedef enum { +typedef enum +{ MMI_MENU_LEVEL_MAIN = 0, MMI_MENU_LEVEL_MATURE, MMI_MENU_LEVEL_ASK_PIN_MATURE } MMI_MENU_LEVEL; -typedef enum { +typedef enum +{ MMI_PIN_LEVEL_ASK_OLD = 0, MMI_PIN_LEVEL_CHECK_CURRENT, MMI_PIN_LEVEL_ASK_REPEAT, MMI_PIN_LEVEL_CHECK_AND_CHANGE } MMI_PIN_LEVEL; -typedef struct { +typedef struct +{ int slot; int choice_nb; char title[MAX_MMI_TEXT_LEN]; @@ -36,7 +40,8 @@ typedef struct { char choice_item[MAX_MMI_ITEMS][MAX_MMI_CHOICE_TEXT_LEN]; } MMI_MENU_LIST_INFO; -typedef struct { +typedef struct +{ int slot; int blind; int answerlen; diff --git a/include/pwrmngr.h b/include/pwrmngr.h index aee6c34..edf5a31 100644 --- a/include/pwrmngr.h +++ b/include/pwrmngr.h @@ -20,28 +20,28 @@ class cCpuFreqManager { -public: - cCpuFreqManager(void); - void Up(void); - void Down(void); - void Reset(void); + public: + cCpuFreqManager(void); + void Up(void); + void Down(void); + void Reset(void); - bool SetCpuFreq(unsigned long CpuFreq); - bool SetDelta(unsigned long Delta); - unsigned long GetCpuFreq(void); - unsigned long GetDelta(void); + bool SetCpuFreq(unsigned long CpuFreq); + bool SetDelta(unsigned long Delta); + unsigned long GetCpuFreq(void); + unsigned long GetDelta(void); }; class cPowerManager { -public: - cPowerManager(void); - virtual ~cPowerManager(); + public: + cPowerManager(void); + virtual ~cPowerManager(); - bool Open(void); - void Close(void); + bool Open(void); + void Close(void); - bool SetStandby(bool Active, bool Passive); + bool SetStandby(bool Active, bool Passive); }; #endif // __PWRMNGR_H__ diff --git a/include/version_hal.h b/include/version_hal.h index 1b17725..d04afcc 100644 --- a/include/version_hal.h +++ b/include/version_hal.h @@ -6,13 +6,13 @@ // library version functions typedef struct hal_libversion_t { - std::string vVersion; - int vMajor; - int vMinor; - int vPatch;; - std::string vName; - std::string vStr; - std::string vGitDescribe; + std::string vVersion; + int vMajor; + int vMinor; + int vPatch;; + std::string vName; + std::string vStr; + std::string vGitDescribe; } hal_libversion_struct_t; void hal_get_lib_version(hal_libversion_t *ver); diff --git a/libarmbox/audio.cpp b/libarmbox/audio.cpp index d289825..f86b0b8 100644 --- a/libarmbox/audio.cpp +++ b/libarmbox/audio.cpp @@ -14,30 +14,31 @@ #include "hal_debug.h" #include -#define AUDIO_DEVICE "/dev/dvb/adapter0/audio0" +#define AUDIO_DEVICE "/dev/dvb/adapter0/audio0" #define hal_debug(args...) _hal_debug(HAL_DEBUG_AUDIO, this, args) #define hal_info(args...) _hal_info(HAL_DEBUG_AUDIO, this, args) -#define fop(cmd, args...) ({ \ - int _r; \ - if (fd >= 0) { \ - if ((_r = ::cmd(fd, args)) < 0) \ - hal_info(#cmd"(fd, "#args")\n");\ - else \ - hal_debug(#cmd"(fd, "#args")\n");\ - } \ - else { _r = fd; } \ - _r; \ -}) +#define fop(cmd, args...) ({ \ + int _r; \ + if (fd >= 0) { \ + if ((_r = ::cmd(fd, args)) < 0) \ + hal_info(#cmd"(fd, "#args")\n");\ + else \ + hal_debug(#cmd"(fd, "#args")\n");\ + } \ + else { _r = fd; } \ + _r; \ + }) #include enum -{ ENCODER, +{ + ENCODER, AUX }; -cAudio * audioDecoder = NULL; +cAudio *audioDecoder = NULL; cAudio::cAudio(void *, void *, void *) { @@ -69,15 +70,18 @@ void cAudio::openDevice(void) void cAudio::closeDevice(void) { - if (fd > -1) { + if (fd > -1) + { close(fd); fd = -1; } - if (clipfd > -1) { + if (clipfd > -1) + { close(clipfd); clipfd = -1; } - if (mixer_fd > -1) { + if (mixer_fd > -1) + { close(mixer_fd); mixer_fd = -1; } @@ -103,7 +107,8 @@ void cAudio::close_AVInput_Device(void) { hal_debug("%s\n", __func__); - if (fdd) { + if (fdd) + { fop(ioctl, AUDIO_STOP); } fdd = false; @@ -113,11 +118,15 @@ void cAudio::setAVInput(int val) { hal_info("%s - switching to: %s\n", __func__, val == AUX ? "AUX" : "ENCODER"); - if (val == AUX) { + if (val == AUX) + { Stop(); open_AVInput_Device(); - } else { - if (fdd) { + } + else + { + if (fdd) + { close_AVInput_Device(); fop(ioctl, AUDIO_SELECT_SOURCE, AUDIO_SOURCE_DEMUX); Start(); @@ -243,7 +252,8 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) const char *dsp_dev = getenv("DSP_DEVICE"); const char *mix_dev = getenv("MIX_DEVICE"); hal_info("cAudio::%s ch %d srate %d bits %d le %d\n", __FUNCTION__, ch, srate, bits, little_endian); - if (clipfd > -1) { + if (clipfd > -1) + { hal_info("%s: clipfd already opened (%d)\n", __func__, clipfd); return -1; } @@ -257,22 +267,25 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) * export MIX_DEVICE=/dev/sound/mixer2 * neutrino */ - if ((!dsp_dev) || (access(dsp_dev, W_OK))) { + if ((!dsp_dev) || (access(dsp_dev, W_OK))) + { if (dsp_dev) hal_info("%s: DSP_DEVICE is set (%s) but cannot be opened," - " fall back to /dev/dsp\n", __func__, dsp_dev); + " fall back to /dev/dsp\n", __func__, dsp_dev); dsp_dev = "/dev/dsp"; } - if ((!mix_dev) || (access(mix_dev, W_OK))) { + if ((!mix_dev) || (access(mix_dev, W_OK))) + { if (mix_dev) hal_info("%s: MIX_DEVICE is set (%s) but cannot be opened," - " fall back to /dev/mixer\n", __func__, dsp_dev); + " fall back to /dev/mixer\n", __func__, dsp_dev); mix_dev = "/dev/mixer"; } hal_info("cAudio::%s: dsp_dev %s mix_dev %s\n", __func__, dsp_dev, mix_dev); /* NULL mix_dev is ok */ /* the tdoss dsp driver seems to work only on the second open(). really. */ clipfd = open(dsp_dev, O_WRONLY); - if (clipfd < 0) { + if (clipfd < 0) + { hal_info("%s open %s: %m\n", dsp_dev, __FUNCTION__); return -1; } @@ -297,42 +310,50 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) return 0; mixer_fd = open(mix_dev, O_RDWR); - if (mixer_fd < 0) { + if (mixer_fd < 0) + { hal_info("%s: open mixer %s failed (%m)\n", __func__, mix_dev); /* not a real error */ return 0; } - if (ioctl(mixer_fd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) { + if (ioctl(mixer_fd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) + { hal_info("%s: SOUND_MIXER_READ_DEVMASK %m\n", __func__); devmask = 0; } - if (ioctl(mixer_fd, SOUND_MIXER_READ_STEREODEVS, &stereo) == -1) { + if (ioctl(mixer_fd, SOUND_MIXER_READ_STEREODEVS, &stereo) == -1) + { hal_info("%s: SOUND_MIXER_READ_STEREODEVS %m\n", __func__); stereo = 0; } usable = devmask & stereo; - if (usable == 0) { + if (usable == 0) + { hal_info("%s: devmask: %08x stereo: %08x, no usable dev :-(\n", - __func__, devmask, stereo); + __func__, devmask, stereo); close(mixer_fd); mixer_fd = -1; return 0; /* TODO: should we treat this as error? */ } /* __builtin_popcount needs GCC, it counts the set bits... */ - if (__builtin_popcount (usable) != 1) { + if (__builtin_popcount(usable) != 1) + { /* TODO: this code is not yet tested as I have only single-mixer devices... */ hal_info("%s: more than one mixer control: devmask %08x stereo %08x\n" - "%s: querying MIX_NUMBER environment variable...\n", - __func__, devmask, stereo, __func__); + "%s: querying MIX_NUMBER environment variable...\n", + __func__, devmask, stereo, __func__); const char *tmp = getenv("MIX_NUMBER"); if (tmp) mixer_num = atoi(tmp); hal_info("%s: mixer_num is %d -> device %08x\n", - __func__, mixer_num, (mixer_num >= 0) ? (1 << mixer_num) : 0); + __func__, mixer_num, (mixer_num >= 0) ? (1 << mixer_num) : 0); /* no error checking, you'd better know what you are doing... */ - } else { + } + else + { mixer_num = 0; - while (!(usable & 0x01)) { + while (!(usable & 0x01)) + { mixer_num++; usable >>= 1; } @@ -344,9 +365,10 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) int cAudio::WriteClip(unsigned char *buffer, int size) { - int ret, __attribute__ ((unused)) count = 1; + int ret, __attribute__((unused)) count = 1; // hal_debug("cAudio::%s\n", __FUNCTION__); - if (clipfd < 0) { + if (clipfd < 0) + { hal_info("%s: clipfd not yet opened\n", __FUNCTION__); return -1; } @@ -354,12 +376,14 @@ int cAudio::WriteClip(unsigned char *buffer, int size) again: #endif ret = write(clipfd, buffer, size); - if (ret < 0) { + if (ret < 0) + { hal_info("%s: write error (%m)\n", __FUNCTION__); return ret; } #if BOXMODEL_HD51 || BOXMODEL_BRE2ZE4K || BOXMODEL_H7 - if (ret != size) { + if (ret != size) + { hal_info("cAudio::%s: difference > to write (%d) != written (%d) try (%d) > reset dsp and restart write\n", __FUNCTION__, size, ret, count); if (ioctl(clipfd, SNDCTL_DSP_RESET)) perror("SNDCTL_DSP_RESET"); @@ -375,7 +399,8 @@ int cAudio::StopClip() { hal_info("cAudio::%s\n", __FUNCTION__); - if (clipfd < 0) { + if (clipfd < 0) + { hal_info("%s: clipfd not yet opened\n", __FUNCTION__); return -1; } @@ -384,7 +409,8 @@ int cAudio::StopClip() #endif close(clipfd); clipfd = -1; - if (mixer_fd > -1) { + if (mixer_fd > -1) + { close(mixer_fd); mixer_fd = -1; } @@ -412,24 +438,24 @@ void cAudio::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &m type = atype; #if 0 -/* this does not work, some of the values are negative?? */ + /* this does not work, some of the values are negative?? */ AMPEGStatus A; memcpy(&A, &i.word00, sizeof(i.word00)); layer = A.audio_mpeg_layer; mode = A.audio_mpeg_mode; bitrate = A.audio_mpeg_bitrate; - switch(A.audio_mpeg_frequency) + switch (A.audio_mpeg_frequency) #endif - /* layer and bitrate are not used anyway... */ - layer = 0; //(i.word00 >> 17) & 3; + /* layer and bitrate are not used anyway... */ + layer = 0; //(i.word00 >> 17) & 3; bitrate = 0; //(i.word00 >> 12) & 3; switch (type) { - case 0: /* MPEG */ + case 0: /* MPEG */ mode = (i.word00 >> 6) & 3; freq = freq_mpg[(i.word00 >> 10) & 3]; break; - case 1: /* AC3 */ + case 1: /* AC3 */ mode = (i.word00 >> 28) & 7; freq = freq_ac3[(i.word00 >> 16) & 3]; break; diff --git a/libarmbox/audio_lib.h b/libarmbox/audio_lib.h index 18f0820..33bc485 100644 --- a/libarmbox/audio_lib.h +++ b/libarmbox/audio_lib.h @@ -12,7 +12,8 @@ typedef enum AUDIO_SYNC_AUDIO_MASTER } AUDIO_SYNC_MODE; -typedef enum { +typedef enum +{ HDMI_ENCODED_OFF, HDMI_ENCODED_AUTO, HDMI_ENCODED_FORCED @@ -22,7 +23,7 @@ class mixerVolume; class cAudio { - friend class cPlayback; + friend class cPlayback; private: int fd; bool fdd; @@ -32,7 +33,7 @@ class cAudio int mixer_fd; /* if we are using the OSS mixer */ int mixer_num; /* oss mixer to use, if any */ - int StreamType; + int StreamType; AUDIO_SYNC_MODE SyncMode; bool started; @@ -54,32 +55,53 @@ class cAudio void setAVInput(int val); - void *GetHandle() { return NULL; }; + void *GetHandle() + { + return NULL; + }; /* shut up */ - int mute(bool remember = true) { return do_mute(true, remember); }; - int unmute(bool remember = true) { return do_mute(false, remember); }; + int mute(bool remember = true) + { + return do_mute(true, remember); + }; + int unmute(bool remember = true) + { + return do_mute(false, remember); + }; /* volume, min = 0, max = 255 */ int setVolume(unsigned int left, unsigned int right); - int getVolume(void) { return volume;} - bool getMuteStatus(void) { return Muted; }; + int getVolume(void) + { + return volume; + } + bool getMuteStatus(void) + { + return Muted; + }; /* start and stop audio */ int Start(void); int Stop(void); bool Pause(bool Pcm = true); void SetStreamType(int bypass); - int GetStreamType(void) { return StreamType; } + int GetStreamType(void) + { + return StreamType; + } void SetSyncMode(AVSYNC_TYPE Mode); /* select channels */ int setChannel(int channel); int PrepareClipPlay(int uNoOfChannels, int uSampleRate, int uBitsPerSample, int bLittleEndian); - int WriteClip(unsigned char * buffer, int size); + int WriteClip(unsigned char *buffer, int size); int StopClip(); - void getAudioInfo(int &type, int &layer, int& freq, int &bitrate, int &mode); + void getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode); void SetSRS(int iq_enable, int nmgr_enable, int iq_mode, int iq_level); - bool IsHdmiDDSupported() { return true; }; + bool IsHdmiDDSupported() + { + return true; + }; void SetHdmiDD(bool enable); void SetSpdifDD(bool enable); void ScheduleMute(bool On); diff --git a/libarmbox/dmx.cpp b/libarmbox/dmx.cpp index 08158b3..a702646 100644 --- a/libarmbox/dmx.cpp +++ b/libarmbox/dmx.cpp @@ -50,15 +50,16 @@ extern cVideo *videoDecoder; #define hal_debug_z(args...) _hal_debug(HAL_DEBUG_DEMUX, thiz, args) #define dmx_err(_errfmt, _errstr, _revents) do { \ - hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ -} while(0); + hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ + __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ + } while(0); cDemux *videoDemux = NULL; cDemux *audioDemux = NULL; //cDemux *pcrDemux = NULL; -static const char *DMX_T[] = { +static const char *DMX_T[] = +{ "DMX_INVALID", "DMX_VIDEO", "DMX_AUDIO", @@ -92,7 +93,8 @@ static int dmx_source[NUM_DEMUX] = { 0, 0, 0, 0 }; #endif char dmxdev[32]; -static char* devname(int adapter, int demux) { +static char *devname(int adapter, int demux) +{ snprintf(dmxdev, sizeof(dmxdev), "/dev/dvb/adapter%d/demux%d", adapter, demux); return dmxdev; } @@ -119,7 +121,8 @@ static bool init[NUM_DEMUXDEV] = { false, false, false, false, false, false, fal #endif #endif -typedef struct dmx_pdata { +typedef struct dmx_pdata +{ int last_source; OpenThreads::Mutex *mutex; } dmx_pdata; @@ -167,17 +170,19 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe static bool _open(cDemux *thiz, int num, int &fd, int &last_source, DMX_CHANNEL_TYPE dmx_type, int buffersize) { - int flags = O_RDWR|O_CLOEXEC; + int flags = O_RDWR | O_CLOEXEC; int devnum = dmx_source[num]; - if (last_source == devnum) { + if (last_source == devnum) + { hal_debug_z("%s #%d: source (%d) did not change\n", __func__, num, last_source); if (fd > -1) return true; } - if (fd > -1) { + if (fd > -1) + { /* we changed source -> close and reopen the fd */ hal_debug_z("%s #%d: FD ALREADY OPENED fd = %d lastsource %d devnum %d\n", - __func__, num, fd, last_source, devnum); + __func__, num, fd, last_source, devnum); close(fd); } @@ -191,7 +196,7 @@ static bool _open(cDemux *thiz, int num, int &fd, int &last_source, DMX_CHANNEL_ return false; } hal_debug_z("%s #%d pes_type: %s(%d), uBufferSize: %d fd: %d\n", __func__, - num, DMX_T[dmx_type], dmx_type, buffersize, fd); + num, DMX_T[dmx_type], dmx_type, buffersize, fd); /* this would actually need locking, but the worst that weill happen is, that * we'll DMX_SET_SOURCE twice per device, so don't bother... */ @@ -262,7 +267,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) #if 0 if (len != 4095 && timeout != 10) fprintf(stderr, "cDemux::%s #%d fd: %d type: %s len: %d timeout: %d\n", - __FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout); + __FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout); #endif if (fd < 0) { @@ -275,7 +280,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) int to = timeout; struct pollfd ufds; ufds.fd = fd; - ufds.events = POLLIN|POLLPRI|POLLERR; + ufds.events = POLLIN | POLLPRI | POLLERR; ufds.revents = 0; /* hack: if the frontend loses and regains lock, the demuxer often will not @@ -286,7 +291,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) if (to > 0) { - retry: +retry: rc = ::poll(&ufds, 1, to); if (ufds.fd != fd) { @@ -331,8 +336,9 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return 0; } } - if (ufds.fd != fd) /* does this ever happen? and if, is it harmful? */ - { /* read(-1,...) will just return EBADF anyway... */ + if (ufds.fd != fd) /* does this ever happen? and if, is it harmful? */ + { + /* read(-1,...) will just return EBADF anyway... */ hal_info("%s:2 ========== fd has changed, %d->%d ==========\n", __func__, ufds.fd, fd); return -1; } @@ -345,9 +351,9 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return rc; } -bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, - const unsigned char * const mask, int len, int timeout, - const unsigned char * const negmask) +bool cDemux::sectionFilter(unsigned short _pid, const unsigned char *const filter, + const unsigned char *const mask, int len, int timeout, + const unsigned char *const negmask) { struct dmx_sct_filter_params s_flt; memset(&s_flt, 0, sizeof(s_flt)); @@ -368,7 +374,7 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt if (negmask != NULL) memcpy(s_flt.filter.mode, negmask, len); - s_flt.flags = DMX_IMMEDIATE_START|DMX_CHECK_CRC; + s_flt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; int to = 0; switch (filter[0]) @@ -453,15 +459,22 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt s_flt.timeout = to; hal_debug("%s #%d pid:0x%04hx fd:%d type:%s len:%d to:%d flags:%x flt[0]:%02x\n", __func__, num, - pid, fd, DMX_T[dmx_type], len, s_flt.timeout, s_flt.flags, s_flt.filter.filter[0]); + pid, fd, DMX_T[dmx_type], len, s_flt.timeout, s_flt.flags, s_flt.filter.filter[0]); - if (debuglevel == 2) { - fprintf(stderr,"filt: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.filter[i]); fprintf(stderr, "\n"); - fprintf(stderr,"mask: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mask [i]); fprintf(stderr, "\n"); - fprintf(stderr,"mode: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mode [i]); fprintf(stderr, "\n"); + if (debuglevel == 2) + { + fprintf(stderr, "filt: "); + for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.filter[i]); + fprintf(stderr, "\n"); + fprintf(stderr, "mask: "); + for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mask [i]); + fprintf(stderr, "\n"); + fprintf(stderr, "mode: "); + for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mode [i]); + fprintf(stderr, "\n"); } - ioctl (fd, DMX_STOP); + ioctl(fd, DMX_STOP); if (ioctl(fd, DMX_SET_FILTER, &s_flt) < 0) return false; @@ -477,7 +490,7 @@ bool cDemux::pesFilter(const unsigned short _pid) * this check originally is from tuxbox cvs but I'm not sure * what it is good for... if (pid <= 0x0001 && dmx_type != DMX_PCR_ONLY_CHANNEL) - return false; + return false; */ if ((pid >= 0x0002 && pid <= 0x000f) || pid >= 0x1fff) return false; @@ -569,7 +582,8 @@ void cDemux::removePid(unsigned short Pid) } for (std::vector::iterator i = pesfds.begin(); i != pesfds.end(); ++i) { - if ((*i).pid == Pid) { + if ((*i).pid == Pid) + { hal_debug("removePid: removing demux fd %d pid 0x%04x\n", fd, Pid); if (ioctl(fd, DMX_REMOVE_PID, Pid) < 0) hal_info("%s: (DMX_REMOVE_PID, 0x%04hx): %m\n", __func__, Pid); @@ -580,7 +594,7 @@ void cDemux::removePid(unsigned short Pid) hal_info("%s pid 0x%04x not found\n", __FUNCTION__, Pid); } -void cDemux::getSTC(int64_t * STC) +void cDemux::getSTC(int64_t *STC) { /* apparently I can only get the PTS of the video decoder, * but that's good enough for dvbsub */ @@ -602,7 +616,8 @@ int cDemux::getUnit(void) bool cDemux::SetSource(int unit, int source) { - if (unit >= NUM_DEMUX || unit < 0) { + if (unit >= NUM_DEMUX || unit < 0) + { hal_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX); return false; } @@ -616,7 +631,8 @@ bool cDemux::SetSource(int unit, int source) int cDemux::GetSource(int unit) { - if (unit >= NUM_DEMUX || unit < 0) { + if (unit >= NUM_DEMUX || unit < 0) + { hal_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX); return -1; } diff --git a/libarmbox/hardware_caps.c b/libarmbox/hardware_caps.c index d586e24..905fca2 100644 --- a/libarmbox/hardware_caps.c +++ b/libarmbox/hardware_caps.c @@ -38,10 +38,10 @@ hw_caps_t *get_hwcaps(void) caps.display_xres = 480; caps.display_yres = 320; caps.display_type = HW_DISPLAY_GFX; - caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_umlauts = 0; /* need test */ - caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_umlauts = 0; /* need test */ + caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux caps.display_has_colon = 0; caps.has_button_timer = 1; caps.has_button_vformat = 0; @@ -60,10 +60,10 @@ hw_caps_t *get_hwcaps(void) caps.display_xres = 480; caps.display_yres = 320; caps.display_type = HW_DISPLAY_GFX; - caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_umlauts = 0; /* need test */ - caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_umlauts = 0; /* need test */ + caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux caps.display_has_colon = 0; caps.has_button_timer = 1; caps.has_button_vformat = 0; @@ -82,10 +82,10 @@ hw_caps_t *get_hwcaps(void) caps.display_xres = 480; caps.display_yres = 320; caps.display_type = HW_DISPLAY_GFX; - caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_umlauts = 0; /* need test */ - caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_umlauts = 0; /* need test */ + caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux caps.display_has_colon = 0; caps.has_button_timer = 1; caps.has_button_vformat = 0; @@ -105,10 +105,10 @@ hw_caps_t *get_hwcaps(void) caps.display_xres = 800; caps.display_yres = 480; caps.display_type = HW_DISPLAY_GFX; - caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_umlauts = 0; /* need test */ - caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_umlauts = 0; /* need test */ + caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux caps.display_has_colon = 0; caps.has_button_timer = 1; caps.has_button_vformat = 0; @@ -148,10 +148,10 @@ hw_caps_t *get_hwcaps(void) caps.display_xres = 400; caps.display_yres = 240; caps.display_type = HW_DISPLAY_GFX; - caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_umlauts = 0; /* need test */ - caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_umlauts = 0; /* need test */ + caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux caps.display_has_colon = 0; caps.has_button_timer = 1; caps.has_button_vformat = 0; @@ -335,10 +335,10 @@ hw_caps_t *get_hwcaps(void) caps.display_xres = 128; caps.display_yres = 64; caps.display_type = HW_DISPLAY_GFX; - caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux - caps.display_can_umlauts = 0; /* need test */ - caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_deepstandby = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_set_brightness = 0; // 0 because we use graphlcd/lcd4linux + caps.display_can_umlauts = 0; /* need test */ + caps.display_has_statusline = 0; // 0 because we use graphlcd/lcd4linux caps.display_has_colon = 0; caps.has_button_timer = 1; caps.has_button_vformat = 1; diff --git a/libarmbox/hdmi_cec.cpp b/libarmbox/hdmi_cec.cpp index eb1d451..b29852e 100644 --- a/libarmbox/hdmi_cec.cpp +++ b/libarmbox/hdmi_cec.cpp @@ -1,20 +1,20 @@ /* - Copyright (C) 2018-2021 TangoCash + Copyright (C) 2018-2021 TangoCash - License: GPLv2 + License: GPLv2 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include @@ -52,17 +52,17 @@ #define hal_debug_c(args...) _hal_debug(HAL_DEBUG_INIT, NULL, args) #define hal_info_c(args...) _hal_info(HAL_DEBUG_INIT, NULL, args) -#define fop(cmd, args...) ({ \ - int _r; \ - if (fd >= 0) { \ - if ((_r = ::cmd(fd, args)) < 0) \ - hal_info(#cmd"(fd, "#args")\n"); \ - else \ - hal_debug(#cmd"(fd, "#args")\n");\ - } \ - else { _r = fd; } \ - _r; \ -}) +#define fop(cmd, args...) ({ \ + int _r; \ + if (fd >= 0) { \ + if ((_r = ::cmd(fd, args)) < 0) \ + hal_info(#cmd"(fd, "#args")\n"); \ + else \ + hal_debug(#cmd"(fd, "#args")\n");\ + } \ + else { _r = fd; } \ + _r; \ + }) #define CEC_FALLBACK_DEVICE "/dev/cec0" #define CEC_HDMIDEV "/dev/hdmi_cec" @@ -72,10 +72,10 @@ #define RC_DEVICE "/dev/input/event1" #endif -hdmi_cec * hdmi_cec::hdmi_cec_instance = NULL; +hdmi_cec *hdmi_cec::hdmi_cec_instance = NULL; //hack to get an instance before first call -hdmi_cec * CEC = hdmi_cec::getInstance(); +hdmi_cec *CEC = hdmi_cec::getInstance(); hdmi_cec::hdmi_cec() { @@ -97,7 +97,7 @@ hdmi_cec::~hdmi_cec() } } -hdmi_cec* hdmi_cec::getInstance() +hdmi_cec *hdmi_cec::getInstance() { if (hdmi_cec_instance == NULL) { @@ -173,36 +173,36 @@ bool hdmi_cec::SetCECMode(VIDEO_HDMI_CEC_MODE _deviceType) switch (deviceType) { - case CEC_LOG_ADDR_TV: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TV; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TV; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TV; - break; - case CEC_LOG_ADDR_RECORD_1: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_RECORD; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_RECORD; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_RECORD; - break; - case CEC_LOG_ADDR_TUNER_1: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TUNER; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TUNER; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TUNER; - break; - case CEC_LOG_ADDR_PLAYBACK_1: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_PLAYBACK; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_PLAYBACK; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_PLAYBACK; - break; - case CEC_LOG_ADDR_AUDIOSYSTEM: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_AUDIOSYSTEM; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM; - break; - default: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_UNREGISTERED; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_SWITCH; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_SWITCH; - break; + case CEC_LOG_ADDR_TV: + laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TV; + laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TV; + laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TV; + break; + case CEC_LOG_ADDR_RECORD_1: + laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_RECORD; + laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_RECORD; + laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_RECORD; + break; + case CEC_LOG_ADDR_TUNER_1: + laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TUNER; + laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TUNER; + laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TUNER; + break; + case CEC_LOG_ADDR_PLAYBACK_1: + laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_PLAYBACK; + laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_PLAYBACK; + laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_PLAYBACK; + break; + case CEC_LOG_ADDR_AUDIOSYSTEM: + laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_AUDIOSYSTEM; + laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM; + laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM; + break; + default: + laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_UNREGISTERED; + laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_SWITCH; + laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_SWITCH; + break; } laddrs.num_log_addrs++; @@ -220,7 +220,7 @@ bool hdmi_cec::SetCECMode(VIDEO_HDMI_CEC_MODE _deviceType) { GetCECAddressInfo(); - if(autoview_cec_activ) + if (autoview_cec_activ) SetCECState(false); Start(); @@ -251,25 +251,25 @@ void hdmi_cec::GetCECAddressInfo() switch (laddrs.log_addr_type[0]) { - case CEC_LOG_ADDR_TYPE_TV: - addressinfo.type = CEC_LOG_ADDR_TV; - break; - case CEC_LOG_ADDR_TYPE_RECORD: - addressinfo.type = CEC_LOG_ADDR_RECORD_1; - break; - case CEC_LOG_ADDR_TYPE_TUNER: - addressinfo.type = CEC_LOG_ADDR_TUNER_1; - break; - case CEC_LOG_ADDR_TYPE_PLAYBACK: - addressinfo.type = CEC_LOG_ADDR_PLAYBACK_1; - break; - case CEC_LOG_ADDR_TYPE_AUDIOSYSTEM: - addressinfo.type = CEC_LOG_ADDR_AUDIOSYSTEM; - break; - case CEC_LOG_ADDR_TYPE_UNREGISTERED: - default: - addressinfo.type = CEC_LOG_ADDR_UNREGISTERED; - break; + case CEC_LOG_ADDR_TYPE_TV: + addressinfo.type = CEC_LOG_ADDR_TV; + break; + case CEC_LOG_ADDR_TYPE_RECORD: + addressinfo.type = CEC_LOG_ADDR_RECORD_1; + break; + case CEC_LOG_ADDR_TYPE_TUNER: + addressinfo.type = CEC_LOG_ADDR_TUNER_1; + break; + case CEC_LOG_ADDR_TYPE_PLAYBACK: + addressinfo.type = CEC_LOG_ADDR_PLAYBACK_1; + break; + case CEC_LOG_ADDR_TYPE_AUDIOSYSTEM: + addressinfo.type = CEC_LOG_ADDR_AUDIOSYSTEM; + break; + case CEC_LOG_ADDR_TYPE_UNREGISTERED: + default: + addressinfo.type = CEC_LOG_ADDR_UNREGISTERED; + break; } hasdata = true; } @@ -312,12 +312,12 @@ void hdmi_cec::SendCECMessage(struct cec_message &txmessage, int sleeptime) if (hdmiFd >= 0) { - char str[txmessage.length*6]; + char str[txmessage.length * 6]; for (int i = 0; i < txmessage.length; i++) { - sprintf(str+(i*6),"[0x%02X]", txmessage.data[i]); + sprintf(str + (i * 6), "[0x%02X]", txmessage.data[i]); } - hal_info(GREEN "[CEC] send message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n" NORMAL,ToString((cec_logical_address)txmessage.initiator), txmessage.destination == 0xf ? "all" : ToString((cec_logical_address)txmessage.destination), txmessage.initiator, txmessage.destination, ToString((cec_opcode)txmessage.data[0]), str); + hal_info(GREEN "[CEC] send message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n" NORMAL, ToString((cec_logical_address)txmessage.initiator), txmessage.destination == 0xf ? "all" : ToString((cec_logical_address)txmessage.destination), txmessage.initiator, txmessage.destination, ToString((cec_opcode)txmessage.data[0]), str); if (fallback) { @@ -443,114 +443,114 @@ long hdmi_cec::translateKey(unsigned char code) long key = 0; switch (code) { - case CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL: - key = KEY_MENU; - break; - case CEC_USER_CONTROL_CODE_NUMBER0: - key = KEY_0; - break; - case CEC_USER_CONTROL_CODE_NUMBER1: - key = KEY_1; - break; - case CEC_USER_CONTROL_CODE_NUMBER2: - key = KEY_2; - break; - case CEC_USER_CONTROL_CODE_NUMBER3: - key = KEY_3; - break; - case CEC_USER_CONTROL_CODE_NUMBER4: - key = KEY_4; - break; - case CEC_USER_CONTROL_CODE_NUMBER5: - key = KEY_5; - break; - case CEC_USER_CONTROL_CODE_NUMBER6: - key = KEY_6; - break; - case CEC_USER_CONTROL_CODE_NUMBER7: - key = KEY_7; - break; - case CEC_USER_CONTROL_CODE_NUMBER8: - key = KEY_8; - break; - case CEC_USER_CONTROL_CODE_NUMBER9: - key = KEY_9; - break; - case CEC_USER_CONTROL_CODE_CHANNEL_UP: - key = KEY_CHANNELUP; - break; - case CEC_USER_CONTROL_CODE_CHANNEL_DOWN: - key = KEY_CHANNELDOWN; - break; - case CEC_USER_CONTROL_CODE_PLAY: - key = KEY_PLAY; - break; - case CEC_USER_CONTROL_CODE_STOP: - key = KEY_STOP; - break; - case CEC_USER_CONTROL_CODE_PAUSE: - key = KEY_PAUSE; - break; - case CEC_USER_CONTROL_CODE_RECORD: - key = KEY_RECORD; - break; - case CEC_USER_CONTROL_CODE_REWIND: - key = KEY_REWIND; - break; - case CEC_USER_CONTROL_CODE_FAST_FORWARD: - key = KEY_FASTFORWARD; - break; - case CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE: - key = KEY_INFO; - break; - case CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING: - key = KEY_PROGRAM; - break; - case CEC_USER_CONTROL_CODE_PLAY_FUNCTION: - key = KEY_PLAY; - break; - case CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION: - key = KEY_PLAYPAUSE; - break; - case CEC_USER_CONTROL_CODE_RECORD_FUNCTION: - key = KEY_RECORD; - break; - case CEC_USER_CONTROL_CODE_STOP_FUNCTION: - key = KEY_STOP; - break; - case CEC_USER_CONTROL_CODE_SELECT: - key = KEY_OK; - break; - case CEC_USER_CONTROL_CODE_LEFT: - key = KEY_LEFT; - break; - case CEC_USER_CONTROL_CODE_RIGHT: - key = KEY_RIGHT; - break; - case CEC_USER_CONTROL_CODE_UP: - key = KEY_UP; - break; - case CEC_USER_CONTROL_CODE_DOWN: - key = KEY_DOWN; - break; - case CEC_USER_CONTROL_CODE_EXIT: - key = KEY_EXIT; - break; - case CEC_USER_CONTROL_CODE_F2_RED: - key = KEY_RED; - break; - case CEC_USER_CONTROL_CODE_F3_GREEN: - key = KEY_GREEN; - break; - case CEC_USER_CONTROL_CODE_F4_YELLOW: - key = KEY_YELLOW; - break; - case CEC_USER_CONTROL_CODE_F1_BLUE: - key = KEY_BLUE; - break; - default: - key = KEY_MENU; - break; + case CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL: + key = KEY_MENU; + break; + case CEC_USER_CONTROL_CODE_NUMBER0: + key = KEY_0; + break; + case CEC_USER_CONTROL_CODE_NUMBER1: + key = KEY_1; + break; + case CEC_USER_CONTROL_CODE_NUMBER2: + key = KEY_2; + break; + case CEC_USER_CONTROL_CODE_NUMBER3: + key = KEY_3; + break; + case CEC_USER_CONTROL_CODE_NUMBER4: + key = KEY_4; + break; + case CEC_USER_CONTROL_CODE_NUMBER5: + key = KEY_5; + break; + case CEC_USER_CONTROL_CODE_NUMBER6: + key = KEY_6; + break; + case CEC_USER_CONTROL_CODE_NUMBER7: + key = KEY_7; + break; + case CEC_USER_CONTROL_CODE_NUMBER8: + key = KEY_8; + break; + case CEC_USER_CONTROL_CODE_NUMBER9: + key = KEY_9; + break; + case CEC_USER_CONTROL_CODE_CHANNEL_UP: + key = KEY_CHANNELUP; + break; + case CEC_USER_CONTROL_CODE_CHANNEL_DOWN: + key = KEY_CHANNELDOWN; + break; + case CEC_USER_CONTROL_CODE_PLAY: + key = KEY_PLAY; + break; + case CEC_USER_CONTROL_CODE_STOP: + key = KEY_STOP; + break; + case CEC_USER_CONTROL_CODE_PAUSE: + key = KEY_PAUSE; + break; + case CEC_USER_CONTROL_CODE_RECORD: + key = KEY_RECORD; + break; + case CEC_USER_CONTROL_CODE_REWIND: + key = KEY_REWIND; + break; + case CEC_USER_CONTROL_CODE_FAST_FORWARD: + key = KEY_FASTFORWARD; + break; + case CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE: + key = KEY_INFO; + break; + case CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING: + key = KEY_PROGRAM; + break; + case CEC_USER_CONTROL_CODE_PLAY_FUNCTION: + key = KEY_PLAY; + break; + case CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION: + key = KEY_PLAYPAUSE; + break; + case CEC_USER_CONTROL_CODE_RECORD_FUNCTION: + key = KEY_RECORD; + break; + case CEC_USER_CONTROL_CODE_STOP_FUNCTION: + key = KEY_STOP; + break; + case CEC_USER_CONTROL_CODE_SELECT: + key = KEY_OK; + break; + case CEC_USER_CONTROL_CODE_LEFT: + key = KEY_LEFT; + break; + case CEC_USER_CONTROL_CODE_RIGHT: + key = KEY_RIGHT; + break; + case CEC_USER_CONTROL_CODE_UP: + key = KEY_UP; + break; + case CEC_USER_CONTROL_CODE_DOWN: + key = KEY_DOWN; + break; + case CEC_USER_CONTROL_CODE_EXIT: + key = KEY_EXIT; + break; + case CEC_USER_CONTROL_CODE_F2_RED: + key = KEY_RED; + break; + case CEC_USER_CONTROL_CODE_F3_GREEN: + key = KEY_GREEN; + break; + case CEC_USER_CONTROL_CODE_F4_YELLOW: + key = KEY_YELLOW; + break; + case CEC_USER_CONTROL_CODE_F1_BLUE: + key = KEY_BLUE; + break; + default: + key = KEY_MENU; + break; } return key; } @@ -654,88 +654,90 @@ void hdmi_cec::Receive(int what) bool keypressed = false; static unsigned char pressedkey = 0; - char str[rxmessage.length*6]; + char str[rxmessage.length * 6]; for (int i = 0; i < rxmessage.length; i++) { - sprintf(str+(i*6),"[0x%02X]", rxmessage.data[i]); + sprintf(str + (i * 6), "[0x%02X]", rxmessage.data[i]); } - hal_info(GREEN "[CEC] received message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n" NORMAL,ToString((cec_logical_address)rxmessage.initiator), rxmessage.destination == 0xf ? "all" : ToString((cec_logical_address)rxmessage.destination), rxmessage.initiator, rxmessage.destination, ToString((cec_opcode)rxmessage.opcode), str); + hal_info(GREEN "[CEC] received message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.destination == 0xf ? "all" : ToString((cec_logical_address)rxmessage.destination), rxmessage.initiator, rxmessage.destination, ToString((cec_opcode)rxmessage.opcode), str); switch (rxmessage.opcode) { - //case CEC_OPCODE_ACTIVE_SOURCE: - case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: - { - txmessage.destination = CEC_LOG_ADDR_BROADCAST; //rxmessage.initiator; - txmessage.initiator = logicalAddress; //rxmessage.destination; - txmessage.data[0] = CEC_MSG_ACTIVE_SOURCE; - txmessage.data[1] = physicalAddress[0]; - txmessage.data[2] = physicalAddress[1]; - txmessage.length = 3; - if (!standby) - SendCECMessage(txmessage); - } - case CEC_OPCODE_REPORT_AUDIO_STATUS: - { - muted = ((rxmessage.data[1] & 0x80) == 0x80); - volume = ((rxmessage.data[1] & 0x7F) / 127.0) * 100.0; - if (muted) - hal_info(GREEN "[CEC] %s volume muted\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator)); - else - hal_info(GREEN "[CEC] %s volume %d \n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), volume); - break; - } - case CEC_OPCODE_DEVICE_VENDOR_ID: - case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: - { - uint64_t iVendorId = ((uint64_t)rxmessage.data[1] << 16) + - ((uint64_t)rxmessage.data[2] << 8) + - (uint64_t)rxmessage.data[3]; - hal_info(GREEN "[CEC] decoded message '%s' (%s)\n" NORMAL, ToString((cec_opcode)rxmessage.opcode), ToString((cec_vendor_id)iVendorId)); - break; - } - case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: - { - txmessage.destination = rxmessage.initiator; - txmessage.initiator = rxmessage.destination; - txmessage.data[0] = GetResponseOpcode((cec_opcode)rxmessage.opcode); - txmessage.data[1] = standby ? CEC_POWER_STATUS_STANDBY : CEC_POWER_STATUS_ON; - txmessage.length = 2; - SendCECMessage(txmessage); - break; - } - case CEC_OPCODE_REPORT_POWER_STATUS: - { - if ((rxmessage.data[1] == CEC_POWER_STATUS_ON) || (rxmessage.data[1] == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)) + //case CEC_OPCODE_ACTIVE_SOURCE: + case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: + { + txmessage.destination = CEC_LOG_ADDR_BROADCAST; //rxmessage.initiator; + txmessage.initiator = logicalAddress; //rxmessage.destination; + txmessage.data[0] = CEC_MSG_ACTIVE_SOURCE; + txmessage.data[1] = physicalAddress[0]; + txmessage.data[2] = physicalAddress[1]; + txmessage.length = 3; + if (!standby) + SendCECMessage(txmessage); + } + case CEC_OPCODE_REPORT_AUDIO_STATUS: + { + muted = ((rxmessage.data[1] & 0x80) == 0x80); + volume = ((rxmessage.data[1] & 0x7F) / 127.0) * 100.0; + if (muted) + hal_info(GREEN "[CEC] %s volume muted\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator)); + else + hal_info(GREEN "[CEC] %s volume %d \n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), volume); + break; + } + case CEC_OPCODE_DEVICE_VENDOR_ID: + case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: + { + uint64_t iVendorId = ((uint64_t)rxmessage.data[1] << 16) + + ((uint64_t)rxmessage.data[2] << 8) + + (uint64_t)rxmessage.data[3]; + hal_info(GREEN "[CEC] decoded message '%s' (%s)\n" NORMAL, ToString((cec_opcode)rxmessage.opcode), ToString((cec_vendor_id)iVendorId)); + break; + } + case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: + { + txmessage.destination = rxmessage.initiator; + txmessage.initiator = rxmessage.destination; + txmessage.data[0] = GetResponseOpcode((cec_opcode)rxmessage.opcode); + txmessage.data[1] = standby ? CEC_POWER_STATUS_STANDBY : CEC_POWER_STATUS_ON; + txmessage.length = 2; + SendCECMessage(txmessage); + break; + } + case CEC_OPCODE_REPORT_POWER_STATUS: + { + if ((rxmessage.data[1] == CEC_POWER_STATUS_ON) || (rxmessage.data[1] == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)) + { + hal_info(GREEN "[CEC] %s reporting state on (%d)\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); + if (rxmessage.initiator == CEC_OP_PRIM_DEVTYPE_TV) + tv_off = false; + } + else + { + hal_info(GREEN "[CEC] %s reporting state off (%d)\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); + if (rxmessage.initiator == CEC_OP_PRIM_DEVTYPE_TV) + tv_off = true; + } + break; + } + case CEC_OPCODE_STANDBY: { - hal_info(GREEN "[CEC] %s reporting state on (%d)\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); - if (rxmessage.initiator == CEC_OP_PRIM_DEVTYPE_TV) - tv_off = false; - } else { - hal_info(GREEN "[CEC] %s reporting state off (%d)\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); if (rxmessage.initiator == CEC_OP_PRIM_DEVTYPE_TV) tv_off = true; + break; + } + case CEC_OPCODE_USER_CONTROL_PRESSED: /* key pressed */ + { + keypressed = true; + pressedkey = rxmessage.data[1]; + } // fall through + case CEC_OPCODE_USER_CONTROL_RELEASE: /* key released */ + { + long code = translateKey(pressedkey); + hal_info(GREEN "[CEC] decoded key %s (%ld)\n" NORMAL, ToString((cec_user_control_code)pressedkey), code); + handleCode(code, keypressed); + break; } - break; - } - case CEC_OPCODE_STANDBY: - { - if (rxmessage.initiator == CEC_OP_PRIM_DEVTYPE_TV) - tv_off = true; - break; - } - case CEC_OPCODE_USER_CONTROL_PRESSED: /* key pressed */ - { - keypressed = true; - pressedkey = rxmessage.data[1]; - } // fall through - case CEC_OPCODE_USER_CONTROL_RELEASE: /* key released */ - { - long code = translateKey(pressedkey); - hal_info(GREEN "[CEC] decoded key %s (%ld)\n" NORMAL,ToString((cec_user_control_code)pressedkey), code); - handleCode(code,keypressed); - break; - } } } } @@ -838,7 +840,7 @@ void hdmi_cec::toggle_mute() void hdmi_cec::SetAudioDestination(int audio_dest) { - switch(audio_dest) + switch (audio_dest) { case 2: audio_destination = CEC_OP_PRIM_DEVTYPE_TV; diff --git a/libarmbox/hdmi_cec.h b/libarmbox/hdmi_cec.h index 681cc75..e13a7cd 100644 --- a/libarmbox/hdmi_cec.h +++ b/libarmbox/hdmi_cec.h @@ -2,22 +2,22 @@ #define __HDMI_CEC_H__ /* - Copyright (C) 2018-2021 TangoCash + Copyright (C) 2018-2021 TangoCash - License: GPLv2 + License: GPLv2 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include @@ -57,58 +57,58 @@ enum class hdmi_cec : public OpenThreads::Thread { -private: - hdmi_cec(); - static hdmi_cec *hdmi_cec_instance; - void run(); - bool Start(); - bool Stop(); - void Receive(int what); - unsigned char physicalAddress[2]; - bool autoview_cec_activ; - unsigned char deviceType, logicalAddress; - int hdmiFd; - long translateKey(unsigned char code); - void handleCode(long code, bool keypressed); - int rc_send(int fd, unsigned int code, unsigned int value); - void rc_sync(int fd); - bool standby; - void send_key(unsigned char key, unsigned char destination); - void request_audio_status(); - bool muted; - int volume; - bool fallback; - bool tv_off; - unsigned char audio_destination; -protected: - bool running; -public: - ~hdmi_cec(); - static hdmi_cec* getInstance(); - bool SetCECMode(VIDEO_HDMI_CEC_MODE); - void SetCECAutoView(bool); - void SetCECAutoStandby(bool); - void GetCECAddressInfo(); - void SendCECMessage(struct cec_message &message, int sleeptime = 10); - void SetCECState(bool state); - void ReportPhysicalAddress(); - bool standby_cec_activ; - void vol_up(); - void vol_down(); - void toggle_mute(); - int GetVolume() - { - return volume; - }; - bool isMuted() - { - return muted; - }; - int GetAudioDestination() - { - return (int)audio_destination; - } - void SetAudioDestination(int audio_dest); + private: + hdmi_cec(); + static hdmi_cec *hdmi_cec_instance; + void run(); + bool Start(); + bool Stop(); + void Receive(int what); + unsigned char physicalAddress[2]; + bool autoview_cec_activ; + unsigned char deviceType, logicalAddress; + int hdmiFd; + long translateKey(unsigned char code); + void handleCode(long code, bool keypressed); + int rc_send(int fd, unsigned int code, unsigned int value); + void rc_sync(int fd); + bool standby; + void send_key(unsigned char key, unsigned char destination); + void request_audio_status(); + bool muted; + int volume; + bool fallback; + bool tv_off; + unsigned char audio_destination; + protected: + bool running; + public: + ~hdmi_cec(); + static hdmi_cec *getInstance(); + bool SetCECMode(VIDEO_HDMI_CEC_MODE); + void SetCECAutoView(bool); + void SetCECAutoStandby(bool); + void GetCECAddressInfo(); + void SendCECMessage(struct cec_message &message, int sleeptime = 10); + void SetCECState(bool state); + void ReportPhysicalAddress(); + bool standby_cec_activ; + void vol_up(); + void vol_down(); + void toggle_mute(); + int GetVolume() + { + return volume; + }; + bool isMuted() + { + return muted; + }; + int GetAudioDestination() + { + return (int)audio_destination; + } + void SetAudioDestination(int audio_dest); }; #endif // __HDMI_CEC_H__ diff --git a/libarmbox/hdmi_cec_types.h b/libarmbox/hdmi_cec_types.h index 9600222..4e3a726 100644 --- a/libarmbox/hdmi_cec_types.h +++ b/libarmbox/hdmi_cec_types.h @@ -245,148 +245,148 @@ static const char *ToString(const cec_opcode opcode) { switch (opcode) { - case CEC_OPCODE_ACTIVE_SOURCE: - return "active source"; - case CEC_OPCODE_IMAGE_VIEW_ON: - return "image view on"; - case CEC_OPCODE_TEXT_VIEW_ON: - return "text view on"; - case CEC_OPCODE_INACTIVE_SOURCE: - return "inactive source"; - case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: - return "request active source"; - case CEC_OPCODE_ROUTING_CHANGE: - return "routing change"; - case CEC_OPCODE_ROUTING_INFORMATION: - return "routing information"; - case CEC_OPCODE_SET_STREAM_PATH: - return "set stream path"; - case CEC_OPCODE_STANDBY: - return "standby"; - case CEC_OPCODE_RECORD_OFF: - return "record off"; - case CEC_OPCODE_RECORD_ON: - return "record on"; - case CEC_OPCODE_RECORD_STATUS: - return "record status"; - case CEC_OPCODE_RECORD_TV_SCREEN: - return "record tv screen"; - case CEC_OPCODE_CLEAR_ANALOGUE_TIMER: - return "clear analogue timer"; - case CEC_OPCODE_CLEAR_DIGITAL_TIMER: - return "clear digital timer"; - case CEC_OPCODE_CLEAR_EXTERNAL_TIMER: - return "clear external timer"; - case CEC_OPCODE_SET_ANALOGUE_TIMER: - return "set analogue timer"; - case CEC_OPCODE_SET_DIGITAL_TIMER: - return "set digital timer"; - case CEC_OPCODE_SET_EXTERNAL_TIMER: - return "set external timer"; - case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE: - return "set timer program title"; - case CEC_OPCODE_TIMER_CLEARED_STATUS: - return "timer cleared status"; - case CEC_OPCODE_TIMER_STATUS: - return "timer status"; - case CEC_OPCODE_CEC_VERSION: - return "cec version"; - case CEC_OPCODE_GET_CEC_VERSION: - return "get cec version"; - case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: - return "give physical address"; - case CEC_OPCODE_GET_MENU_LANGUAGE: - return "get menu language"; - case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: - return "report physical address"; - case CEC_OPCODE_SET_MENU_LANGUAGE: - return "set menu language"; - case CEC_OPCODE_DECK_CONTROL: - return "deck control"; - case CEC_OPCODE_DECK_STATUS: - return "deck status"; - case CEC_OPCODE_GIVE_DECK_STATUS: - return "give deck status"; - case CEC_OPCODE_PLAY: - return "play"; - case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: - return "give tuner status"; - case CEC_OPCODE_SELECT_ANALOGUE_SERVICE: - return "select analogue service"; - case CEC_OPCODE_SELECT_DIGITAL_SERVICE: - return "set digital service"; - case CEC_OPCODE_TUNER_DEVICE_STATUS: - return "tuner device status"; - case CEC_OPCODE_TUNER_STEP_DECREMENT: - return "tuner step decrement"; - case CEC_OPCODE_TUNER_STEP_INCREMENT: - return "tuner step increment"; - case CEC_OPCODE_DEVICE_VENDOR_ID: - return "device vendor id"; - case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: - return "give device vendor id"; - case CEC_OPCODE_VENDOR_COMMAND: - return "vendor command"; - case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: - return "vendor command with id"; - case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN: - return "vendor remote button down"; - case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP: - return "vendor remote button up"; - case CEC_OPCODE_SET_OSD_STRING: - return "set osd string"; - case CEC_OPCODE_GIVE_OSD_NAME: - return "give osd name"; - case CEC_OPCODE_SET_OSD_NAME: - return "set osd name"; - case CEC_OPCODE_MENU_REQUEST: - return "menu request"; - case CEC_OPCODE_MENU_STATUS: - return "menu status"; - case CEC_OPCODE_USER_CONTROL_PRESSED: - return "user control pressed"; - case CEC_OPCODE_USER_CONTROL_RELEASE: - return "user control release"; - case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: - return "give device power status"; - case CEC_OPCODE_REPORT_POWER_STATUS: - return "report power status"; - case CEC_OPCODE_FEATURE_ABORT: - return "feature abort"; - case CEC_OPCODE_ABORT: - return "abort"; - case CEC_OPCODE_GIVE_AUDIO_STATUS: - return "give audio status"; - case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: - return "give audio mode status"; - case CEC_OPCODE_REPORT_AUDIO_STATUS: - return "report audio status"; - case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: - return "set system audio mode"; - case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: - return "system audio mode request"; - case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: - return "system audio mode status"; - case CEC_OPCODE_SET_AUDIO_RATE: - return "set audio rate"; - case CEC_OPCODE_START_ARC: - return "start ARC"; - case CEC_OPCODE_REPORT_ARC_STARTED: - return "report ARC started"; - case CEC_OPCODE_REPORT_ARC_ENDED: - return "report ARC ended"; - case CEC_OPCODE_REQUEST_ARC_START: - return "request ARC start"; - case CEC_OPCODE_REQUEST_ARC_END: - return "request ARC end"; - case CEC_OPCODE_END_ARC: - return "end ARC"; - case CEC_OPCODE_CDC: - return "CDC"; - case CEC_OPCODE_NONE: - return "poll"; - default: - return "UNKNOWN"; + case CEC_OPCODE_ACTIVE_SOURCE: + return "active source"; + case CEC_OPCODE_IMAGE_VIEW_ON: + return "image view on"; + case CEC_OPCODE_TEXT_VIEW_ON: + return "text view on"; + case CEC_OPCODE_INACTIVE_SOURCE: + return "inactive source"; + case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: + return "request active source"; + case CEC_OPCODE_ROUTING_CHANGE: + return "routing change"; + case CEC_OPCODE_ROUTING_INFORMATION: + return "routing information"; + case CEC_OPCODE_SET_STREAM_PATH: + return "set stream path"; + case CEC_OPCODE_STANDBY: + return "standby"; + case CEC_OPCODE_RECORD_OFF: + return "record off"; + case CEC_OPCODE_RECORD_ON: + return "record on"; + case CEC_OPCODE_RECORD_STATUS: + return "record status"; + case CEC_OPCODE_RECORD_TV_SCREEN: + return "record tv screen"; + case CEC_OPCODE_CLEAR_ANALOGUE_TIMER: + return "clear analogue timer"; + case CEC_OPCODE_CLEAR_DIGITAL_TIMER: + return "clear digital timer"; + case CEC_OPCODE_CLEAR_EXTERNAL_TIMER: + return "clear external timer"; + case CEC_OPCODE_SET_ANALOGUE_TIMER: + return "set analogue timer"; + case CEC_OPCODE_SET_DIGITAL_TIMER: + return "set digital timer"; + case CEC_OPCODE_SET_EXTERNAL_TIMER: + return "set external timer"; + case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE: + return "set timer program title"; + case CEC_OPCODE_TIMER_CLEARED_STATUS: + return "timer cleared status"; + case CEC_OPCODE_TIMER_STATUS: + return "timer status"; + case CEC_OPCODE_CEC_VERSION: + return "cec version"; + case CEC_OPCODE_GET_CEC_VERSION: + return "get cec version"; + case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: + return "give physical address"; + case CEC_OPCODE_GET_MENU_LANGUAGE: + return "get menu language"; + case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: + return "report physical address"; + case CEC_OPCODE_SET_MENU_LANGUAGE: + return "set menu language"; + case CEC_OPCODE_DECK_CONTROL: + return "deck control"; + case CEC_OPCODE_DECK_STATUS: + return "deck status"; + case CEC_OPCODE_GIVE_DECK_STATUS: + return "give deck status"; + case CEC_OPCODE_PLAY: + return "play"; + case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: + return "give tuner status"; + case CEC_OPCODE_SELECT_ANALOGUE_SERVICE: + return "select analogue service"; + case CEC_OPCODE_SELECT_DIGITAL_SERVICE: + return "set digital service"; + case CEC_OPCODE_TUNER_DEVICE_STATUS: + return "tuner device status"; + case CEC_OPCODE_TUNER_STEP_DECREMENT: + return "tuner step decrement"; + case CEC_OPCODE_TUNER_STEP_INCREMENT: + return "tuner step increment"; + case CEC_OPCODE_DEVICE_VENDOR_ID: + return "device vendor id"; + case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: + return "give device vendor id"; + case CEC_OPCODE_VENDOR_COMMAND: + return "vendor command"; + case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: + return "vendor command with id"; + case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN: + return "vendor remote button down"; + case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP: + return "vendor remote button up"; + case CEC_OPCODE_SET_OSD_STRING: + return "set osd string"; + case CEC_OPCODE_GIVE_OSD_NAME: + return "give osd name"; + case CEC_OPCODE_SET_OSD_NAME: + return "set osd name"; + case CEC_OPCODE_MENU_REQUEST: + return "menu request"; + case CEC_OPCODE_MENU_STATUS: + return "menu status"; + case CEC_OPCODE_USER_CONTROL_PRESSED: + return "user control pressed"; + case CEC_OPCODE_USER_CONTROL_RELEASE: + return "user control release"; + case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: + return "give device power status"; + case CEC_OPCODE_REPORT_POWER_STATUS: + return "report power status"; + case CEC_OPCODE_FEATURE_ABORT: + return "feature abort"; + case CEC_OPCODE_ABORT: + return "abort"; + case CEC_OPCODE_GIVE_AUDIO_STATUS: + return "give audio status"; + case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: + return "give audio mode status"; + case CEC_OPCODE_REPORT_AUDIO_STATUS: + return "report audio status"; + case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: + return "set system audio mode"; + case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: + return "system audio mode request"; + case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: + return "system audio mode status"; + case CEC_OPCODE_SET_AUDIO_RATE: + return "set audio rate"; + case CEC_OPCODE_START_ARC: + return "start ARC"; + case CEC_OPCODE_REPORT_ARC_STARTED: + return "report ARC started"; + case CEC_OPCODE_REPORT_ARC_ENDED: + return "report ARC ended"; + case CEC_OPCODE_REQUEST_ARC_START: + return "request ARC start"; + case CEC_OPCODE_REQUEST_ARC_END: + return "request ARC end"; + case CEC_OPCODE_END_ARC: + return "end ARC"; + case CEC_OPCODE_CDC: + return "CDC"; + case CEC_OPCODE_NONE: + return "poll"; + default: + return "UNKNOWN"; } } @@ -394,59 +394,59 @@ static const char *ToString(const cec_vendor_id vendor) { switch (vendor) { - case CEC_VENDOR_SAMSUNG: - return "Samsung"; - case CEC_VENDOR_LG: - return "LG"; - case CEC_VENDOR_PANASONIC: - return "Panasonic"; - case CEC_VENDOR_PIONEER: - return "Pioneer"; - case CEC_VENDOR_ONKYO: - return "Onkyo"; - case CEC_VENDOR_YAMAHA: - return "Yamaha"; - case CEC_VENDOR_PHILIPS: - return "Philips"; - case CEC_VENDOR_SONY: - return "Sony"; - case CEC_VENDOR_TOSHIBA: - case CEC_VENDOR_TOSHIBA2: - return "Toshiba"; - case CEC_VENDOR_AKAI: - return "Akai"; - case CEC_VENDOR_AOC: - return "AOC"; - case CEC_VENDOR_BENQ: - return "Benq"; - case CEC_VENDOR_DAEWOO: - return "Daewoo"; - case CEC_VENDOR_GRUNDIG: - return "Grundig"; - case CEC_VENDOR_MEDION: - return "Medion"; - case CEC_VENDOR_SHARP: - case CEC_VENDOR_SHARP2: - return "Sharp"; - case CEC_VENDOR_VIZIO: - return "Vizio"; - case CEC_VENDOR_BROADCOM: - return "Broadcom"; - case CEC_VENDOR_LOEWE: - return "Loewe"; - case CEC_VENDOR_DENON: - return "Denon"; - case CEC_VENDOR_MARANTZ: - return "Marantz"; - case CEC_VENDOR_HARMAN_KARDON: - case CEC_VENDOR_HARMAN_KARDON2: - return "Harman/Kardon"; - case CEC_VENDOR_PULSE_EIGHT: - return "Pulse Eight"; - case CEC_VENDOR_GOOGLE: - return "Google"; - default: - return "Unknown"; + case CEC_VENDOR_SAMSUNG: + return "Samsung"; + case CEC_VENDOR_LG: + return "LG"; + case CEC_VENDOR_PANASONIC: + return "Panasonic"; + case CEC_VENDOR_PIONEER: + return "Pioneer"; + case CEC_VENDOR_ONKYO: + return "Onkyo"; + case CEC_VENDOR_YAMAHA: + return "Yamaha"; + case CEC_VENDOR_PHILIPS: + return "Philips"; + case CEC_VENDOR_SONY: + return "Sony"; + case CEC_VENDOR_TOSHIBA: + case CEC_VENDOR_TOSHIBA2: + return "Toshiba"; + case CEC_VENDOR_AKAI: + return "Akai"; + case CEC_VENDOR_AOC: + return "AOC"; + case CEC_VENDOR_BENQ: + return "Benq"; + case CEC_VENDOR_DAEWOO: + return "Daewoo"; + case CEC_VENDOR_GRUNDIG: + return "Grundig"; + case CEC_VENDOR_MEDION: + return "Medion"; + case CEC_VENDOR_SHARP: + case CEC_VENDOR_SHARP2: + return "Sharp"; + case CEC_VENDOR_VIZIO: + return "Vizio"; + case CEC_VENDOR_BROADCOM: + return "Broadcom"; + case CEC_VENDOR_LOEWE: + return "Loewe"; + case CEC_VENDOR_DENON: + return "Denon"; + case CEC_VENDOR_MARANTZ: + return "Marantz"; + case CEC_VENDOR_HARMAN_KARDON: + case CEC_VENDOR_HARMAN_KARDON2: + return "Harman/Kardon"; + case CEC_VENDOR_PULSE_EIGHT: + return "Pulse Eight"; + case CEC_VENDOR_GOOGLE: + return "Google"; + default: + return "Unknown"; } } @@ -454,182 +454,182 @@ static const char *ToString(const cec_user_control_code key) { switch (key) { - case CEC_USER_CONTROL_CODE_SELECT: - return "select"; - case CEC_USER_CONTROL_CODE_UP: - return "up"; - case CEC_USER_CONTROL_CODE_DOWN: - return "down"; - case CEC_USER_CONTROL_CODE_LEFT: - return "left"; - case CEC_USER_CONTROL_CODE_RIGHT: - return "right"; - case CEC_USER_CONTROL_CODE_RIGHT_UP: - return "right+up"; - case CEC_USER_CONTROL_CODE_RIGHT_DOWN: - return "right+down"; - case CEC_USER_CONTROL_CODE_LEFT_UP: - return "left+up"; - case CEC_USER_CONTROL_CODE_LEFT_DOWN: - return "left+down"; - case CEC_USER_CONTROL_CODE_ROOT_MENU: - return "root menu"; - case CEC_USER_CONTROL_CODE_SETUP_MENU: - return "setup menu"; - case CEC_USER_CONTROL_CODE_CONTENTS_MENU: - return "contents menu"; - case CEC_USER_CONTROL_CODE_FAVORITE_MENU: - return "favourite menu"; - case CEC_USER_CONTROL_CODE_EXIT: - return "exit"; - case CEC_USER_CONTROL_CODE_TOP_MENU: - return "top menu"; - case CEC_USER_CONTROL_CODE_DVD_MENU: - return "dvd menu"; - case CEC_USER_CONTROL_CODE_NUMBER_ENTRY_MODE: - return "number entry mode"; - case CEC_USER_CONTROL_CODE_NUMBER11: - return "11"; - case CEC_USER_CONTROL_CODE_NUMBER12: - return "12"; - case CEC_USER_CONTROL_CODE_NUMBER0: - return "0"; - case CEC_USER_CONTROL_CODE_NUMBER1: - return "1"; - case CEC_USER_CONTROL_CODE_NUMBER2: - return "2"; - case CEC_USER_CONTROL_CODE_NUMBER3: - return "3"; - case CEC_USER_CONTROL_CODE_NUMBER4: - return "4"; - case CEC_USER_CONTROL_CODE_NUMBER5: - return "5"; - case CEC_USER_CONTROL_CODE_NUMBER6: - return "6"; - case CEC_USER_CONTROL_CODE_NUMBER7: - return "7"; - case CEC_USER_CONTROL_CODE_NUMBER8: - return "8"; - case CEC_USER_CONTROL_CODE_NUMBER9: - return "9"; - case CEC_USER_CONTROL_CODE_DOT: - return "."; - case CEC_USER_CONTROL_CODE_ENTER: - return "enter"; - case CEC_USER_CONTROL_CODE_CLEAR: - return "clear"; - case CEC_USER_CONTROL_CODE_NEXT_FAVORITE: - return "next favourite"; - case CEC_USER_CONTROL_CODE_CHANNEL_UP: - return "channel up"; - case CEC_USER_CONTROL_CODE_CHANNEL_DOWN: - return "channel down"; - case CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL: - return "previous channel"; - case CEC_USER_CONTROL_CODE_SOUND_SELECT: - return "sound select"; - case CEC_USER_CONTROL_CODE_INPUT_SELECT: - return "input select"; - case CEC_USER_CONTROL_CODE_DISPLAY_INFORMATION: - return "display information"; - case CEC_USER_CONTROL_CODE_HELP: - return "help"; - case CEC_USER_CONTROL_CODE_PAGE_UP: - return "page up"; - case CEC_USER_CONTROL_CODE_PAGE_DOWN: - return "page down"; - case CEC_USER_CONTROL_CODE_POWER: - return "power"; - case CEC_USER_CONTROL_CODE_VOLUME_UP: - return "volume up"; - case CEC_USER_CONTROL_CODE_VOLUME_DOWN: - return "volume down"; - case CEC_USER_CONTROL_CODE_MUTE: - return "mute"; - case CEC_USER_CONTROL_CODE_PLAY: - return "play"; - case CEC_USER_CONTROL_CODE_STOP: - return "stop"; - case CEC_USER_CONTROL_CODE_PAUSE: - return "pause"; - case CEC_USER_CONTROL_CODE_RECORD: - return "record"; - case CEC_USER_CONTROL_CODE_REWIND: - return "rewind"; - case CEC_USER_CONTROL_CODE_FAST_FORWARD: - return "Fast forward"; - case CEC_USER_CONTROL_CODE_EJECT: - return "eject"; - case CEC_USER_CONTROL_CODE_FORWARD: - return "forward"; - case CEC_USER_CONTROL_CODE_BACKWARD: - return "backward"; - case CEC_USER_CONTROL_CODE_STOP_RECORD: - return "stop record"; - case CEC_USER_CONTROL_CODE_PAUSE_RECORD: - return "pause record"; - case CEC_USER_CONTROL_CODE_ANGLE: - return "angle"; - case CEC_USER_CONTROL_CODE_SUB_PICTURE: - return "sub picture"; - case CEC_USER_CONTROL_CODE_VIDEO_ON_DEMAND: - return "video on demand"; - case CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE: - return "electronic program guide"; - case CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING: - return "timer programming"; - case CEC_USER_CONTROL_CODE_INITIAL_CONFIGURATION: - return "initial configuration"; - case CEC_USER_CONTROL_CODE_SELECT_BROADCAST_TYPE: - return "select broadcast type"; - case CEC_USER_CONTROL_CODE_SELECT_SOUND_PRESENTATION: - return "select sound presentation"; - case CEC_USER_CONTROL_CODE_PLAY_FUNCTION: - return "play (function)"; - case CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION: - return "pause play (function)"; - case CEC_USER_CONTROL_CODE_RECORD_FUNCTION: - return "record (function)"; - case CEC_USER_CONTROL_CODE_PAUSE_RECORD_FUNCTION: - return "pause record (function)"; - case CEC_USER_CONTROL_CODE_STOP_FUNCTION: - return "stop (function)"; - case CEC_USER_CONTROL_CODE_MUTE_FUNCTION: - return "mute (function)"; - case CEC_USER_CONTROL_CODE_RESTORE_VOLUME_FUNCTION: - return "restore volume"; - case CEC_USER_CONTROL_CODE_TUNE_FUNCTION: - return "tune"; - case CEC_USER_CONTROL_CODE_SELECT_MEDIA_FUNCTION: - return "select media"; - case CEC_USER_CONTROL_CODE_SELECT_AV_INPUT_FUNCTION: - return "select AV input"; - case CEC_USER_CONTROL_CODE_SELECT_AUDIO_INPUT_FUNCTION: - return "select audio input"; - case CEC_USER_CONTROL_CODE_POWER_TOGGLE_FUNCTION: - return "power toggle"; - case CEC_USER_CONTROL_CODE_POWER_OFF_FUNCTION: - return "power off"; - case CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION: - return "power on"; - case CEC_USER_CONTROL_CODE_F1_BLUE: - return "F1 (blue)"; - case CEC_USER_CONTROL_CODE_F2_RED: - return "F2 (red)"; - case CEC_USER_CONTROL_CODE_F3_GREEN: - return "F3 (green)"; - case CEC_USER_CONTROL_CODE_F4_YELLOW: - return "F4 (yellow)"; - case CEC_USER_CONTROL_CODE_F5: - return "F5"; - case CEC_USER_CONTROL_CODE_DATA: - return "data"; - case CEC_USER_CONTROL_CODE_AN_RETURN: - return "return (Samsung)"; - case CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST: - return "channels list (Samsung)"; - default: - return "unknown"; + case CEC_USER_CONTROL_CODE_SELECT: + return "select"; + case CEC_USER_CONTROL_CODE_UP: + return "up"; + case CEC_USER_CONTROL_CODE_DOWN: + return "down"; + case CEC_USER_CONTROL_CODE_LEFT: + return "left"; + case CEC_USER_CONTROL_CODE_RIGHT: + return "right"; + case CEC_USER_CONTROL_CODE_RIGHT_UP: + return "right+up"; + case CEC_USER_CONTROL_CODE_RIGHT_DOWN: + return "right+down"; + case CEC_USER_CONTROL_CODE_LEFT_UP: + return "left+up"; + case CEC_USER_CONTROL_CODE_LEFT_DOWN: + return "left+down"; + case CEC_USER_CONTROL_CODE_ROOT_MENU: + return "root menu"; + case CEC_USER_CONTROL_CODE_SETUP_MENU: + return "setup menu"; + case CEC_USER_CONTROL_CODE_CONTENTS_MENU: + return "contents menu"; + case CEC_USER_CONTROL_CODE_FAVORITE_MENU: + return "favourite menu"; + case CEC_USER_CONTROL_CODE_EXIT: + return "exit"; + case CEC_USER_CONTROL_CODE_TOP_MENU: + return "top menu"; + case CEC_USER_CONTROL_CODE_DVD_MENU: + return "dvd menu"; + case CEC_USER_CONTROL_CODE_NUMBER_ENTRY_MODE: + return "number entry mode"; + case CEC_USER_CONTROL_CODE_NUMBER11: + return "11"; + case CEC_USER_CONTROL_CODE_NUMBER12: + return "12"; + case CEC_USER_CONTROL_CODE_NUMBER0: + return "0"; + case CEC_USER_CONTROL_CODE_NUMBER1: + return "1"; + case CEC_USER_CONTROL_CODE_NUMBER2: + return "2"; + case CEC_USER_CONTROL_CODE_NUMBER3: + return "3"; + case CEC_USER_CONTROL_CODE_NUMBER4: + return "4"; + case CEC_USER_CONTROL_CODE_NUMBER5: + return "5"; + case CEC_USER_CONTROL_CODE_NUMBER6: + return "6"; + case CEC_USER_CONTROL_CODE_NUMBER7: + return "7"; + case CEC_USER_CONTROL_CODE_NUMBER8: + return "8"; + case CEC_USER_CONTROL_CODE_NUMBER9: + return "9"; + case CEC_USER_CONTROL_CODE_DOT: + return "."; + case CEC_USER_CONTROL_CODE_ENTER: + return "enter"; + case CEC_USER_CONTROL_CODE_CLEAR: + return "clear"; + case CEC_USER_CONTROL_CODE_NEXT_FAVORITE: + return "next favourite"; + case CEC_USER_CONTROL_CODE_CHANNEL_UP: + return "channel up"; + case CEC_USER_CONTROL_CODE_CHANNEL_DOWN: + return "channel down"; + case CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL: + return "previous channel"; + case CEC_USER_CONTROL_CODE_SOUND_SELECT: + return "sound select"; + case CEC_USER_CONTROL_CODE_INPUT_SELECT: + return "input select"; + case CEC_USER_CONTROL_CODE_DISPLAY_INFORMATION: + return "display information"; + case CEC_USER_CONTROL_CODE_HELP: + return "help"; + case CEC_USER_CONTROL_CODE_PAGE_UP: + return "page up"; + case CEC_USER_CONTROL_CODE_PAGE_DOWN: + return "page down"; + case CEC_USER_CONTROL_CODE_POWER: + return "power"; + case CEC_USER_CONTROL_CODE_VOLUME_UP: + return "volume up"; + case CEC_USER_CONTROL_CODE_VOLUME_DOWN: + return "volume down"; + case CEC_USER_CONTROL_CODE_MUTE: + return "mute"; + case CEC_USER_CONTROL_CODE_PLAY: + return "play"; + case CEC_USER_CONTROL_CODE_STOP: + return "stop"; + case CEC_USER_CONTROL_CODE_PAUSE: + return "pause"; + case CEC_USER_CONTROL_CODE_RECORD: + return "record"; + case CEC_USER_CONTROL_CODE_REWIND: + return "rewind"; + case CEC_USER_CONTROL_CODE_FAST_FORWARD: + return "Fast forward"; + case CEC_USER_CONTROL_CODE_EJECT: + return "eject"; + case CEC_USER_CONTROL_CODE_FORWARD: + return "forward"; + case CEC_USER_CONTROL_CODE_BACKWARD: + return "backward"; + case CEC_USER_CONTROL_CODE_STOP_RECORD: + return "stop record"; + case CEC_USER_CONTROL_CODE_PAUSE_RECORD: + return "pause record"; + case CEC_USER_CONTROL_CODE_ANGLE: + return "angle"; + case CEC_USER_CONTROL_CODE_SUB_PICTURE: + return "sub picture"; + case CEC_USER_CONTROL_CODE_VIDEO_ON_DEMAND: + return "video on demand"; + case CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE: + return "electronic program guide"; + case CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING: + return "timer programming"; + case CEC_USER_CONTROL_CODE_INITIAL_CONFIGURATION: + return "initial configuration"; + case CEC_USER_CONTROL_CODE_SELECT_BROADCAST_TYPE: + return "select broadcast type"; + case CEC_USER_CONTROL_CODE_SELECT_SOUND_PRESENTATION: + return "select sound presentation"; + case CEC_USER_CONTROL_CODE_PLAY_FUNCTION: + return "play (function)"; + case CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION: + return "pause play (function)"; + case CEC_USER_CONTROL_CODE_RECORD_FUNCTION: + return "record (function)"; + case CEC_USER_CONTROL_CODE_PAUSE_RECORD_FUNCTION: + return "pause record (function)"; + case CEC_USER_CONTROL_CODE_STOP_FUNCTION: + return "stop (function)"; + case CEC_USER_CONTROL_CODE_MUTE_FUNCTION: + return "mute (function)"; + case CEC_USER_CONTROL_CODE_RESTORE_VOLUME_FUNCTION: + return "restore volume"; + case CEC_USER_CONTROL_CODE_TUNE_FUNCTION: + return "tune"; + case CEC_USER_CONTROL_CODE_SELECT_MEDIA_FUNCTION: + return "select media"; + case CEC_USER_CONTROL_CODE_SELECT_AV_INPUT_FUNCTION: + return "select AV input"; + case CEC_USER_CONTROL_CODE_SELECT_AUDIO_INPUT_FUNCTION: + return "select audio input"; + case CEC_USER_CONTROL_CODE_POWER_TOGGLE_FUNCTION: + return "power toggle"; + case CEC_USER_CONTROL_CODE_POWER_OFF_FUNCTION: + return "power off"; + case CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION: + return "power on"; + case CEC_USER_CONTROL_CODE_F1_BLUE: + return "F1 (blue)"; + case CEC_USER_CONTROL_CODE_F2_RED: + return "F2 (red)"; + case CEC_USER_CONTROL_CODE_F3_GREEN: + return "F3 (green)"; + case CEC_USER_CONTROL_CODE_F4_YELLOW: + return "F4 (yellow)"; + case CEC_USER_CONTROL_CODE_F5: + return "F5"; + case CEC_USER_CONTROL_CODE_DATA: + return "data"; + case CEC_USER_CONTROL_CODE_AN_RETURN: + return "return (Samsung)"; + case CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST: + return "channels list (Samsung)"; + default: + return "unknown"; } } @@ -637,39 +637,39 @@ static const char *ToString(cec_logical_address la) { switch (la & 0xf) { - case CECDEVICE_TV: - return "TV"; - case CECDEVICE_RECORDINGDEVICE1: - return "Recording Device 1"; - case CECDEVICE_RECORDINGDEVICE2: - return "Recording Device 2"; - case CECDEVICE_TUNER1: - return "Tuner 1"; - case CECDEVICE_PLAYBACKDEVICE1: - return "Playback Device 1"; - case CECDEVICE_AUDIOSYSTEM: - return "Audio System"; - case CECDEVICE_TUNER2: - return "Tuner 2"; - case CECDEVICE_TUNER3: - return "Tuner 3"; - case CECDEVICE_PLAYBACKDEVICE2: - return "Playback Device 2"; - case CECDEVICE_RECORDINGDEVICE3: - return "Recording Device 3"; - case CECDEVICE_TUNER4: - return "Tuner 4"; - case CECDEVICE_PLAYBACKDEVICE3: - return "Playback Device 3"; - case CECDEVICE_RESERVED1: - return "Reserved 1"; - case CECDEVICE_RESERVED2: - return "Reserved 2"; - case CECDEVICE_FREEUSE: - return "Free use"; - case CECDEVICE_UNREGISTERED: - default: - return "Unregistered"; + case CECDEVICE_TV: + return "TV"; + case CECDEVICE_RECORDINGDEVICE1: + return "Recording Device 1"; + case CECDEVICE_RECORDINGDEVICE2: + return "Recording Device 2"; + case CECDEVICE_TUNER1: + return "Tuner 1"; + case CECDEVICE_PLAYBACKDEVICE1: + return "Playback Device 1"; + case CECDEVICE_AUDIOSYSTEM: + return "Audio System"; + case CECDEVICE_TUNER2: + return "Tuner 2"; + case CECDEVICE_TUNER3: + return "Tuner 3"; + case CECDEVICE_PLAYBACKDEVICE2: + return "Playback Device 2"; + case CECDEVICE_RECORDINGDEVICE3: + return "Recording Device 3"; + case CECDEVICE_TUNER4: + return "Tuner 4"; + case CECDEVICE_PLAYBACKDEVICE3: + return "Playback Device 3"; + case CECDEVICE_RESERVED1: + return "Reserved 1"; + case CECDEVICE_RESERVED2: + return "Reserved 2"; + case CECDEVICE_FREEUSE: + return "Free use"; + case CECDEVICE_UNREGISTERED: + default: + return "Unregistered"; } } @@ -677,34 +677,34 @@ static cec_opcode GetResponseOpcode(cec_opcode opcode) { switch (opcode) { - case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: - return CEC_OPCODE_ACTIVE_SOURCE; - case CEC_OPCODE_GET_CEC_VERSION: - return CEC_OPCODE_CEC_VERSION; - case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: - return CEC_OPCODE_REPORT_PHYSICAL_ADDRESS; - case CEC_OPCODE_GET_MENU_LANGUAGE: - return CEC_OPCODE_SET_MENU_LANGUAGE; - case CEC_OPCODE_GIVE_DECK_STATUS: - return CEC_OPCODE_DECK_STATUS; - case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: - return CEC_OPCODE_TUNER_DEVICE_STATUS; - case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: - return CEC_OPCODE_DEVICE_VENDOR_ID; - case CEC_OPCODE_GIVE_OSD_NAME: - return CEC_OPCODE_SET_OSD_NAME; - case CEC_OPCODE_MENU_REQUEST: - return CEC_OPCODE_MENU_STATUS; - case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: - return CEC_OPCODE_REPORT_POWER_STATUS; - case CEC_OPCODE_GIVE_AUDIO_STATUS: - return CEC_OPCODE_REPORT_AUDIO_STATUS; - case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: - return CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS; - case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: - return CEC_OPCODE_SET_SYSTEM_AUDIO_MODE; - default: - break; + case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: + return CEC_OPCODE_ACTIVE_SOURCE; + case CEC_OPCODE_GET_CEC_VERSION: + return CEC_OPCODE_CEC_VERSION; + case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: + return CEC_OPCODE_REPORT_PHYSICAL_ADDRESS; + case CEC_OPCODE_GET_MENU_LANGUAGE: + return CEC_OPCODE_SET_MENU_LANGUAGE; + case CEC_OPCODE_GIVE_DECK_STATUS: + return CEC_OPCODE_DECK_STATUS; + case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: + return CEC_OPCODE_TUNER_DEVICE_STATUS; + case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: + return CEC_OPCODE_DEVICE_VENDOR_ID; + case CEC_OPCODE_GIVE_OSD_NAME: + return CEC_OPCODE_SET_OSD_NAME; + case CEC_OPCODE_MENU_REQUEST: + return CEC_OPCODE_MENU_STATUS; + case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: + return CEC_OPCODE_REPORT_POWER_STATUS; + case CEC_OPCODE_GIVE_AUDIO_STATUS: + return CEC_OPCODE_REPORT_AUDIO_STATUS; + case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: + return CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS; + case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: + return CEC_OPCODE_SET_SYSTEM_AUDIO_MODE; + default: + break; } return CEC_OPCODE_NONE; diff --git a/libarmbox/hisilicon.h b/libarmbox/hisilicon.h index 6563348..d13384b 100644 --- a/libarmbox/hisilicon.h +++ b/libarmbox/hisilicon.h @@ -202,8 +202,8 @@ typedef struct hiFORMAT_AUD_INFO_S HI_BOOL bBigEndian; /**< Big endian or little endian. It is valid only for the PCM format */ HI_CHAR aszLanguage[HI_FORMAT_LANG_LEN]; /**< Audio stream language */ HI_U32 u32ExtradataSize; /**< Length of the extended data */ - HI_U8* pu8Extradata; /**< Extended data */ - HI_VOID* pCodecContext; /**< Audio decode context */ + HI_U8 *pu8Extradata; /**< Extended data */ + HI_VOID *pCodecContext; /**< Audio decode context */ HI_U32 u32Role; /**< Role descriptor value of mpeg dash. the most 8 bits is scheme value(refer to HI_FORMAT_ROLE_SCHEME_E), the left 24 bits is descriptor value, the descriptor value may be the bitwise '|' result of value define in HI_FORMAT_ROLE_VALUE_E*/ HI_U32 u32Accessibility; /**< Accessbilitydescriptor value of mpeg dash. the most 8 bits is scheme value(refer to HI_FORMAT_ROLE_SCHEME_E), the left 24 bits is descriptor value, the descriptor value type is number*/ HI_S64 s64Duration; /**< Duration of audio stream, in the unit of ms. */ @@ -226,8 +226,8 @@ typedef struct hiFORMAT_VID_INFO_S HI_U32 u32Reversed; HI_BOOL bEnableTVP; HI_U32 u32ExtradataSize; /**< Length of the extended data */ - HI_U8* pu8Extradata; /**< Extended data */ - HI_VOID* pCodecContext; /**< video decode context */ + HI_U8 *pu8Extradata; /**< Extended data */ + HI_VOID *pCodecContext; /**< video decode context */ HI_U32 u32Role; /**< Role descriptor value of mpeg dash. the most 8 bits is scheme value(refer to HI_FORMAT_ROLE_SCHEME_E), the left 24 bits is descriptor value, the descriptor value may be the bitwise '|' result of value define in HI_FORMAT_ROLE_VALUE_E*/ HI_U32 u32Accessibility; /**< Accessbilitydescriptor value of mpeg dash. the most 8 bits is scheme value(refer to HI_FORMAT_ROLE_SCHEME_E), the left 24 bits is descriptor value, the descriptor value type is number*/ HI_S64 s64Duration; /**< Duration of video stream, in the unit of ms. */ @@ -239,17 +239,17 @@ typedef struct hiFORMAT_SUB_INFO_S HI_S32 s32StreamIndex; /**< Stream index. The invalid value is ::HI_FORMAT_INVALID_STREAM_ID. */ HI_U32 u32Format; /**< Subtitle format, For details about the value definition, see::HI_FORMAT_SUBTITLE_TYPE_E */ HI_U32 u32CharSet; /**< Encoding type of the subtitle, the value range is as follows: - 1. The default value is 0. - 2. The value of the u32CharSet is the identified byte encoding value if the IdentStream byte encoding function (for details about the definition, see hi_charset_common.h) is set. - 3. If the ConvStream function (for details about the definition, see hi_charset_common.h) is set and the invoke interface is called to set the encoding type to be converted by implementing HI_FORMAT_INVOKE_SET_SOURCE_CODETYPE, the value of the u32CharSet is the configured encoding type */ + 1. The default value is 0. + 2. The value of the u32CharSet is the identified byte encoding value if the IdentStream byte encoding function (for details about the definition, see hi_charset_common.h) is set. + 3. If the ConvStream function (for details about the definition, see hi_charset_common.h) is set and the invoke interface is called to set the encoding type to be converted by implementing HI_FORMAT_INVOKE_SET_SOURCE_CODETYPE, the value of the u32CharSet is the configured encoding type */ HI_BOOL bExtSub; /**< Whether subtitles are external subtitles. When bExtSub is HI_TRUE, the subtitles are external. When bExtSub is HI_FALSE, the subtitles are internal. */ HI_U32 u32StreamNum; /**< contains stream number */ HI_CHAR paszLanguage[HI_FORMAT_MAX_LANGUAGE_NUM][HI_FORMAT_LANG_LEN]; /**< Subtitle language */ HI_U16 u16OriginalFrameWidth; /**< Width of the original image */ HI_U16 u16OriginalFrameHeight; /**< Height of the original image */ HI_U32 u32ExtradataSize; /**< Length of the extended data */ - HI_U8* pu8Extradata; /**< Extended data */ - HI_VOID* pCodecContext; /**< Audio decode context */ + HI_U8 *pu8Extradata; /**< Extended data */ + HI_VOID *pCodecContext; /**< Audio decode context */ HI_U32 u32Role; /**< Role descriptor value of mpeg dash. the most 8 bits is scheme value(refer to HI_FORMAT_ROLE_SCHEME_E), the left 24 bits is descriptor value, the descriptor value may be the bitwise '|' result of value define in HI_FORMAT_ROLE_VALUE_E*/ HI_U32 u32Accessibility; /**< Accessibility descriptor value of mpeg dash. the most 8 bits is scheme value(refer to HI_FORMAT_ROLE_SCHEME_E), the left 24 bits is descriptor value, value type is number*/ HI_CHAR paszFileName[HI_FORMAT_MAX_URL_LEN]; /**< File name of external subtitle. */ @@ -258,11 +258,11 @@ typedef struct hiFORMAT_SUB_INFO_S typedef struct hiFORMAT_PROGRAM_INFO_S { HI_U32 u32VidStreamNum; /**< Number of video streams */ - HI_FORMAT_VID_INFO_S* pastVidStream; /**< Video stream information */ + HI_FORMAT_VID_INFO_S *pastVidStream; /**< Video stream information */ HI_U32 u32AudStreamNum; /**< Number of audio streams */ - HI_FORMAT_AUD_INFO_S* pastAudStream; /**< Audio stream information */ + HI_FORMAT_AUD_INFO_S *pastAudStream; /**< Audio stream information */ HI_U32 u32SubStreamNum; /**< Number of subtitles */ - HI_FORMAT_SUB_INFO_S* pastSubStream; /**< Subtitle information */ + HI_FORMAT_SUB_INFO_S *pastSubStream; /**< Subtitle information */ HI_CHAR aszServiceName[HI_FORMAT_SERVICE_DESCRIPT_LEN]; /**< Program service name info */ HI_CHAR aszServiceProvider[HI_FORMAT_SERVICE_DESCRIPT_LEN]; /**< Program service provider info */ HI_S64 s64ProgramDuration; @@ -279,7 +279,7 @@ typedef struct hiFORMAT_FILE_INFO_S HI_U32 u32Bitrate; /**< File bit rate, in the unit of bit/s. */ HI_CHAR aszFileFormat[HI_FORMAT_TITLE_MAX_LEN]; /**< File demuxer info .Not used now*/ HI_U32 u32ProgramNum; /**< Actual number of programs */ - HI_FORMAT_PROGRAM_INFO_S* pastProgramInfo; /**< Program information */ + HI_FORMAT_PROGRAM_INFO_S *pastProgramInfo; /**< Program information */ HI_BOOL bIsDivx; /**< If the stream is DIVX restricted stream,HI_TRUE yes,HI_FALSE no */ HI_BOOL bIsDrmFile; } HI_FORMAT_FILE_INFO_S; diff --git a/libarmbox/init.cpp b/libarmbox/init.cpp index 76190c7..e4e7ef1 100644 --- a/libarmbox/init.cpp +++ b/libarmbox/init.cpp @@ -27,7 +27,7 @@ void hal_api_init() if (!initialized) { cCpuFreqManager f; - f.SetCpuFreq(0); /* CPUFREQ == 0 is the trigger for leaving standby */ + f.SetCpuFreq(0); /* CPUFREQ == 0 is the trigger for leaving standby */ char buffer[64]; sprintf(buffer, "%x", 0); proc_put("/proc/stb/fb/dst_top", buffer, strlen(buffer)); diff --git a/libarmbox/linux-uapi-cec.h b/libarmbox/linux-uapi-cec.h index 851968e..7bcd081 100644 --- a/libarmbox/linux-uapi-cec.h +++ b/libarmbox/linux-uapi-cec.h @@ -44,50 +44,51 @@ #include -#define CEC_MAX_MSG_SIZE 16 +#define CEC_MAX_MSG_SIZE 16 /** * struct cec_msg - CEC message structure. - * @tx_ts: Timestamp in nanoseconds using CLOCK_MONOTONIC. Set by the - * driver when the message transmission has finished. - * @rx_ts: Timestamp in nanoseconds using CLOCK_MONOTONIC. Set by the - * driver when the message was received. - * @len: Length in bytes of the message. - * @timeout: The timeout (in ms) that is used to timeout CEC_RECEIVE. - * Set to 0 if you want to wait forever. This timeout can also be - * used with CEC_TRANSMIT as the timeout for waiting for a reply. - * If 0, then it will use a 1 second timeout instead of waiting - * forever as is done with CEC_RECEIVE. - * @sequence: The framework assigns a sequence number to messages that are - * sent. This can be used to track replies to previously sent - * messages. - * @flags: Set to 0. - * @msg: The message payload. - * @reply: This field is ignored with CEC_RECEIVE and is only used by - * CEC_TRANSMIT. If non-zero, then wait for a reply with this - * opcode. Set to CEC_MSG_FEATURE_ABORT if you want to wait for - * a possible ABORT reply. If there was an error when sending the - * msg or FeatureAbort was returned, then reply is set to 0. - * If reply is non-zero upon return, then len/msg are set to - * the received message. - * If reply is zero upon return and status has the - * CEC_TX_STATUS_FEATURE_ABORT bit set, then len/msg are set to - * the received feature abort message. - * If reply is zero upon return and status has the - * CEC_TX_STATUS_MAX_RETRIES bit set, then no reply was seen at - * all. If reply is non-zero for CEC_TRANSMIT and the message is a - * broadcast, then -EINVAL is returned. - * if reply is non-zero, then timeout is set to 1000 (the required - * maximum response time). - * @rx_status: The message receive status bits. Set by the driver. - * @tx_status: The message transmit status bits. Set by the driver. + * @tx_ts: Timestamp in nanoseconds using CLOCK_MONOTONIC. Set by the + * driver when the message transmission has finished. + * @rx_ts: Timestamp in nanoseconds using CLOCK_MONOTONIC. Set by the + * driver when the message was received. + * @len: Length in bytes of the message. + * @timeout: The timeout (in ms) that is used to timeout CEC_RECEIVE. + * Set to 0 if you want to wait forever. This timeout can also be + * used with CEC_TRANSMIT as the timeout for waiting for a reply. + * If 0, then it will use a 1 second timeout instead of waiting + * forever as is done with CEC_RECEIVE. + * @sequence: The framework assigns a sequence number to messages that are + * sent. This can be used to track replies to previously sent + * messages. + * @flags: Set to 0. + * @msg: The message payload. + * @reply: This field is ignored with CEC_RECEIVE and is only used by + * CEC_TRANSMIT. If non-zero, then wait for a reply with this + * opcode. Set to CEC_MSG_FEATURE_ABORT if you want to wait for + * a possible ABORT reply. If there was an error when sending the + * msg or FeatureAbort was returned, then reply is set to 0. + * If reply is non-zero upon return, then len/msg are set to + * the received message. + * If reply is zero upon return and status has the + * CEC_TX_STATUS_FEATURE_ABORT bit set, then len/msg are set to + * the received feature abort message. + * If reply is zero upon return and status has the + * CEC_TX_STATUS_MAX_RETRIES bit set, then no reply was seen at + * all. If reply is non-zero for CEC_TRANSMIT and the message is a + * broadcast, then -EINVAL is returned. + * if reply is non-zero, then timeout is set to 1000 (the required + * maximum response time). + * @rx_status: The message receive status bits. Set by the driver. + * @tx_status: The message transmit status bits. Set by the driver. * @tx_arb_lost_cnt: The number of 'Arbitration Lost' events. Set by the driver. * @tx_nack_cnt: The number of 'Not Acknowledged' events. Set by the driver. * @tx_low_drive_cnt: The number of 'Low Drive Detected' events. Set by the - * driver. + * driver. * @tx_error_cnt: The number of 'Error' events. Set by the driver. */ -struct cec_msg { +struct cec_msg +{ __u64 tx_ts; __u64 rx_ts; __u32 len; @@ -106,7 +107,7 @@ struct cec_msg { /** * cec_msg_initiator - return the initiator's logical address. - * @msg: the message structure + * @msg: the message structure */ static inline __u8 cec_msg_initiator(const struct cec_msg *msg) { @@ -115,7 +116,7 @@ static inline __u8 cec_msg_initiator(const struct cec_msg *msg) /** * cec_msg_destination - return the destination's logical address. - * @msg: the message structure + * @msg: the message structure */ static inline __u8 cec_msg_destination(const struct cec_msg *msg) { @@ -124,7 +125,7 @@ static inline __u8 cec_msg_destination(const struct cec_msg *msg) /** * cec_msg_opcode - return the opcode of the message, -1 for poll - * @msg: the message structure + * @msg: the message structure */ static inline int cec_msg_opcode(const struct cec_msg *msg) { @@ -133,7 +134,7 @@ static inline int cec_msg_opcode(const struct cec_msg *msg) /** * cec_msg_is_broadcast - return true if this is a broadcast message. - * @msg: the message structure + * @msg: the message structure */ static inline bool cec_msg_is_broadcast(const struct cec_msg *msg) { @@ -142,15 +143,15 @@ static inline bool cec_msg_is_broadcast(const struct cec_msg *msg) /** * cec_msg_init - initialize the message structure. - * @msg: the message structure - * @initiator: the logical address of the initiator + * @msg: the message structure + * @initiator: the logical address of the initiator * @destination:the logical address of the destination (0xf for broadcast) * * The whole structure is zeroed, the len field is set to 1 (i.e. a poll * message) and the initiator and destination are filled in. */ static inline void cec_msg_init(struct cec_msg *msg, - __u8 initiator, __u8 destination) + __u8 initiator, __u8 destination) { memset(msg, 0, sizeof(*msg)); msg->msg[0] = (initiator << 4) | destination; @@ -159,33 +160,33 @@ static inline void cec_msg_init(struct cec_msg *msg, /** * cec_msg_set_reply_to - fill in destination/initiator in a reply message. - * @msg: the message structure for the reply - * @orig: the original message structure + * @msg: the message structure for the reply + * @orig: the original message structure * * Set the msg destination to the orig initiator and the msg initiator to the * orig destination. Note that msg and orig may be the same pointer, in which * case the change is done in place. */ static inline void cec_msg_set_reply_to(struct cec_msg *msg, - struct cec_msg *orig) + struct cec_msg *orig) { /* The destination becomes the initiator and vice versa */ msg->msg[0] = (cec_msg_destination(orig) << 4) | - cec_msg_initiator(orig); + cec_msg_initiator(orig); msg->reply = msg->timeout = 0; } /* cec status field */ -#define CEC_TX_STATUS_OK (1 << 0) -#define CEC_TX_STATUS_ARB_LOST (1 << 1) -#define CEC_TX_STATUS_NACK (1 << 2) -#define CEC_TX_STATUS_LOW_DRIVE (1 << 3) -#define CEC_TX_STATUS_ERROR (1 << 4) -#define CEC_TX_STATUS_MAX_RETRIES (1 << 5) +#define CEC_TX_STATUS_OK (1 << 0) +#define CEC_TX_STATUS_ARB_LOST (1 << 1) +#define CEC_TX_STATUS_NACK (1 << 2) +#define CEC_TX_STATUS_LOW_DRIVE (1 << 3) +#define CEC_TX_STATUS_ERROR (1 << 4) +#define CEC_TX_STATUS_MAX_RETRIES (1 << 5) -#define CEC_RX_STATUS_OK (1 << 0) -#define CEC_RX_STATUS_TIMEOUT (1 << 1) -#define CEC_RX_STATUS_FEATURE_ABORT (1 << 2) +#define CEC_RX_STATUS_OK (1 << 0) +#define CEC_RX_STATUS_TIMEOUT (1 << 1) +#define CEC_RX_STATUS_FEATURE_ABORT (1 << 2) static inline bool cec_msg_status_is_ok(const struct cec_msg *msg) { @@ -198,8 +199,8 @@ static inline bool cec_msg_status_is_ok(const struct cec_msg *msg) return !(msg->rx_status & CEC_RX_STATUS_FEATURE_ABORT); } -#define CEC_LOG_ADDR_INVALID 0xff -#define CEC_PHYS_ADDR_INVALID 0xffff +#define CEC_LOG_ADDR_INVALID 0xff +#define CEC_PHYS_ADDR_INVALID 0xffff /* * The maximum number of logical addresses one device can be assigned to. @@ -209,53 +210,53 @@ static inline bool cec_msg_status_is_ok(const struct cec_msg *msg) #define CEC_MAX_LOG_ADDRS 4 /* The logical addresses defined by CEC 2.0 */ -#define CEC_LOG_ADDR_TV 0 -#define CEC_LOG_ADDR_RECORD_1 1 -#define CEC_LOG_ADDR_RECORD_2 2 -#define CEC_LOG_ADDR_TUNER_1 3 -#define CEC_LOG_ADDR_PLAYBACK_1 4 -#define CEC_LOG_ADDR_AUDIOSYSTEM 5 -#define CEC_LOG_ADDR_TUNER_2 6 -#define CEC_LOG_ADDR_TUNER_3 7 -#define CEC_LOG_ADDR_PLAYBACK_2 8 -#define CEC_LOG_ADDR_RECORD_3 9 -#define CEC_LOG_ADDR_TUNER_4 10 -#define CEC_LOG_ADDR_PLAYBACK_3 11 -#define CEC_LOG_ADDR_BACKUP_1 12 -#define CEC_LOG_ADDR_BACKUP_2 13 -#define CEC_LOG_ADDR_SPECIFIC 14 -#define CEC_LOG_ADDR_UNREGISTERED 15 /* as initiator address */ -#define CEC_LOG_ADDR_BROADCAST 15 /* ad destination address */ +#define CEC_LOG_ADDR_TV 0 +#define CEC_LOG_ADDR_RECORD_1 1 +#define CEC_LOG_ADDR_RECORD_2 2 +#define CEC_LOG_ADDR_TUNER_1 3 +#define CEC_LOG_ADDR_PLAYBACK_1 4 +#define CEC_LOG_ADDR_AUDIOSYSTEM 5 +#define CEC_LOG_ADDR_TUNER_2 6 +#define CEC_LOG_ADDR_TUNER_3 7 +#define CEC_LOG_ADDR_PLAYBACK_2 8 +#define CEC_LOG_ADDR_RECORD_3 9 +#define CEC_LOG_ADDR_TUNER_4 10 +#define CEC_LOG_ADDR_PLAYBACK_3 11 +#define CEC_LOG_ADDR_BACKUP_1 12 +#define CEC_LOG_ADDR_BACKUP_2 13 +#define CEC_LOG_ADDR_SPECIFIC 14 +#define CEC_LOG_ADDR_UNREGISTERED 15 /* as initiator address */ +#define CEC_LOG_ADDR_BROADCAST 15 /* ad destination address */ /* The logical address types that the CEC device wants to claim */ -#define CEC_LOG_ADDR_TYPE_TV 0 -#define CEC_LOG_ADDR_TYPE_RECORD 1 -#define CEC_LOG_ADDR_TYPE_TUNER 2 -#define CEC_LOG_ADDR_TYPE_PLAYBACK 3 -#define CEC_LOG_ADDR_TYPE_AUDIOSYSTEM 4 -#define CEC_LOG_ADDR_TYPE_SPECIFIC 5 -#define CEC_LOG_ADDR_TYPE_UNREGISTERED 6 +#define CEC_LOG_ADDR_TYPE_TV 0 +#define CEC_LOG_ADDR_TYPE_RECORD 1 +#define CEC_LOG_ADDR_TYPE_TUNER 2 +#define CEC_LOG_ADDR_TYPE_PLAYBACK 3 +#define CEC_LOG_ADDR_TYPE_AUDIOSYSTEM 4 +#define CEC_LOG_ADDR_TYPE_SPECIFIC 5 +#define CEC_LOG_ADDR_TYPE_UNREGISTERED 6 /* * Switches should use UNREGISTERED. * Processors should use SPECIFIC. */ -#define CEC_LOG_ADDR_MASK_TV (1 << CEC_LOG_ADDR_TV) -#define CEC_LOG_ADDR_MASK_RECORD ((1 << CEC_LOG_ADDR_RECORD_1) | \ - (1 << CEC_LOG_ADDR_RECORD_2) | \ - (1 << CEC_LOG_ADDR_RECORD_3)) -#define CEC_LOG_ADDR_MASK_TUNER ((1 << CEC_LOG_ADDR_TUNER_1) | \ - (1 << CEC_LOG_ADDR_TUNER_2) | \ - (1 << CEC_LOG_ADDR_TUNER_3) | \ - (1 << CEC_LOG_ADDR_TUNER_4)) -#define CEC_LOG_ADDR_MASK_PLAYBACK ((1 << CEC_LOG_ADDR_PLAYBACK_1) | \ - (1 << CEC_LOG_ADDR_PLAYBACK_2) | \ - (1 << CEC_LOG_ADDR_PLAYBACK_3)) -#define CEC_LOG_ADDR_MASK_AUDIOSYSTEM (1 << CEC_LOG_ADDR_AUDIOSYSTEM) -#define CEC_LOG_ADDR_MASK_BACKUP ((1 << CEC_LOG_ADDR_BACKUP_1) | \ - (1 << CEC_LOG_ADDR_BACKUP_2)) -#define CEC_LOG_ADDR_MASK_SPECIFIC (1 << CEC_LOG_ADDR_SPECIFIC) -#define CEC_LOG_ADDR_MASK_UNREGISTERED (1 << CEC_LOG_ADDR_UNREGISTERED) +#define CEC_LOG_ADDR_MASK_TV (1 << CEC_LOG_ADDR_TV) +#define CEC_LOG_ADDR_MASK_RECORD ((1 << CEC_LOG_ADDR_RECORD_1) | \ + (1 << CEC_LOG_ADDR_RECORD_2) | \ + (1 << CEC_LOG_ADDR_RECORD_3)) +#define CEC_LOG_ADDR_MASK_TUNER ((1 << CEC_LOG_ADDR_TUNER_1) | \ + (1 << CEC_LOG_ADDR_TUNER_2) | \ + (1 << CEC_LOG_ADDR_TUNER_3) | \ + (1 << CEC_LOG_ADDR_TUNER_4)) +#define CEC_LOG_ADDR_MASK_PLAYBACK ((1 << CEC_LOG_ADDR_PLAYBACK_1) | \ + (1 << CEC_LOG_ADDR_PLAYBACK_2) | \ + (1 << CEC_LOG_ADDR_PLAYBACK_3)) +#define CEC_LOG_ADDR_MASK_AUDIOSYSTEM (1 << CEC_LOG_ADDR_AUDIOSYSTEM) +#define CEC_LOG_ADDR_MASK_BACKUP ((1 << CEC_LOG_ADDR_BACKUP_1) | \ + (1 << CEC_LOG_ADDR_BACKUP_2)) +#define CEC_LOG_ADDR_MASK_SPECIFIC (1 << CEC_LOG_ADDR_SPECIFIC) +#define CEC_LOG_ADDR_MASK_UNREGISTERED (1 << CEC_LOG_ADDR_UNREGISTERED) static inline bool cec_has_tv(__u16 log_addr_mask) { @@ -306,38 +307,38 @@ static inline bool cec_is_unconfigured(__u16 log_addr_mask) * Use this if there is no vendor ID (CEC_G_VENDOR_ID) or if the vendor ID * should be disabled (CEC_S_VENDOR_ID) */ -#define CEC_VENDOR_ID_NONE 0xffffffff +#define CEC_VENDOR_ID_NONE 0xffffffff /* The message handling modes */ /* Modes for initiator */ -#define CEC_MODE_NO_INITIATOR (0x0 << 0) -#define CEC_MODE_INITIATOR (0x1 << 0) -#define CEC_MODE_EXCL_INITIATOR (0x2 << 0) -#define CEC_MODE_INITIATOR_MSK 0x0f +#define CEC_MODE_NO_INITIATOR (0x0 << 0) +#define CEC_MODE_INITIATOR (0x1 << 0) +#define CEC_MODE_EXCL_INITIATOR (0x2 << 0) +#define CEC_MODE_INITIATOR_MSK 0x0f /* Modes for follower */ -#define CEC_MODE_NO_FOLLOWER (0x0 << 4) -#define CEC_MODE_FOLLOWER (0x1 << 4) -#define CEC_MODE_EXCL_FOLLOWER (0x2 << 4) -#define CEC_MODE_EXCL_FOLLOWER_PASSTHRU (0x3 << 4) -#define CEC_MODE_MONITOR (0xe << 4) -#define CEC_MODE_MONITOR_ALL (0xf << 4) -#define CEC_MODE_FOLLOWER_MSK 0xf0 +#define CEC_MODE_NO_FOLLOWER (0x0 << 4) +#define CEC_MODE_FOLLOWER (0x1 << 4) +#define CEC_MODE_EXCL_FOLLOWER (0x2 << 4) +#define CEC_MODE_EXCL_FOLLOWER_PASSTHRU (0x3 << 4) +#define CEC_MODE_MONITOR (0xe << 4) +#define CEC_MODE_MONITOR_ALL (0xf << 4) +#define CEC_MODE_FOLLOWER_MSK 0xf0 /* Userspace has to configure the physical address */ -#define CEC_CAP_PHYS_ADDR (1 << 0) +#define CEC_CAP_PHYS_ADDR (1 << 0) /* Userspace has to configure the logical addresses */ -#define CEC_CAP_LOG_ADDRS (1 << 1) +#define CEC_CAP_LOG_ADDRS (1 << 1) /* Userspace can transmit messages (and thus become follower as well) */ -#define CEC_CAP_TRANSMIT (1 << 2) +#define CEC_CAP_TRANSMIT (1 << 2) /* * Passthrough all messages instead of processing them. */ -#define CEC_CAP_PASSTHROUGH (1 << 3) +#define CEC_CAP_PASSTHROUGH (1 << 3) /* Supports remote control */ -#define CEC_CAP_RC (1 << 4) +#define CEC_CAP_RC (1 << 4) /* Hardware can monitor all messages, not just directed and broadcast. */ -#define CEC_CAP_MONITOR_ALL (1 << 5) +#define CEC_CAP_MONITOR_ALL (1 << 5) /** * struct cec_caps - CEC capabilities structure. @@ -347,7 +348,8 @@ static inline bool cec_is_unconfigured(__u16 log_addr_mask) * @capabilities: capabilities of the CEC adapter. * @version: version of the CEC adapter framework. */ -struct cec_caps { +struct cec_caps +{ char driver[32]; char name[32]; __u32 available_log_addrs; @@ -360,20 +362,21 @@ struct cec_caps { * @log_addr: the claimed logical addresses. Set by the driver. * @log_addr_mask: current logical address mask. Set by the driver. * @cec_version: the CEC version that the adapter should implement. Set by the - * caller. + * caller. * @num_log_addrs: how many logical addresses should be claimed. Set by the - * caller. + * caller. * @vendor_id: the vendor ID of the device. Set by the caller. * @flags: flags. * @osd_name: the OSD name of the device. Set by the caller. * @primary_device_type: the primary device type for each logical address. - * Set by the caller. + * Set by the caller. * @log_addr_type: the logical address types. Set by the caller. * @all_device_types: CEC 2.0: all device types represented by the logical - * address. Set by the caller. - * @features: CEC 2.0: The logical address features. Set by the caller. + * address. Set by the caller. + * @features: CEC 2.0: The logical address features. Set by the caller. */ -struct cec_log_addrs { +struct cec_log_addrs +{ __u8 log_addr[CEC_MAX_LOG_ADDRS]; __u16 log_addr_mask; __u8 cec_version; @@ -390,26 +393,27 @@ struct cec_log_addrs { }; /* Allow a fallback to unregistered */ -#define CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK (1 << 0) +#define CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK (1 << 0) /* Events */ /* Event that occurs when the adapter state changes */ -#define CEC_EVENT_STATE_CHANGE 1 +#define CEC_EVENT_STATE_CHANGE 1 /* * This event is sent when messages are lost because the application * didn't empty the message queue in time */ -#define CEC_EVENT_LOST_MSGS 2 +#define CEC_EVENT_LOST_MSGS 2 -#define CEC_EVENT_FL_INITIAL_STATE (1 << 0) +#define CEC_EVENT_FL_INITIAL_STATE (1 << 0) /** * struct cec_event_state_change - used when the CEC adapter changes state. * @phys_addr: the current physical address * @log_addr_mask: the current logical address mask */ -struct cec_event_state_change { +struct cec_event_state_change +{ __u16 phys_addr; __u16 log_addr_mask; }; @@ -418,7 +422,8 @@ struct cec_event_state_change { * struct cec_event_lost_msgs - tells you how many messages were lost due. * @lost_msgs: how many messages were lost. */ -struct cec_event_lost_msgs { +struct cec_event_lost_msgs +{ __u32 lost_msgs; }; @@ -431,11 +436,13 @@ struct cec_event_lost_msgs { * @lost_msgs: the event payload for CEC_EVENT_LOST_MSGS. * @raw: array to pad the union. */ -struct cec_event { +struct cec_event +{ __u64 ts; __u32 event; __u32 flags; - union { + union + { struct cec_event_state_change state_change; struct cec_event_lost_msgs lost_msgs; __u32 raw[16]; @@ -445,7 +452,7 @@ struct cec_event { /* ioctls */ /* Adapter capabilities */ -#define CEC_ADAP_G_CAPS _IOWR('a', 0, struct cec_caps) +#define CEC_ADAP_G_CAPS _IOWR('a', 0, struct cec_caps) /* * phys_addr is either 0 (if this is the CEC root device) @@ -459,8 +466,8 @@ struct cec_event { * The CEC_ADAP_S_PHYS_ADDR ioctl may not be available if that is handled * internally. */ -#define CEC_ADAP_G_PHYS_ADDR _IOR('a', 1, __u16) -#define CEC_ADAP_S_PHYS_ADDR _IOW('a', 2, __u16) +#define CEC_ADAP_G_PHYS_ADDR _IOR('a', 1, __u16) +#define CEC_ADAP_S_PHYS_ADDR _IOW('a', 2, __u16) /* * Configure the CEC adapter. It sets the device type and which @@ -470,21 +477,21 @@ struct cec_event { * is no physical address assigned. */ -#define CEC_ADAP_G_LOG_ADDRS _IOR('a', 3, struct cec_log_addrs) -#define CEC_ADAP_S_LOG_ADDRS _IOWR('a', 4, struct cec_log_addrs) +#define CEC_ADAP_G_LOG_ADDRS _IOR('a', 3, struct cec_log_addrs) +#define CEC_ADAP_S_LOG_ADDRS _IOWR('a', 4, struct cec_log_addrs) /* Transmit/receive a CEC command */ -#define CEC_TRANSMIT _IOWR('a', 5, struct cec_msg) -#define CEC_RECEIVE _IOWR('a', 6, struct cec_msg) +#define CEC_TRANSMIT _IOWR('a', 5, struct cec_msg) +#define CEC_RECEIVE _IOWR('a', 6, struct cec_msg) /* Dequeue CEC events */ -#define CEC_DQEVENT _IOWR('a', 7, struct cec_event) +#define CEC_DQEVENT _IOWR('a', 7, struct cec_event) /* * Get and set the message handling mode for this filehandle. */ -#define CEC_G_MODE _IOR('a', 8, __u32) -#define CEC_S_MODE _IOW('a', 9, __u32) +#define CEC_G_MODE _IOR('a', 8, __u32) +#define CEC_S_MODE _IOW('a', 9, __u32) /* * The remainder of this header defines all CEC messages and operands. @@ -504,511 +511,511 @@ struct cec_event { /* Messages */ /* One Touch Play Feature */ -#define CEC_MSG_ACTIVE_SOURCE 0x82 -#define CEC_MSG_IMAGE_VIEW_ON 0x04 -#define CEC_MSG_TEXT_VIEW_ON 0x0d +#define CEC_MSG_ACTIVE_SOURCE 0x82 +#define CEC_MSG_IMAGE_VIEW_ON 0x04 +#define CEC_MSG_TEXT_VIEW_ON 0x0d /* Routing Control Feature */ /* * Has also: - * CEC_MSG_ACTIVE_SOURCE + * CEC_MSG_ACTIVE_SOURCE */ -#define CEC_MSG_INACTIVE_SOURCE 0x9d -#define CEC_MSG_REQUEST_ACTIVE_SOURCE 0x85 -#define CEC_MSG_ROUTING_CHANGE 0x80 -#define CEC_MSG_ROUTING_INFORMATION 0x81 -#define CEC_MSG_SET_STREAM_PATH 0x86 +#define CEC_MSG_INACTIVE_SOURCE 0x9d +#define CEC_MSG_REQUEST_ACTIVE_SOURCE 0x85 +#define CEC_MSG_ROUTING_CHANGE 0x80 +#define CEC_MSG_ROUTING_INFORMATION 0x81 +#define CEC_MSG_SET_STREAM_PATH 0x86 /* Standby Feature */ -#define CEC_MSG_STANDBY 0x36 +#define CEC_MSG_STANDBY 0x36 /* One Touch Record Feature */ -#define CEC_MSG_RECORD_OFF 0x0b -#define CEC_MSG_RECORD_ON 0x09 +#define CEC_MSG_RECORD_OFF 0x0b +#define CEC_MSG_RECORD_ON 0x09 /* Record Source Type Operand (rec_src_type) */ -#define CEC_OP_RECORD_SRC_OWN 1 -#define CEC_OP_RECORD_SRC_DIGITAL 2 -#define CEC_OP_RECORD_SRC_ANALOG 3 -#define CEC_OP_RECORD_SRC_EXT_PLUG 4 -#define CEC_OP_RECORD_SRC_EXT_PHYS_ADDR 5 +#define CEC_OP_RECORD_SRC_OWN 1 +#define CEC_OP_RECORD_SRC_DIGITAL 2 +#define CEC_OP_RECORD_SRC_ANALOG 3 +#define CEC_OP_RECORD_SRC_EXT_PLUG 4 +#define CEC_OP_RECORD_SRC_EXT_PHYS_ADDR 5 /* Service Identification Method Operand (service_id_method) */ -#define CEC_OP_SERVICE_ID_METHOD_BY_DIG_ID 0 -#define CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL 1 +#define CEC_OP_SERVICE_ID_METHOD_BY_DIG_ID 0 +#define CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL 1 /* Digital Service Broadcast System Operand (dig_bcast_system) */ -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_GEN 0x00 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_GEN 0x01 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_GEN 0x02 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_BS 0x08 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_CS 0x09 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_T 0x0a -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_CABLE 0x10 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_SAT 0x11 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_T 0x12 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_C 0x18 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_S 0x19 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_S2 0x1a -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_T 0x1b +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_GEN 0x00 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_GEN 0x01 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_GEN 0x02 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_BS 0x08 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_CS 0x09 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_T 0x0a +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_CABLE 0x10 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_SAT 0x11 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_T 0x12 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_C 0x18 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_S 0x19 +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_S2 0x1a +#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_T 0x1b /* Analogue Broadcast Type Operand (ana_bcast_type) */ -#define CEC_OP_ANA_BCAST_TYPE_CABLE 0 -#define CEC_OP_ANA_BCAST_TYPE_SATELLITE 1 -#define CEC_OP_ANA_BCAST_TYPE_TERRESTRIAL 2 +#define CEC_OP_ANA_BCAST_TYPE_CABLE 0 +#define CEC_OP_ANA_BCAST_TYPE_SATELLITE 1 +#define CEC_OP_ANA_BCAST_TYPE_TERRESTRIAL 2 /* Broadcast System Operand (bcast_system) */ -#define CEC_OP_BCAST_SYSTEM_PAL_BG 0x00 -#define CEC_OP_BCAST_SYSTEM_SECAM_LQ 0x01 /* SECAM L' */ -#define CEC_OP_BCAST_SYSTEM_PAL_M 0x02 -#define CEC_OP_BCAST_SYSTEM_NTSC_M 0x03 -#define CEC_OP_BCAST_SYSTEM_PAL_I 0x04 -#define CEC_OP_BCAST_SYSTEM_SECAM_DK 0x05 -#define CEC_OP_BCAST_SYSTEM_SECAM_BG 0x06 -#define CEC_OP_BCAST_SYSTEM_SECAM_L 0x07 -#define CEC_OP_BCAST_SYSTEM_PAL_DK 0x08 -#define CEC_OP_BCAST_SYSTEM_OTHER 0x1f +#define CEC_OP_BCAST_SYSTEM_PAL_BG 0x00 +#define CEC_OP_BCAST_SYSTEM_SECAM_LQ 0x01 /* SECAM L' */ +#define CEC_OP_BCAST_SYSTEM_PAL_M 0x02 +#define CEC_OP_BCAST_SYSTEM_NTSC_M 0x03 +#define CEC_OP_BCAST_SYSTEM_PAL_I 0x04 +#define CEC_OP_BCAST_SYSTEM_SECAM_DK 0x05 +#define CEC_OP_BCAST_SYSTEM_SECAM_BG 0x06 +#define CEC_OP_BCAST_SYSTEM_SECAM_L 0x07 +#define CEC_OP_BCAST_SYSTEM_PAL_DK 0x08 +#define CEC_OP_BCAST_SYSTEM_OTHER 0x1f /* Channel Number Format Operand (channel_number_fmt) */ -#define CEC_OP_CHANNEL_NUMBER_FMT_1_PART 0x01 -#define CEC_OP_CHANNEL_NUMBER_FMT_2_PART 0x02 +#define CEC_OP_CHANNEL_NUMBER_FMT_1_PART 0x01 +#define CEC_OP_CHANNEL_NUMBER_FMT_2_PART 0x02 -#define CEC_MSG_RECORD_STATUS 0x0a +#define CEC_MSG_RECORD_STATUS 0x0a /* Record Status Operand (rec_status) */ -#define CEC_OP_RECORD_STATUS_CUR_SRC 0x01 -#define CEC_OP_RECORD_STATUS_DIG_SERVICE 0x02 -#define CEC_OP_RECORD_STATUS_ANA_SERVICE 0x03 -#define CEC_OP_RECORD_STATUS_EXT_INPUT 0x04 -#define CEC_OP_RECORD_STATUS_NO_DIG_SERVICE 0x05 -#define CEC_OP_RECORD_STATUS_NO_ANA_SERVICE 0x06 -#define CEC_OP_RECORD_STATUS_NO_SERVICE 0x07 -#define CEC_OP_RECORD_STATUS_INVALID_EXT_PLUG 0x09 -#define CEC_OP_RECORD_STATUS_INVALID_EXT_PHYS_ADDR 0x0a -#define CEC_OP_RECORD_STATUS_UNSUP_CA 0x0b -#define CEC_OP_RECORD_STATUS_NO_CA_ENTITLEMENTS 0x0c -#define CEC_OP_RECORD_STATUS_CANT_COPY_SRC 0x0d -#define CEC_OP_RECORD_STATUS_NO_MORE_COPIES 0x0e -#define CEC_OP_RECORD_STATUS_NO_MEDIA 0x10 -#define CEC_OP_RECORD_STATUS_PLAYING 0x11 -#define CEC_OP_RECORD_STATUS_ALREADY_RECORDING 0x12 -#define CEC_OP_RECORD_STATUS_MEDIA_PROT 0x13 -#define CEC_OP_RECORD_STATUS_NO_SIGNAL 0x14 -#define CEC_OP_RECORD_STATUS_MEDIA_PROBLEM 0x15 -#define CEC_OP_RECORD_STATUS_NO_SPACE 0x16 -#define CEC_OP_RECORD_STATUS_PARENTAL_LOCK 0x17 -#define CEC_OP_RECORD_STATUS_TERMINATED_OK 0x1a -#define CEC_OP_RECORD_STATUS_ALREADY_TERM 0x1b -#define CEC_OP_RECORD_STATUS_OTHER 0x1f +#define CEC_OP_RECORD_STATUS_CUR_SRC 0x01 +#define CEC_OP_RECORD_STATUS_DIG_SERVICE 0x02 +#define CEC_OP_RECORD_STATUS_ANA_SERVICE 0x03 +#define CEC_OP_RECORD_STATUS_EXT_INPUT 0x04 +#define CEC_OP_RECORD_STATUS_NO_DIG_SERVICE 0x05 +#define CEC_OP_RECORD_STATUS_NO_ANA_SERVICE 0x06 +#define CEC_OP_RECORD_STATUS_NO_SERVICE 0x07 +#define CEC_OP_RECORD_STATUS_INVALID_EXT_PLUG 0x09 +#define CEC_OP_RECORD_STATUS_INVALID_EXT_PHYS_ADDR 0x0a +#define CEC_OP_RECORD_STATUS_UNSUP_CA 0x0b +#define CEC_OP_RECORD_STATUS_NO_CA_ENTITLEMENTS 0x0c +#define CEC_OP_RECORD_STATUS_CANT_COPY_SRC 0x0d +#define CEC_OP_RECORD_STATUS_NO_MORE_COPIES 0x0e +#define CEC_OP_RECORD_STATUS_NO_MEDIA 0x10 +#define CEC_OP_RECORD_STATUS_PLAYING 0x11 +#define CEC_OP_RECORD_STATUS_ALREADY_RECORDING 0x12 +#define CEC_OP_RECORD_STATUS_MEDIA_PROT 0x13 +#define CEC_OP_RECORD_STATUS_NO_SIGNAL 0x14 +#define CEC_OP_RECORD_STATUS_MEDIA_PROBLEM 0x15 +#define CEC_OP_RECORD_STATUS_NO_SPACE 0x16 +#define CEC_OP_RECORD_STATUS_PARENTAL_LOCK 0x17 +#define CEC_OP_RECORD_STATUS_TERMINATED_OK 0x1a +#define CEC_OP_RECORD_STATUS_ALREADY_TERM 0x1b +#define CEC_OP_RECORD_STATUS_OTHER 0x1f -#define CEC_MSG_RECORD_TV_SCREEN 0x0f +#define CEC_MSG_RECORD_TV_SCREEN 0x0f /* Timer Programming Feature */ -#define CEC_MSG_CLEAR_ANALOGUE_TIMER 0x33 +#define CEC_MSG_CLEAR_ANALOGUE_TIMER 0x33 /* Recording Sequence Operand (recording_seq) */ -#define CEC_OP_REC_SEQ_SUNDAY 0x01 -#define CEC_OP_REC_SEQ_MONDAY 0x02 -#define CEC_OP_REC_SEQ_TUESDAY 0x04 -#define CEC_OP_REC_SEQ_WEDNESDAY 0x08 -#define CEC_OP_REC_SEQ_THURSDAY 0x10 -#define CEC_OP_REC_SEQ_FRIDAY 0x20 -#define CEC_OP_REC_SEQ_SATERDAY 0x40 -#define CEC_OP_REC_SEQ_ONCE_ONLY 0x00 +#define CEC_OP_REC_SEQ_SUNDAY 0x01 +#define CEC_OP_REC_SEQ_MONDAY 0x02 +#define CEC_OP_REC_SEQ_TUESDAY 0x04 +#define CEC_OP_REC_SEQ_WEDNESDAY 0x08 +#define CEC_OP_REC_SEQ_THURSDAY 0x10 +#define CEC_OP_REC_SEQ_FRIDAY 0x20 +#define CEC_OP_REC_SEQ_SATERDAY 0x40 +#define CEC_OP_REC_SEQ_ONCE_ONLY 0x00 -#define CEC_MSG_CLEAR_DIGITAL_TIMER 0x99 +#define CEC_MSG_CLEAR_DIGITAL_TIMER 0x99 -#define CEC_MSG_CLEAR_EXT_TIMER 0xa1 +#define CEC_MSG_CLEAR_EXT_TIMER 0xa1 /* External Source Specifier Operand (ext_src_spec) */ -#define CEC_OP_EXT_SRC_PLUG 0x04 -#define CEC_OP_EXT_SRC_PHYS_ADDR 0x05 +#define CEC_OP_EXT_SRC_PLUG 0x04 +#define CEC_OP_EXT_SRC_PHYS_ADDR 0x05 -#define CEC_MSG_SET_ANALOGUE_TIMER 0x34 -#define CEC_MSG_SET_DIGITAL_TIMER 0x97 -#define CEC_MSG_SET_EXT_TIMER 0xa2 +#define CEC_MSG_SET_ANALOGUE_TIMER 0x34 +#define CEC_MSG_SET_DIGITAL_TIMER 0x97 +#define CEC_MSG_SET_EXT_TIMER 0xa2 -#define CEC_MSG_SET_TIMER_PROGRAM_TITLE 0x67 -#define CEC_MSG_TIMER_CLEARED_STATUS 0x43 +#define CEC_MSG_SET_TIMER_PROGRAM_TITLE 0x67 +#define CEC_MSG_TIMER_CLEARED_STATUS 0x43 /* Timer Cleared Status Data Operand (timer_cleared_status) */ -#define CEC_OP_TIMER_CLR_STAT_RECORDING 0x00 -#define CEC_OP_TIMER_CLR_STAT_NO_MATCHING 0x01 -#define CEC_OP_TIMER_CLR_STAT_NO_INFO 0x02 -#define CEC_OP_TIMER_CLR_STAT_CLEARED 0x80 +#define CEC_OP_TIMER_CLR_STAT_RECORDING 0x00 +#define CEC_OP_TIMER_CLR_STAT_NO_MATCHING 0x01 +#define CEC_OP_TIMER_CLR_STAT_NO_INFO 0x02 +#define CEC_OP_TIMER_CLR_STAT_CLEARED 0x80 -#define CEC_MSG_TIMER_STATUS 0x35 +#define CEC_MSG_TIMER_STATUS 0x35 /* Timer Overlap Warning Operand (timer_overlap_warning) */ -#define CEC_OP_TIMER_OVERLAP_WARNING_NO_OVERLAP 0 -#define CEC_OP_TIMER_OVERLAP_WARNING_OVERLAP 1 +#define CEC_OP_TIMER_OVERLAP_WARNING_NO_OVERLAP 0 +#define CEC_OP_TIMER_OVERLAP_WARNING_OVERLAP 1 /* Media Info Operand (media_info) */ -#define CEC_OP_MEDIA_INFO_UNPROT_MEDIA 0 -#define CEC_OP_MEDIA_INFO_PROT_MEDIA 1 -#define CEC_OP_MEDIA_INFO_NO_MEDIA 2 +#define CEC_OP_MEDIA_INFO_UNPROT_MEDIA 0 +#define CEC_OP_MEDIA_INFO_PROT_MEDIA 1 +#define CEC_OP_MEDIA_INFO_NO_MEDIA 2 /* Programmed Indicator Operand (prog_indicator) */ -#define CEC_OP_PROG_IND_NOT_PROGRAMMED 0 -#define CEC_OP_PROG_IND_PROGRAMMED 1 +#define CEC_OP_PROG_IND_NOT_PROGRAMMED 0 +#define CEC_OP_PROG_IND_PROGRAMMED 1 /* Programmed Info Operand (prog_info) */ -#define CEC_OP_PROG_INFO_ENOUGH_SPACE 0x08 -#define CEC_OP_PROG_INFO_NOT_ENOUGH_SPACE 0x09 -#define CEC_OP_PROG_INFO_MIGHT_NOT_BE_ENOUGH_SPACE 0x0b -#define CEC_OP_PROG_INFO_NONE_AVAILABLE 0x0a +#define CEC_OP_PROG_INFO_ENOUGH_SPACE 0x08 +#define CEC_OP_PROG_INFO_NOT_ENOUGH_SPACE 0x09 +#define CEC_OP_PROG_INFO_MIGHT_NOT_BE_ENOUGH_SPACE 0x0b +#define CEC_OP_PROG_INFO_NONE_AVAILABLE 0x0a /* Not Programmed Error Info Operand (prog_error) */ -#define CEC_OP_PROG_ERROR_NO_FREE_TIMER 0x01 -#define CEC_OP_PROG_ERROR_DATE_OUT_OF_RANGE 0x02 -#define CEC_OP_PROG_ERROR_REC_SEQ_ERROR 0x03 -#define CEC_OP_PROG_ERROR_INV_EXT_PLUG 0x04 -#define CEC_OP_PROG_ERROR_INV_EXT_PHYS_ADDR 0x05 -#define CEC_OP_PROG_ERROR_CA_UNSUPP 0x06 -#define CEC_OP_PROG_ERROR_INSUF_CA_ENTITLEMENTS 0x07 -#define CEC_OP_PROG_ERROR_RESOLUTION_UNSUPP 0x08 -#define CEC_OP_PROG_ERROR_PARENTAL_LOCK 0x09 -#define CEC_OP_PROG_ERROR_CLOCK_FAILURE 0x0a -#define CEC_OP_PROG_ERROR_DUPLICATE 0x0e +#define CEC_OP_PROG_ERROR_NO_FREE_TIMER 0x01 +#define CEC_OP_PROG_ERROR_DATE_OUT_OF_RANGE 0x02 +#define CEC_OP_PROG_ERROR_REC_SEQ_ERROR 0x03 +#define CEC_OP_PROG_ERROR_INV_EXT_PLUG 0x04 +#define CEC_OP_PROG_ERROR_INV_EXT_PHYS_ADDR 0x05 +#define CEC_OP_PROG_ERROR_CA_UNSUPP 0x06 +#define CEC_OP_PROG_ERROR_INSUF_CA_ENTITLEMENTS 0x07 +#define CEC_OP_PROG_ERROR_RESOLUTION_UNSUPP 0x08 +#define CEC_OP_PROG_ERROR_PARENTAL_LOCK 0x09 +#define CEC_OP_PROG_ERROR_CLOCK_FAILURE 0x0a +#define CEC_OP_PROG_ERROR_DUPLICATE 0x0e /* System Information Feature */ -#define CEC_MSG_CEC_VERSION 0x9e +#define CEC_MSG_CEC_VERSION 0x9e /* CEC Version Operand (cec_version) */ -#define CEC_OP_CEC_VERSION_1_3A 4 -#define CEC_OP_CEC_VERSION_1_4 5 -#define CEC_OP_CEC_VERSION_2_0 6 +#define CEC_OP_CEC_VERSION_1_3A 4 +#define CEC_OP_CEC_VERSION_1_4 5 +#define CEC_OP_CEC_VERSION_2_0 6 -#define CEC_MSG_GET_CEC_VERSION 0x9f -#define CEC_MSG_GIVE_PHYSICAL_ADDR 0x83 -#define CEC_MSG_GET_MENU_LANGUAGE 0x91 -#define CEC_MSG_REPORT_PHYSICAL_ADDR 0x84 +#define CEC_MSG_GET_CEC_VERSION 0x9f +#define CEC_MSG_GIVE_PHYSICAL_ADDR 0x83 +#define CEC_MSG_GET_MENU_LANGUAGE 0x91 +#define CEC_MSG_REPORT_PHYSICAL_ADDR 0x84 /* Primary Device Type Operand (prim_devtype) */ -#define CEC_OP_PRIM_DEVTYPE_TV 0 -#define CEC_OP_PRIM_DEVTYPE_RECORD 1 -#define CEC_OP_PRIM_DEVTYPE_TUNER 3 -#define CEC_OP_PRIM_DEVTYPE_PLAYBACK 4 -#define CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM 5 -#define CEC_OP_PRIM_DEVTYPE_SWITCH 6 -#define CEC_OP_PRIM_DEVTYPE_PROCESSOR 7 +#define CEC_OP_PRIM_DEVTYPE_TV 0 +#define CEC_OP_PRIM_DEVTYPE_RECORD 1 +#define CEC_OP_PRIM_DEVTYPE_TUNER 3 +#define CEC_OP_PRIM_DEVTYPE_PLAYBACK 4 +#define CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM 5 +#define CEC_OP_PRIM_DEVTYPE_SWITCH 6 +#define CEC_OP_PRIM_DEVTYPE_PROCESSOR 7 -#define CEC_MSG_SET_MENU_LANGUAGE 0x32 -#define CEC_MSG_REPORT_FEATURES 0xa6 /* HDMI 2.0 */ +#define CEC_MSG_SET_MENU_LANGUAGE 0x32 +#define CEC_MSG_REPORT_FEATURES 0xa6 /* HDMI 2.0 */ /* All Device Types Operand (all_device_types) */ -#define CEC_OP_ALL_DEVTYPE_TV 0x80 -#define CEC_OP_ALL_DEVTYPE_RECORD 0x40 -#define CEC_OP_ALL_DEVTYPE_TUNER 0x20 -#define CEC_OP_ALL_DEVTYPE_PLAYBACK 0x10 -#define CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM 0x08 -#define CEC_OP_ALL_DEVTYPE_SWITCH 0x04 +#define CEC_OP_ALL_DEVTYPE_TV 0x80 +#define CEC_OP_ALL_DEVTYPE_RECORD 0x40 +#define CEC_OP_ALL_DEVTYPE_TUNER 0x20 +#define CEC_OP_ALL_DEVTYPE_PLAYBACK 0x10 +#define CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM 0x08 +#define CEC_OP_ALL_DEVTYPE_SWITCH 0x04 /* * And if you wondering what happened to PROCESSOR devices: those should * be mapped to a SWITCH. */ /* Valid for RC Profile and Device Feature operands */ -#define CEC_OP_FEAT_EXT 0x80 /* Extension bit */ +#define CEC_OP_FEAT_EXT 0x80 /* Extension bit */ /* RC Profile Operand (rc_profile) */ -#define CEC_OP_FEAT_RC_TV_PROFILE_NONE 0x00 -#define CEC_OP_FEAT_RC_TV_PROFILE_1 0x02 -#define CEC_OP_FEAT_RC_TV_PROFILE_2 0x06 -#define CEC_OP_FEAT_RC_TV_PROFILE_3 0x0a -#define CEC_OP_FEAT_RC_TV_PROFILE_4 0x0e -#define CEC_OP_FEAT_RC_SRC_HAS_DEV_ROOT_MENU 0x50 -#define CEC_OP_FEAT_RC_SRC_HAS_DEV_SETUP_MENU 0x48 -#define CEC_OP_FEAT_RC_SRC_HAS_CONTENTS_MENU 0x44 -#define CEC_OP_FEAT_RC_SRC_HAS_MEDIA_TOP_MENU 0x42 -#define CEC_OP_FEAT_RC_SRC_HAS_MEDIA_CONTEXT_MENU 0x41 +#define CEC_OP_FEAT_RC_TV_PROFILE_NONE 0x00 +#define CEC_OP_FEAT_RC_TV_PROFILE_1 0x02 +#define CEC_OP_FEAT_RC_TV_PROFILE_2 0x06 +#define CEC_OP_FEAT_RC_TV_PROFILE_3 0x0a +#define CEC_OP_FEAT_RC_TV_PROFILE_4 0x0e +#define CEC_OP_FEAT_RC_SRC_HAS_DEV_ROOT_MENU 0x50 +#define CEC_OP_FEAT_RC_SRC_HAS_DEV_SETUP_MENU 0x48 +#define CEC_OP_FEAT_RC_SRC_HAS_CONTENTS_MENU 0x44 +#define CEC_OP_FEAT_RC_SRC_HAS_MEDIA_TOP_MENU 0x42 +#define CEC_OP_FEAT_RC_SRC_HAS_MEDIA_CONTEXT_MENU 0x41 /* Device Feature Operand (dev_features) */ -#define CEC_OP_FEAT_DEV_HAS_RECORD_TV_SCREEN 0x40 -#define CEC_OP_FEAT_DEV_HAS_SET_OSD_STRING 0x20 -#define CEC_OP_FEAT_DEV_HAS_DECK_CONTROL 0x10 -#define CEC_OP_FEAT_DEV_HAS_SET_AUDIO_RATE 0x08 -#define CEC_OP_FEAT_DEV_SINK_HAS_ARC_TX 0x04 -#define CEC_OP_FEAT_DEV_SOURCE_HAS_ARC_RX 0x02 +#define CEC_OP_FEAT_DEV_HAS_RECORD_TV_SCREEN 0x40 +#define CEC_OP_FEAT_DEV_HAS_SET_OSD_STRING 0x20 +#define CEC_OP_FEAT_DEV_HAS_DECK_CONTROL 0x10 +#define CEC_OP_FEAT_DEV_HAS_SET_AUDIO_RATE 0x08 +#define CEC_OP_FEAT_DEV_SINK_HAS_ARC_TX 0x04 +#define CEC_OP_FEAT_DEV_SOURCE_HAS_ARC_RX 0x02 -#define CEC_MSG_GIVE_FEATURES 0xa5 /* HDMI 2.0 */ +#define CEC_MSG_GIVE_FEATURES 0xa5 /* HDMI 2.0 */ /* Deck Control Feature */ -#define CEC_MSG_DECK_CONTROL 0x42 +#define CEC_MSG_DECK_CONTROL 0x42 /* Deck Control Mode Operand (deck_control_mode) */ -#define CEC_OP_DECK_CTL_MODE_SKIP_FWD 1 -#define CEC_OP_DECK_CTL_MODE_SKIP_REV 2 -#define CEC_OP_DECK_CTL_MODE_STOP 3 -#define CEC_OP_DECK_CTL_MODE_EJECT 4 +#define CEC_OP_DECK_CTL_MODE_SKIP_FWD 1 +#define CEC_OP_DECK_CTL_MODE_SKIP_REV 2 +#define CEC_OP_DECK_CTL_MODE_STOP 3 +#define CEC_OP_DECK_CTL_MODE_EJECT 4 -#define CEC_MSG_DECK_STATUS 0x1b +#define CEC_MSG_DECK_STATUS 0x1b /* Deck Info Operand (deck_info) */ -#define CEC_OP_DECK_INFO_PLAY 0x11 -#define CEC_OP_DECK_INFO_RECORD 0x12 -#define CEC_OP_DECK_INFO_PLAY_REV 0x13 -#define CEC_OP_DECK_INFO_STILL 0x14 -#define CEC_OP_DECK_INFO_SLOW 0x15 -#define CEC_OP_DECK_INFO_SLOW_REV 0x16 -#define CEC_OP_DECK_INFO_FAST_FWD 0x17 -#define CEC_OP_DECK_INFO_FAST_REV 0x18 -#define CEC_OP_DECK_INFO_NO_MEDIA 0x19 -#define CEC_OP_DECK_INFO_STOP 0x1a -#define CEC_OP_DECK_INFO_SKIP_FWD 0x1b -#define CEC_OP_DECK_INFO_SKIP_REV 0x1c -#define CEC_OP_DECK_INFO_INDEX_SEARCH_FWD 0x1d -#define CEC_OP_DECK_INFO_INDEX_SEARCH_REV 0x1e -#define CEC_OP_DECK_INFO_OTHER 0x1f +#define CEC_OP_DECK_INFO_PLAY 0x11 +#define CEC_OP_DECK_INFO_RECORD 0x12 +#define CEC_OP_DECK_INFO_PLAY_REV 0x13 +#define CEC_OP_DECK_INFO_STILL 0x14 +#define CEC_OP_DECK_INFO_SLOW 0x15 +#define CEC_OP_DECK_INFO_SLOW_REV 0x16 +#define CEC_OP_DECK_INFO_FAST_FWD 0x17 +#define CEC_OP_DECK_INFO_FAST_REV 0x18 +#define CEC_OP_DECK_INFO_NO_MEDIA 0x19 +#define CEC_OP_DECK_INFO_STOP 0x1a +#define CEC_OP_DECK_INFO_SKIP_FWD 0x1b +#define CEC_OP_DECK_INFO_SKIP_REV 0x1c +#define CEC_OP_DECK_INFO_INDEX_SEARCH_FWD 0x1d +#define CEC_OP_DECK_INFO_INDEX_SEARCH_REV 0x1e +#define CEC_OP_DECK_INFO_OTHER 0x1f -#define CEC_MSG_GIVE_DECK_STATUS 0x1a +#define CEC_MSG_GIVE_DECK_STATUS 0x1a /* Status Request Operand (status_req) */ -#define CEC_OP_STATUS_REQ_ON 1 -#define CEC_OP_STATUS_REQ_OFF 2 -#define CEC_OP_STATUS_REQ_ONCE 3 +#define CEC_OP_STATUS_REQ_ON 1 +#define CEC_OP_STATUS_REQ_OFF 2 +#define CEC_OP_STATUS_REQ_ONCE 3 -#define CEC_MSG_PLAY 0x41 +#define CEC_MSG_PLAY 0x41 /* Play Mode Operand (play_mode) */ -#define CEC_OP_PLAY_MODE_PLAY_FWD 0x24 -#define CEC_OP_PLAY_MODE_PLAY_REV 0x20 -#define CEC_OP_PLAY_MODE_PLAY_STILL 0x25 -#define CEC_OP_PLAY_MODE_PLAY_FAST_FWD_MIN 0x05 -#define CEC_OP_PLAY_MODE_PLAY_FAST_FWD_MED 0x06 -#define CEC_OP_PLAY_MODE_PLAY_FAST_FWD_MAX 0x07 -#define CEC_OP_PLAY_MODE_PLAY_FAST_REV_MIN 0x09 -#define CEC_OP_PLAY_MODE_PLAY_FAST_REV_MED 0x0a -#define CEC_OP_PLAY_MODE_PLAY_FAST_REV_MAX 0x0b -#define CEC_OP_PLAY_MODE_PLAY_SLOW_FWD_MIN 0x15 -#define CEC_OP_PLAY_MODE_PLAY_SLOW_FWD_MED 0x16 -#define CEC_OP_PLAY_MODE_PLAY_SLOW_FWD_MAX 0x17 -#define CEC_OP_PLAY_MODE_PLAY_SLOW_REV_MIN 0x19 -#define CEC_OP_PLAY_MODE_PLAY_SLOW_REV_MED 0x1a -#define CEC_OP_PLAY_MODE_PLAY_SLOW_REV_MAX 0x1b +#define CEC_OP_PLAY_MODE_PLAY_FWD 0x24 +#define CEC_OP_PLAY_MODE_PLAY_REV 0x20 +#define CEC_OP_PLAY_MODE_PLAY_STILL 0x25 +#define CEC_OP_PLAY_MODE_PLAY_FAST_FWD_MIN 0x05 +#define CEC_OP_PLAY_MODE_PLAY_FAST_FWD_MED 0x06 +#define CEC_OP_PLAY_MODE_PLAY_FAST_FWD_MAX 0x07 +#define CEC_OP_PLAY_MODE_PLAY_FAST_REV_MIN 0x09 +#define CEC_OP_PLAY_MODE_PLAY_FAST_REV_MED 0x0a +#define CEC_OP_PLAY_MODE_PLAY_FAST_REV_MAX 0x0b +#define CEC_OP_PLAY_MODE_PLAY_SLOW_FWD_MIN 0x15 +#define CEC_OP_PLAY_MODE_PLAY_SLOW_FWD_MED 0x16 +#define CEC_OP_PLAY_MODE_PLAY_SLOW_FWD_MAX 0x17 +#define CEC_OP_PLAY_MODE_PLAY_SLOW_REV_MIN 0x19 +#define CEC_OP_PLAY_MODE_PLAY_SLOW_REV_MED 0x1a +#define CEC_OP_PLAY_MODE_PLAY_SLOW_REV_MAX 0x1b /* Tuner Control Feature */ -#define CEC_MSG_GIVE_TUNER_DEVICE_STATUS 0x08 -#define CEC_MSG_SELECT_ANALOGUE_SERVICE 0x92 -#define CEC_MSG_SELECT_DIGITAL_SERVICE 0x93 -#define CEC_MSG_TUNER_DEVICE_STATUS 0x07 +#define CEC_MSG_GIVE_TUNER_DEVICE_STATUS 0x08 +#define CEC_MSG_SELECT_ANALOGUE_SERVICE 0x92 +#define CEC_MSG_SELECT_DIGITAL_SERVICE 0x93 +#define CEC_MSG_TUNER_DEVICE_STATUS 0x07 /* Recording Flag Operand (rec_flag) */ -#define CEC_OP_REC_FLAG_USED 0 -#define CEC_OP_REC_FLAG_NOT_USED 1 +#define CEC_OP_REC_FLAG_USED 0 +#define CEC_OP_REC_FLAG_NOT_USED 1 /* Tuner Display Info Operand (tuner_display_info) */ -#define CEC_OP_TUNER_DISPLAY_INFO_DIGITAL 0 -#define CEC_OP_TUNER_DISPLAY_INFO_NONE 1 -#define CEC_OP_TUNER_DISPLAY_INFO_ANALOGUE 2 +#define CEC_OP_TUNER_DISPLAY_INFO_DIGITAL 0 +#define CEC_OP_TUNER_DISPLAY_INFO_NONE 1 +#define CEC_OP_TUNER_DISPLAY_INFO_ANALOGUE 2 -#define CEC_MSG_TUNER_STEP_DECREMENT 0x06 -#define CEC_MSG_TUNER_STEP_INCREMENT 0x05 +#define CEC_MSG_TUNER_STEP_DECREMENT 0x06 +#define CEC_MSG_TUNER_STEP_INCREMENT 0x05 /* Vendor Specific Commands Feature */ /* * Has also: - * CEC_MSG_CEC_VERSION - * CEC_MSG_GET_CEC_VERSION + * CEC_MSG_CEC_VERSION + * CEC_MSG_GET_CEC_VERSION */ -#define CEC_MSG_DEVICE_VENDOR_ID 0x87 -#define CEC_MSG_GIVE_DEVICE_VENDOR_ID 0x8c -#define CEC_MSG_VENDOR_COMMAND 0x89 -#define CEC_MSG_VENDOR_COMMAND_WITH_ID 0xa0 -#define CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN 0x8a -#define CEC_MSG_VENDOR_REMOTE_BUTTON_UP 0x8b +#define CEC_MSG_DEVICE_VENDOR_ID 0x87 +#define CEC_MSG_GIVE_DEVICE_VENDOR_ID 0x8c +#define CEC_MSG_VENDOR_COMMAND 0x89 +#define CEC_MSG_VENDOR_COMMAND_WITH_ID 0xa0 +#define CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN 0x8a +#define CEC_MSG_VENDOR_REMOTE_BUTTON_UP 0x8b /* OSD Display Feature */ -#define CEC_MSG_SET_OSD_STRING 0x64 +#define CEC_MSG_SET_OSD_STRING 0x64 /* Display Control Operand (disp_ctl) */ -#define CEC_OP_DISP_CTL_DEFAULT 0x00 -#define CEC_OP_DISP_CTL_UNTIL_CLEARED 0x40 -#define CEC_OP_DISP_CTL_CLEAR 0x80 +#define CEC_OP_DISP_CTL_DEFAULT 0x00 +#define CEC_OP_DISP_CTL_UNTIL_CLEARED 0x40 +#define CEC_OP_DISP_CTL_CLEAR 0x80 /* Device OSD Transfer Feature */ -#define CEC_MSG_GIVE_OSD_NAME 0x46 -#define CEC_MSG_SET_OSD_NAME 0x47 +#define CEC_MSG_GIVE_OSD_NAME 0x46 +#define CEC_MSG_SET_OSD_NAME 0x47 /* Device Menu Control Feature */ -#define CEC_MSG_MENU_REQUEST 0x8d +#define CEC_MSG_MENU_REQUEST 0x8d /* Menu Request Type Operand (menu_req) */ -#define CEC_OP_MENU_REQUEST_ACTIVATE 0x00 -#define CEC_OP_MENU_REQUEST_DEACTIVATE 0x01 -#define CEC_OP_MENU_REQUEST_QUERY 0x02 +#define CEC_OP_MENU_REQUEST_ACTIVATE 0x00 +#define CEC_OP_MENU_REQUEST_DEACTIVATE 0x01 +#define CEC_OP_MENU_REQUEST_QUERY 0x02 -#define CEC_MSG_MENU_STATUS 0x8e +#define CEC_MSG_MENU_STATUS 0x8e /* Menu State Operand (menu_state) */ -#define CEC_OP_MENU_STATE_ACTIVATED 0x00 -#define CEC_OP_MENU_STATE_DEACTIVATED 0x01 +#define CEC_OP_MENU_STATE_ACTIVATED 0x00 +#define CEC_OP_MENU_STATE_DEACTIVATED 0x01 -#define CEC_MSG_USER_CONTROL_PRESSED 0x44 +#define CEC_MSG_USER_CONTROL_PRESSED 0x44 /* UI Broadcast Type Operand (ui_bcast_type) */ -#define CEC_OP_UI_BCAST_TYPE_TOGGLE_ALL 0x00 -#define CEC_OP_UI_BCAST_TYPE_TOGGLE_DIG_ANA 0x01 -#define CEC_OP_UI_BCAST_TYPE_ANALOGUE 0x10 -#define CEC_OP_UI_BCAST_TYPE_ANALOGUE_T 0x20 -#define CEC_OP_UI_BCAST_TYPE_ANALOGUE_CABLE 0x30 -#define CEC_OP_UI_BCAST_TYPE_ANALOGUE_SAT 0x40 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL 0x50 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_T 0x60 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_CABLE 0x70 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_SAT 0x80 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_COM_SAT 0x90 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_COM_SAT2 0x91 -#define CEC_OP_UI_BCAST_TYPE_IP 0xa0 +#define CEC_OP_UI_BCAST_TYPE_TOGGLE_ALL 0x00 +#define CEC_OP_UI_BCAST_TYPE_TOGGLE_DIG_ANA 0x01 +#define CEC_OP_UI_BCAST_TYPE_ANALOGUE 0x10 +#define CEC_OP_UI_BCAST_TYPE_ANALOGUE_T 0x20 +#define CEC_OP_UI_BCAST_TYPE_ANALOGUE_CABLE 0x30 +#define CEC_OP_UI_BCAST_TYPE_ANALOGUE_SAT 0x40 +#define CEC_OP_UI_BCAST_TYPE_DIGITAL 0x50 +#define CEC_OP_UI_BCAST_TYPE_DIGITAL_T 0x60 +#define CEC_OP_UI_BCAST_TYPE_DIGITAL_CABLE 0x70 +#define CEC_OP_UI_BCAST_TYPE_DIGITAL_SAT 0x80 +#define CEC_OP_UI_BCAST_TYPE_DIGITAL_COM_SAT 0x90 +#define CEC_OP_UI_BCAST_TYPE_DIGITAL_COM_SAT2 0x91 +#define CEC_OP_UI_BCAST_TYPE_IP 0xa0 /* UI Sound Presentation Control Operand (ui_snd_pres_ctl) */ -#define CEC_OP_UI_SND_PRES_CTL_DUAL_MONO 0x10 -#define CEC_OP_UI_SND_PRES_CTL_KARAOKE 0x20 -#define CEC_OP_UI_SND_PRES_CTL_DOWNMIX 0x80 -#define CEC_OP_UI_SND_PRES_CTL_REVERB 0x90 -#define CEC_OP_UI_SND_PRES_CTL_EQUALIZER 0xa0 -#define CEC_OP_UI_SND_PRES_CTL_BASS_UP 0xb1 -#define CEC_OP_UI_SND_PRES_CTL_BASS_NEUTRAL 0xb2 -#define CEC_OP_UI_SND_PRES_CTL_BASS_DOWN 0xb3 -#define CEC_OP_UI_SND_PRES_CTL_TREBLE_UP 0xc1 -#define CEC_OP_UI_SND_PRES_CTL_TREBLE_NEUTRAL 0xc2 -#define CEC_OP_UI_SND_PRES_CTL_TREBLE_DOWN 0xc3 +#define CEC_OP_UI_SND_PRES_CTL_DUAL_MONO 0x10 +#define CEC_OP_UI_SND_PRES_CTL_KARAOKE 0x20 +#define CEC_OP_UI_SND_PRES_CTL_DOWNMIX 0x80 +#define CEC_OP_UI_SND_PRES_CTL_REVERB 0x90 +#define CEC_OP_UI_SND_PRES_CTL_EQUALIZER 0xa0 +#define CEC_OP_UI_SND_PRES_CTL_BASS_UP 0xb1 +#define CEC_OP_UI_SND_PRES_CTL_BASS_NEUTRAL 0xb2 +#define CEC_OP_UI_SND_PRES_CTL_BASS_DOWN 0xb3 +#define CEC_OP_UI_SND_PRES_CTL_TREBLE_UP 0xc1 +#define CEC_OP_UI_SND_PRES_CTL_TREBLE_NEUTRAL 0xc2 +#define CEC_OP_UI_SND_PRES_CTL_TREBLE_DOWN 0xc3 -#define CEC_MSG_USER_CONTROL_RELEASED 0x45 +#define CEC_MSG_USER_CONTROL_RELEASED 0x45 /* Remote Control Passthrough Feature */ /* * Has also: - * CEC_MSG_USER_CONTROL_PRESSED - * CEC_MSG_USER_CONTROL_RELEASED + * CEC_MSG_USER_CONTROL_PRESSED + * CEC_MSG_USER_CONTROL_RELEASED */ /* Power Status Feature */ -#define CEC_MSG_GIVE_DEVICE_POWER_STATUS 0x8f -#define CEC_MSG_REPORT_POWER_STATUS 0x90 +#define CEC_MSG_GIVE_DEVICE_POWER_STATUS 0x8f +#define CEC_MSG_REPORT_POWER_STATUS 0x90 /* Power Status Operand (pwr_state) */ -#define CEC_OP_POWER_STATUS_ON 0 -#define CEC_OP_POWER_STATUS_STANDBY 1 -#define CEC_OP_POWER_STATUS_TO_ON 2 -#define CEC_OP_POWER_STATUS_TO_STANDBY 3 +#define CEC_OP_POWER_STATUS_ON 0 +#define CEC_OP_POWER_STATUS_STANDBY 1 +#define CEC_OP_POWER_STATUS_TO_ON 2 +#define CEC_OP_POWER_STATUS_TO_STANDBY 3 /* General Protocol Messages */ -#define CEC_MSG_FEATURE_ABORT 0x00 +#define CEC_MSG_FEATURE_ABORT 0x00 /* Abort Reason Operand (reason) */ -#define CEC_OP_ABORT_UNRECOGNIZED_OP 0 -#define CEC_OP_ABORT_INCORRECT_MODE 1 -#define CEC_OP_ABORT_NO_SOURCE 2 -#define CEC_OP_ABORT_INVALID_OP 3 -#define CEC_OP_ABORT_REFUSED 4 -#define CEC_OP_ABORT_UNDETERMINED 5 +#define CEC_OP_ABORT_UNRECOGNIZED_OP 0 +#define CEC_OP_ABORT_INCORRECT_MODE 1 +#define CEC_OP_ABORT_NO_SOURCE 2 +#define CEC_OP_ABORT_INVALID_OP 3 +#define CEC_OP_ABORT_REFUSED 4 +#define CEC_OP_ABORT_UNDETERMINED 5 -#define CEC_MSG_ABORT 0xff +#define CEC_MSG_ABORT 0xff /* System Audio Control Feature */ /* * Has also: - * CEC_MSG_USER_CONTROL_PRESSED - * CEC_MSG_USER_CONTROL_RELEASED + * CEC_MSG_USER_CONTROL_PRESSED + * CEC_MSG_USER_CONTROL_RELEASED */ -#define CEC_MSG_GIVE_AUDIO_STATUS 0x71 -#define CEC_MSG_GIVE_SYSTEM_AUDIO_MODE_STATUS 0x7d -#define CEC_MSG_REPORT_AUDIO_STATUS 0x7a +#define CEC_MSG_GIVE_AUDIO_STATUS 0x71 +#define CEC_MSG_GIVE_SYSTEM_AUDIO_MODE_STATUS 0x7d +#define CEC_MSG_REPORT_AUDIO_STATUS 0x7a /* Audio Mute Status Operand (aud_mute_status) */ -#define CEC_OP_AUD_MUTE_STATUS_OFF 0 -#define CEC_OP_AUD_MUTE_STATUS_ON 1 +#define CEC_OP_AUD_MUTE_STATUS_OFF 0 +#define CEC_OP_AUD_MUTE_STATUS_ON 1 -#define CEC_MSG_REPORT_SHORT_AUDIO_DESCRIPTOR 0xa3 -#define CEC_MSG_REQUEST_SHORT_AUDIO_DESCRIPTOR 0xa4 -#define CEC_MSG_SET_SYSTEM_AUDIO_MODE 0x72 +#define CEC_MSG_REPORT_SHORT_AUDIO_DESCRIPTOR 0xa3 +#define CEC_MSG_REQUEST_SHORT_AUDIO_DESCRIPTOR 0xa4 +#define CEC_MSG_SET_SYSTEM_AUDIO_MODE 0x72 /* System Audio Status Operand (sys_aud_status) */ -#define CEC_OP_SYS_AUD_STATUS_OFF 0 -#define CEC_OP_SYS_AUD_STATUS_ON 1 +#define CEC_OP_SYS_AUD_STATUS_OFF 0 +#define CEC_OP_SYS_AUD_STATUS_ON 1 -#define CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST 0x70 -#define CEC_MSG_SYSTEM_AUDIO_MODE_STATUS 0x7e +#define CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST 0x70 +#define CEC_MSG_SYSTEM_AUDIO_MODE_STATUS 0x7e /* Audio Format ID Operand (audio_format_id) */ -#define CEC_OP_AUD_FMT_ID_CEA861 0 -#define CEC_OP_AUD_FMT_ID_CEA861_CXT 1 +#define CEC_OP_AUD_FMT_ID_CEA861 0 +#define CEC_OP_AUD_FMT_ID_CEA861_CXT 1 /* Audio Rate Control Feature */ -#define CEC_MSG_SET_AUDIO_RATE 0x9a +#define CEC_MSG_SET_AUDIO_RATE 0x9a /* Audio Rate Operand (audio_rate) */ -#define CEC_OP_AUD_RATE_OFF 0 -#define CEC_OP_AUD_RATE_WIDE_STD 1 -#define CEC_OP_AUD_RATE_WIDE_FAST 2 -#define CEC_OP_AUD_RATE_WIDE_SLOW 3 -#define CEC_OP_AUD_RATE_NARROW_STD 4 -#define CEC_OP_AUD_RATE_NARROW_FAST 5 -#define CEC_OP_AUD_RATE_NARROW_SLOW 6 +#define CEC_OP_AUD_RATE_OFF 0 +#define CEC_OP_AUD_RATE_WIDE_STD 1 +#define CEC_OP_AUD_RATE_WIDE_FAST 2 +#define CEC_OP_AUD_RATE_WIDE_SLOW 3 +#define CEC_OP_AUD_RATE_NARROW_STD 4 +#define CEC_OP_AUD_RATE_NARROW_FAST 5 +#define CEC_OP_AUD_RATE_NARROW_SLOW 6 /* Audio Return Channel Control Feature */ -#define CEC_MSG_INITIATE_ARC 0xc0 -#define CEC_MSG_REPORT_ARC_INITIATED 0xc1 -#define CEC_MSG_REPORT_ARC_TERMINATED 0xc2 -#define CEC_MSG_REQUEST_ARC_INITIATION 0xc3 -#define CEC_MSG_REQUEST_ARC_TERMINATION 0xc4 -#define CEC_MSG_TERMINATE_ARC 0xc5 +#define CEC_MSG_INITIATE_ARC 0xc0 +#define CEC_MSG_REPORT_ARC_INITIATED 0xc1 +#define CEC_MSG_REPORT_ARC_TERMINATED 0xc2 +#define CEC_MSG_REQUEST_ARC_INITIATION 0xc3 +#define CEC_MSG_REQUEST_ARC_TERMINATION 0xc4 +#define CEC_MSG_TERMINATE_ARC 0xc5 /* Dynamic Audio Lipsync Feature */ /* Only for CEC 2.0 and up */ -#define CEC_MSG_REQUEST_CURRENT_LATENCY 0xa7 -#define CEC_MSG_REPORT_CURRENT_LATENCY 0xa8 +#define CEC_MSG_REQUEST_CURRENT_LATENCY 0xa7 +#define CEC_MSG_REPORT_CURRENT_LATENCY 0xa8 /* Low Latency Mode Operand (low_latency_mode) */ -#define CEC_OP_LOW_LATENCY_MODE_OFF 0 -#define CEC_OP_LOW_LATENCY_MODE_ON 1 +#define CEC_OP_LOW_LATENCY_MODE_OFF 0 +#define CEC_OP_LOW_LATENCY_MODE_ON 1 /* Audio Output Compensated Operand (audio_out_compensated) */ -#define CEC_OP_AUD_OUT_COMPENSATED_NA 0 -#define CEC_OP_AUD_OUT_COMPENSATED_DELAY 1 -#define CEC_OP_AUD_OUT_COMPENSATED_NO_DELAY 2 -#define CEC_OP_AUD_OUT_COMPENSATED_PARTIAL_DELAY 3 +#define CEC_OP_AUD_OUT_COMPENSATED_NA 0 +#define CEC_OP_AUD_OUT_COMPENSATED_DELAY 1 +#define CEC_OP_AUD_OUT_COMPENSATED_NO_DELAY 2 +#define CEC_OP_AUD_OUT_COMPENSATED_PARTIAL_DELAY 3 /* Capability Discovery and Control Feature */ -#define CEC_MSG_CDC_MESSAGE 0xf8 +#define CEC_MSG_CDC_MESSAGE 0xf8 /* Ethernet-over-HDMI: nobody ever does this... */ -#define CEC_MSG_CDC_HEC_INQUIRE_STATE 0x00 -#define CEC_MSG_CDC_HEC_REPORT_STATE 0x01 +#define CEC_MSG_CDC_HEC_INQUIRE_STATE 0x00 +#define CEC_MSG_CDC_HEC_REPORT_STATE 0x01 /* HEC Functionality State Operand (hec_func_state) */ -#define CEC_OP_HEC_FUNC_STATE_NOT_SUPPORTED 0 -#define CEC_OP_HEC_FUNC_STATE_INACTIVE 1 -#define CEC_OP_HEC_FUNC_STATE_ACTIVE 2 -#define CEC_OP_HEC_FUNC_STATE_ACTIVATION_FIELD 3 +#define CEC_OP_HEC_FUNC_STATE_NOT_SUPPORTED 0 +#define CEC_OP_HEC_FUNC_STATE_INACTIVE 1 +#define CEC_OP_HEC_FUNC_STATE_ACTIVE 2 +#define CEC_OP_HEC_FUNC_STATE_ACTIVATION_FIELD 3 /* Host Functionality State Operand (host_func_state) */ -#define CEC_OP_HOST_FUNC_STATE_NOT_SUPPORTED 0 -#define CEC_OP_HOST_FUNC_STATE_INACTIVE 1 -#define CEC_OP_HOST_FUNC_STATE_ACTIVE 2 +#define CEC_OP_HOST_FUNC_STATE_NOT_SUPPORTED 0 +#define CEC_OP_HOST_FUNC_STATE_INACTIVE 1 +#define CEC_OP_HOST_FUNC_STATE_ACTIVE 2 /* ENC Functionality State Operand (enc_func_state) */ -#define CEC_OP_ENC_FUNC_STATE_EXT_CON_NOT_SUPPORTED 0 -#define CEC_OP_ENC_FUNC_STATE_EXT_CON_INACTIVE 1 -#define CEC_OP_ENC_FUNC_STATE_EXT_CON_ACTIVE 2 +#define CEC_OP_ENC_FUNC_STATE_EXT_CON_NOT_SUPPORTED 0 +#define CEC_OP_ENC_FUNC_STATE_EXT_CON_INACTIVE 1 +#define CEC_OP_ENC_FUNC_STATE_EXT_CON_ACTIVE 2 /* CDC Error Code Operand (cdc_errcode) */ -#define CEC_OP_CDC_ERROR_CODE_NONE 0 -#define CEC_OP_CDC_ERROR_CODE_CAP_UNSUPPORTED 1 -#define CEC_OP_CDC_ERROR_CODE_WRONG_STATE 2 -#define CEC_OP_CDC_ERROR_CODE_OTHER 3 +#define CEC_OP_CDC_ERROR_CODE_NONE 0 +#define CEC_OP_CDC_ERROR_CODE_CAP_UNSUPPORTED 1 +#define CEC_OP_CDC_ERROR_CODE_WRONG_STATE 2 +#define CEC_OP_CDC_ERROR_CODE_OTHER 3 /* HEC Support Operand (hec_support) */ -#define CEC_OP_HEC_SUPPORT_NO 0 -#define CEC_OP_HEC_SUPPORT_YES 1 +#define CEC_OP_HEC_SUPPORT_NO 0 +#define CEC_OP_HEC_SUPPORT_YES 1 /* HEC Activation Operand (hec_activation) */ -#define CEC_OP_HEC_ACTIVATION_ON 0 -#define CEC_OP_HEC_ACTIVATION_OFF 1 +#define CEC_OP_HEC_ACTIVATION_ON 0 +#define CEC_OP_HEC_ACTIVATION_OFF 1 -#define CEC_MSG_CDC_HEC_SET_STATE_ADJACENT 0x02 -#define CEC_MSG_CDC_HEC_SET_STATE 0x03 +#define CEC_MSG_CDC_HEC_SET_STATE_ADJACENT 0x02 +#define CEC_MSG_CDC_HEC_SET_STATE 0x03 /* HEC Set State Operand (hec_set_state) */ -#define CEC_OP_HEC_SET_STATE_DEACTIVATE 0 -#define CEC_OP_HEC_SET_STATE_ACTIVATE 1 +#define CEC_OP_HEC_SET_STATE_DEACTIVATE 0 +#define CEC_OP_HEC_SET_STATE_ACTIVATE 1 -#define CEC_MSG_CDC_HEC_REQUEST_DEACTIVATION 0x04 -#define CEC_MSG_CDC_HEC_NOTIFY_ALIVE 0x05 -#define CEC_MSG_CDC_HEC_DISCOVER 0x06 +#define CEC_MSG_CDC_HEC_REQUEST_DEACTIVATION 0x04 +#define CEC_MSG_CDC_HEC_NOTIFY_ALIVE 0x05 +#define CEC_MSG_CDC_HEC_DISCOVER 0x06 /* Hotplug Detect messages */ -#define CEC_MSG_CDC_HPD_SET_STATE 0x10 +#define CEC_MSG_CDC_HPD_SET_STATE 0x10 /* HPD State Operand (hpd_state) */ -#define CEC_OP_HPD_STATE_CP_EDID_DISABLE 0 -#define CEC_OP_HPD_STATE_CP_EDID_ENABLE 1 -#define CEC_OP_HPD_STATE_CP_EDID_DISABLE_ENABLE 2 -#define CEC_OP_HPD_STATE_EDID_DISABLE 3 -#define CEC_OP_HPD_STATE_EDID_ENABLE 4 -#define CEC_OP_HPD_STATE_EDID_DISABLE_ENABLE 5 -#define CEC_MSG_CDC_HPD_REPORT_STATE 0x11 +#define CEC_OP_HPD_STATE_CP_EDID_DISABLE 0 +#define CEC_OP_HPD_STATE_CP_EDID_ENABLE 1 +#define CEC_OP_HPD_STATE_CP_EDID_DISABLE_ENABLE 2 +#define CEC_OP_HPD_STATE_EDID_DISABLE 3 +#define CEC_OP_HPD_STATE_EDID_ENABLE 4 +#define CEC_OP_HPD_STATE_EDID_DISABLE_ENABLE 5 +#define CEC_MSG_CDC_HPD_REPORT_STATE 0x11 /* HPD Error Code Operand (hpd_error) */ -#define CEC_OP_HPD_ERROR_NONE 0 -#define CEC_OP_HPD_ERROR_INITIATOR_NOT_CAPABLE 1 -#define CEC_OP_HPD_ERROR_INITIATOR_WRONG_STATE 2 -#define CEC_OP_HPD_ERROR_OTHER 3 -#define CEC_OP_HPD_ERROR_NONE_NO_VIDEO 4 +#define CEC_OP_HPD_ERROR_NONE 0 +#define CEC_OP_HPD_ERROR_INITIATOR_NOT_CAPABLE 1 +#define CEC_OP_HPD_ERROR_INITIATOR_WRONG_STATE 2 +#define CEC_OP_HPD_ERROR_OTHER 3 +#define CEC_OP_HPD_ERROR_NONE_NO_VIDEO 4 #endif diff --git a/libarmbox/playback_gst.cpp b/libarmbox/playback_gst.cpp index a87a3e6..890ba52 100644 --- a/libarmbox/playback_gst.cpp +++ b/libarmbox/playback_gst.cpp @@ -41,9 +41,9 @@ #define hal_debug_c(args...) _hal_debug(HAL_DEBUG_PLAYBACK, NULL, args) #define hal_info_c(args...) _hal_info(HAL_DEBUG_PLAYBACK, NULL, args) -static const char * FILENAME = "[playback_gst.cpp]"; -extern cVideo * videoDecoder; -extern cAudio * audioDecoder; +static const char *FILENAME = "[playback_gst.cpp]"; +extern cVideo *videoDecoder; +extern cAudio *audioDecoder; #include #include @@ -67,11 +67,11 @@ typedef enum } GstPlayFlags; -GstElement * m_gst_playbin = NULL; -GstElement * audioSink = NULL; -GstElement * videoSink = NULL; -gchar * uri = NULL; -GstTagList * m_stream_tags = NULL; +GstElement *m_gst_playbin = NULL; +GstElement *audioSink = NULL; +GstElement *videoSink = NULL; +gchar *uri = NULL; +GstTagList *m_stream_tags = NULL; pthread_mutex_t mutex_tag_ist; static int end_eof = 0; @@ -88,21 +88,25 @@ gint match_sinktype(const GValue *velement, const gchar *type) void resetPids() { - for (unsigned int i = 0; i < REC_MAX_APIDS; i++) { + for (unsigned int i = 0; i < REC_MAX_APIDS; i++) + { real_apids[i] = 0; } } -void processMpegTsSection(GstMpegtsSection* section) +void processMpegTsSection(GstMpegtsSection *section) { resetPids(); int cnt = 0; - if (section->section_type == GST_MPEGTS_SECTION_PMT) { - const GstMpegtsPMT* pmt = gst_mpegts_section_get_pmt(section); - for (guint i = 0; i < pmt->streams->len; ++i) { - const GstMpegtsPMTStream* stream = static_cast(g_ptr_array_index(pmt->streams, i)); - if (stream->stream_type == 0x05 || stream->stream_type >= 0x80) { - hal_info_c( "%s:%s Audio Stream pid: %d\n", FILENAME, __FUNCTION__, stream->pid); + if (section->section_type == GST_MPEGTS_SECTION_PMT) + { + const GstMpegtsPMT *pmt = gst_mpegts_section_get_pmt(section); + for (guint i = 0; i < pmt->streams->len; ++i) + { + const GstMpegtsPMTStream *stream = static_cast(g_ptr_array_index(pmt->streams, i)); + if (stream->stream_type == 0x05 || stream->stream_type >= 0x80) + { + hal_info_c("%s:%s Audio Stream pid: %d\n", FILENAME, __FUNCTION__, stream->pid); real_apids[cnt] = stream->pid; cnt++; } @@ -113,7 +117,7 @@ void processMpegTsSection(GstMpegtsSection* section) void playbinNotifySource(GObject *object, GParamSpec *param_spec, gpointer user_data) { GstElement *source = NULL; - cPlayback *_this = (cPlayback*)user_data; + cPlayback *_this = (cPlayback *)user_data; g_object_get(object, "source", &source, NULL); if (source) @@ -166,7 +170,7 @@ void playbinNotifySource(GObject *object, GParamSpec *param_spec, gpointer user_ if (!name.empty() && !value.empty()) { GValue header; - hal_info_c( "%s:%s setting extra-header '%s:%s'\n", FILENAME, __FUNCTION__, name.c_str(), value.c_str()); + hal_info_c("%s:%s setting extra-header '%s:%s'\n", FILENAME, __FUNCTION__, name.c_str(), value.c_str()); memset(&header, 0, sizeof(GValue)); g_value_init(&header, G_TYPE_STRING); g_value_set_string(&header, value.c_str()); @@ -174,7 +178,7 @@ void playbinNotifySource(GObject *object, GParamSpec *param_spec, gpointer user_ } else { - hal_info_c( "%s:%s Invalid header format %s\n", FILENAME, __FUNCTION__, _this->extra_headers.c_str()); + hal_info_c("%s:%s Invalid header format %s\n", FILENAME, __FUNCTION__, _this->extra_headers.c_str()); break; } } @@ -191,7 +195,7 @@ void playbinNotifySource(GObject *object, GParamSpec *param_spec, gpointer user_ GstBusSyncReply Gst_bus_call(GstBus *bus, GstMessage *msg, gpointer user_data) { // source - GstObject * source; + GstObject *source; source = GST_MESSAGE_SRC(msg); if (!GST_IS_OBJECT(source)) @@ -199,210 +203,211 @@ GstBusSyncReply Gst_bus_call(GstBus *bus, GstMessage *msg, gpointer user_data) switch (GST_MESSAGE_TYPE(msg)) { - case GST_MESSAGE_EOS: - { - g_message("End-of-stream"); - end_eof = 1; - break; - } - - case GST_MESSAGE_ERROR: - { - gchar * debug; - GError *err; - gst_message_parse_error(msg, &err, &debug); - g_free (debug); - gchar * sourceName = gst_object_get_name(source); - hal_info_c( "%s:%s - GST_MESSAGE_ERROR: %s (%i) from %s\n", FILENAME, __FUNCTION__, err->message, err->code, sourceName ); - if ( err->domain == GST_STREAM_ERROR ) + case GST_MESSAGE_EOS: { - if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND ) - { - if ( g_strrstr(sourceName, "videosink") ) - hal_info_c( "%s:%s - GST_MESSAGE_ERROR: videosink\n", FILENAME, __FUNCTION__ ); //FIXME: how shall playback handle this event??? - else if ( g_strrstr(sourceName, "audiosink") ) - hal_info_c( "%s:%s - GST_MESSAGE_ERROR: audioSink\n", FILENAME, __FUNCTION__ ); //FIXME: how shall playback handle this event??? - } + g_message("End-of-stream"); + end_eof = 1; + break; } - g_error_free(err); - if(sourceName) - g_free(sourceName); - end_eof = 1; // NOTE: just to exit - - break; - } - - case GST_MESSAGE_INFO: - { - gchar *debug; - GError *inf; - - gst_message_parse_info (msg, &inf, &debug); - g_free (debug); - if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE ) + case GST_MESSAGE_ERROR: { - gchar * sourceName = gst_object_get_name(source); - if ( g_strrstr(sourceName, "videosink") ) - hal_info_c( "%s:%s - GST_MESSAGE_INFO: videosink\n", FILENAME, __FUNCTION__ ); //FIXME: how shall playback handle this event??? - if(sourceName) + gchar *debug; + GError *err; + gst_message_parse_error(msg, &err, &debug); + g_free(debug); + gchar *sourceName = gst_object_get_name(source); + hal_info_c("%s:%s - GST_MESSAGE_ERROR: %s (%i) from %s\n", FILENAME, __FUNCTION__, err->message, err->code, sourceName); + if (err->domain == GST_STREAM_ERROR) + { + if (err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND) + { + if (g_strrstr(sourceName, "videosink")) + hal_info_c("%s:%s - GST_MESSAGE_ERROR: videosink\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? + else if (g_strrstr(sourceName, "audiosink")) + hal_info_c("%s:%s - GST_MESSAGE_ERROR: audioSink\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? + } + } + g_error_free(err); + if (sourceName) g_free(sourceName); + end_eof = 1; // NOTE: just to exit + + break; } - g_error_free(inf); - break; - } - case GST_MESSAGE_TAG: - { - GstTagList *tags = NULL, *result = NULL; - gst_message_parse_tag(msg, &tags); - - if(tags == NULL) - break; - if(!GST_IS_TAG_LIST(tags)) - break; - - pthread_mutex_lock (&mutex_tag_ist); - - result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE); - if (result) + case GST_MESSAGE_INFO: { - if (m_stream_tags && gst_tag_list_is_equal(m_stream_tags, result)) - { - gst_tag_list_unref(tags); - gst_tag_list_unref(result); + gchar *debug; + GError *inf; - pthread_mutex_unlock (&mutex_tag_ist); + gst_message_parse_info(msg, &inf, &debug); + g_free(debug); + if (inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE) + { + gchar *sourceName = gst_object_get_name(source); + if (g_strrstr(sourceName, "videosink")) + hal_info_c("%s:%s - GST_MESSAGE_INFO: videosink\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? + if (sourceName) + g_free(sourceName); + + } + g_error_free(inf); + break; + } + + case GST_MESSAGE_TAG: + { + GstTagList *tags = NULL, *result = NULL; + gst_message_parse_tag(msg, &tags); + + if (tags == NULL) + break; + if (!GST_IS_TAG_LIST(tags)) break; - } - if (m_stream_tags) - gst_tag_list_unref(m_stream_tags); - m_stream_tags = gst_tag_list_copy(result); - gst_tag_list_unref(result); - } - pthread_mutex_unlock (&mutex_tag_ist); + pthread_mutex_lock(&mutex_tag_ist); - const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0); - if ( gv_image ) - { - GstBuffer *buf_image; - GstSample *sample; - sample = (GstSample *)g_value_get_boxed(gv_image); - buf_image = gst_sample_get_buffer(sample); - int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644); - if (fd >= 0) + result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE); + if (result) { - guint8 *data; - gsize size; - GstMapInfo map; - gst_buffer_map(buf_image, &map, GST_MAP_READ); - data = map.data; - size = map.size; - int ret = write(fd, data, size); - gst_buffer_unmap(buf_image, &map); - close(fd); - hal_info_c("%s:%s - /tmp/.id3coverart %d bytes written\n", FILENAME, __FUNCTION__, ret); + if (m_stream_tags && gst_tag_list_is_equal(m_stream_tags, result)) + { + gst_tag_list_unref(tags); + gst_tag_list_unref(result); + + pthread_mutex_unlock(&mutex_tag_ist); + break; + } + if (m_stream_tags) + gst_tag_list_unref(m_stream_tags); + m_stream_tags = gst_tag_list_copy(result); + gst_tag_list_unref(result); } - } - if (tags) - gst_tag_list_unref(tags); - hal_debug_c( "%s:%s - GST_MESSAGE_INFO: update info tags\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? - break; - } - case GST_MESSAGE_ELEMENT: - { - GstMpegtsSection* section = gst_message_parse_mpegts_section(msg); - if (section) { - processMpegTsSection(section); - gst_mpegts_section_unref(section); - } - } - case GST_MESSAGE_STATE_CHANGED: - { - if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin)) + + pthread_mutex_unlock(&mutex_tag_ist); + + const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0); + if (gv_image) + { + GstBuffer *buf_image; + GstSample *sample; + sample = (GstSample *)g_value_get_boxed(gv_image); + buf_image = gst_sample_get_buffer(sample); + int fd = open("/tmp/.id3coverart", O_CREAT | O_WRONLY | O_TRUNC, 0644); + if (fd >= 0) + { + guint8 *data; + gsize size; + GstMapInfo map; + gst_buffer_map(buf_image, &map, GST_MAP_READ); + data = map.data; + size = map.size; + int ret = write(fd, data, size); + gst_buffer_unmap(buf_image, &map); + close(fd); + hal_info_c("%s:%s - /tmp/.id3coverart %d bytes written\n", FILENAME, __FUNCTION__, ret); + } + } + if (tags) + gst_tag_list_unref(tags); + hal_debug_c("%s:%s - GST_MESSAGE_INFO: update info tags\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? break; + } + case GST_MESSAGE_ELEMENT: + { + GstMpegtsSection *section = gst_message_parse_mpegts_section(msg); + if (section) + { + processMpegTsSection(section); + gst_mpegts_section_unref(section); + } + } + case GST_MESSAGE_STATE_CHANGED: + { + if (GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin)) + break; - GstState old_state, new_state; - gst_message_parse_state_changed(msg, &old_state, &new_state, NULL); + GstState old_state, new_state; + gst_message_parse_state_changed(msg, &old_state, &new_state, NULL); - if(old_state == new_state) + if (old_state == new_state) + break; + hal_info_c("%s:%s - GST_MESSAGE_STATE_CHANGED: state transition %s -> %s\n", FILENAME, __FUNCTION__, gst_element_state_get_name(old_state), gst_element_state_get_name(new_state)); + + GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state); + + switch (transition) + { + case GST_STATE_CHANGE_NULL_TO_READY: + { + } break; + case GST_STATE_CHANGE_READY_TO_PAUSED: + { + GstIterator *children; + GValue r = G_VALUE_INIT; + + if (audioSink) + { + gst_object_unref(GST_OBJECT(audioSink)); + audioSink = NULL; + } + + if (videoSink) + { + gst_object_unref(GST_OBJECT(videoSink)); + videoSink = NULL; + } + children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin)); + if (children && gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &r, (gpointer)"GstDVBAudioSink")) + { + audioSink = GST_ELEMENT_CAST(g_value_dup_object(&r)); + g_value_unset(&r); + hal_info_c("%s %s - audio sink created\n", FILENAME, __FUNCTION__); + } + + gst_iterator_free(children); + children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin)); + if (children && gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &r, (gpointer)"GstDVBVideoSink")) + { + videoSink = GST_ELEMENT_CAST(g_value_dup_object(&r)); + g_value_unset(&r); + hal_info_c("%s %s - video sink created\n", FILENAME, __FUNCTION__); + } + gst_iterator_free(children); + + } + break; + case GST_STATE_CHANGE_PAUSED_TO_PLAYING: + { + } break; + case GST_STATE_CHANGE_PLAYING_TO_PAUSED: + { + } break; + case GST_STATE_CHANGE_PAUSED_TO_READY: + { + if (audioSink) + { + gst_object_unref(GST_OBJECT(audioSink)); + audioSink = NULL; + } + if (videoSink) + { + gst_object_unref(GST_OBJECT(videoSink)); + videoSink = NULL; + } + } + break; + case GST_STATE_CHANGE_READY_TO_NULL: + { + } break; + } break; - hal_info_c( "%s:%s - GST_MESSAGE_STATE_CHANGED: state transition %s -> %s\n", FILENAME, __FUNCTION__, gst_element_state_get_name(old_state), gst_element_state_get_name(new_state)); - - GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state); - - switch(transition) - { - case GST_STATE_CHANGE_NULL_TO_READY: - { - } break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - { - GstIterator *children; - GValue r = G_VALUE_INIT; - - if (audioSink) - { - gst_object_unref(GST_OBJECT(audioSink)); - audioSink = NULL; - } - - if (videoSink) - { - gst_object_unref(GST_OBJECT(videoSink)); - videoSink = NULL; - } - children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin)); - if (children && gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &r, (gpointer)"GstDVBAudioSink")) - { - audioSink = GST_ELEMENT_CAST(g_value_dup_object (&r)); - g_value_unset (&r); - hal_info_c( "%s %s - audio sink created\n", FILENAME, __FUNCTION__); - } - - gst_iterator_free(children); - children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin)); - if (children && gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &r, (gpointer)"GstDVBVideoSink")) - { - videoSink = GST_ELEMENT_CAST(g_value_dup_object (&r)); - g_value_unset (&r); - hal_info_c( "%s %s - video sink created\n", FILENAME, __FUNCTION__); - } - gst_iterator_free(children); - } break; - case GST_STATE_CHANGE_PAUSED_TO_PLAYING: - { - } break; - case GST_STATE_CHANGE_PLAYING_TO_PAUSED: - { - } break; - case GST_STATE_CHANGE_PAUSED_TO_READY: - { - if (audioSink) - { - gst_object_unref(GST_OBJECT(audioSink)); - audioSink = NULL; - } - if (videoSink) - { - gst_object_unref(GST_OBJECT(videoSink)); - videoSink = NULL; - } - } - break; - case GST_STATE_CHANGE_READY_TO_NULL: - { - } break; - } - break; - } - break; - default: - break; + default: + break; } return GST_BUS_DROP; @@ -411,17 +416,17 @@ GstBusSyncReply Gst_bus_call(GstBus *bus, GstMessage *msg, gpointer user_data) cPlayback::cPlayback(int num) { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); const gchar *nano_str; guint major, minor, micro, nano; gst_init(NULL, NULL); - gst_version (&major, &minor, µ, &nano); + gst_version(&major, &minor, µ, &nano); gst_mpegts_initialize(); - pthread_mutex_init (&mutex_tag_ist, NULL); + pthread_mutex_init(&mutex_tag_ist, NULL); if (nano == 1) nano_str = "(CVS)"; @@ -430,9 +435,9 @@ cPlayback::cPlayback(int num) else nano_str = ""; - hal_info( "%s:%s - This program is linked against GStreamer %d.%d.%d %s\n", - FILENAME, __FUNCTION__, - major, minor, micro, nano_str); + hal_info("%s:%s - This program is linked against GStreamer %d.%d.%d %s\n", + FILENAME, __FUNCTION__, + major, minor, micro, nano_str); mAudioStream = 0; mSpeed = 0; @@ -445,12 +450,12 @@ cPlayback::cPlayback(int num) cPlayback::~cPlayback() { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); //FIXME: all deleting stuff is done in Close() - pthread_mutex_lock (&mutex_tag_ist); + pthread_mutex_lock(&mutex_tag_ist); if (m_stream_tags) gst_tag_list_unref(m_stream_tags); - pthread_mutex_unlock (&mutex_tag_ist); + pthread_mutex_unlock(&mutex_tag_ist); } //Used by Fileplay @@ -472,7 +477,7 @@ bool cPlayback::Open(playmode_t PlayMode) // used by movieplay void cPlayback::Close(void) { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); Stop(); @@ -480,11 +485,11 @@ void cPlayback::Close(void) if (m_gst_playbin) { // disconnect sync handler callback - GstBus * bus = gst_pipeline_get_bus(GST_PIPELINE (m_gst_playbin)); + GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(m_gst_playbin)); gst_bus_set_sync_handler(bus, NULL, NULL, NULL); if (bus) gst_object_unref(bus); - hal_info( "%s:%s - GST bus handler closed\n", FILENAME, __FUNCTION__); + hal_info("%s:%s - GST bus handler closed\n", FILENAME, __FUNCTION__); } // close gst @@ -495,7 +500,7 @@ void cPlayback::Close(void) gst_object_unref(GST_OBJECT(audioSink)); audioSink = NULL; - hal_info( "%s:%s - GST audio Sink closed\n", FILENAME, __FUNCTION__); + hal_info("%s:%s - GST audio Sink closed\n", FILENAME, __FUNCTION__); } if (videoSink) @@ -503,12 +508,12 @@ void cPlayback::Close(void) gst_object_unref(GST_OBJECT(videoSink)); videoSink = NULL; - hal_info( "%s:%s - GST video Sink closed\n", FILENAME, __FUNCTION__); + hal_info("%s:%s - GST video Sink closed\n", FILENAME, __FUNCTION__); } // unref m_gst_playbin - gst_object_unref (GST_OBJECT (m_gst_playbin)); - hal_info( "%s:%s - GST playbin closed\n", FILENAME, __FUNCTION__); + gst_object_unref(GST_OBJECT(m_gst_playbin)); + hal_info("%s:%s - GST playbin closed\n", FILENAME, __FUNCTION__); m_gst_playbin = NULL; @@ -525,12 +530,12 @@ void cPlayback::Close(void) // start bool cPlayback::Start(std::string filename, std::string headers) { - return Start((char*) filename.c_str(),0,0,0,0,0, headers); + return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers); } bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, int /*ac3*/, int /*duration*/, std::string headers) { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); if (!headers.empty()) extra_headers = headers; @@ -542,68 +547,68 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, mAudioStream = 0; init_jump = -1; - pthread_mutex_lock (&mutex_tag_ist); + pthread_mutex_lock(&mutex_tag_ist); if (m_stream_tags) gst_tag_list_unref(m_stream_tags); m_stream_tags = NULL; - pthread_mutex_unlock (&mutex_tag_ist); + pthread_mutex_unlock(&mutex_tag_ist); unlink("/tmp/.id3coverart"); //create playback path bool isHTTP = false; - if(!strncmp("http://", filename, 7)) + if (!strncmp("http://", filename, 7)) { isHTTP = true; } - else if(!strncmp("https://", filename, 8)) + else if (!strncmp("https://", filename, 8)) { isHTTP = true; } - else if(!strncmp("file://", filename, 7)) + else if (!strncmp("file://", filename, 7)) { isHTTP = false; } - else if(!strncmp("upnp://", filename, 7)) + else if (!strncmp("upnp://", filename, 7)) { isHTTP = true; } - else if(!strncmp("rtmp://", filename, 7)) + else if (!strncmp("rtmp://", filename, 7)) { isHTTP = true; } - else if(!strncmp("rtsp://", filename, 7)) + else if (!strncmp("rtsp://", filename, 7)) { isHTTP = true; } - else if(!strncmp("mms://", filename, 6)) + else if (!strncmp("mms://", filename, 6)) { isHTTP = true; } if (isHTTP) - uri = g_strdup_printf ("%s", filename); + uri = g_strdup_printf("%s", filename); else uri = g_filename_to_uri(filename, NULL, NULL); hal_info("%s:%s - filename=%s\n", FILENAME, __FUNCTION__, filename); - guint flags = GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_NATIVE_VIDEO; + guint flags = GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_NATIVE_VIDEO; /* increase the default 2 second / 2 MB buffer limitations to 5s / 5MB */ - int m_buffer_size = 5*1024*1024; + int m_buffer_size = 5 * 1024 * 1024; // create gst pipeline - m_gst_playbin = gst_element_factory_make ("playbin", "playbin"); + m_gst_playbin = gst_element_factory_make("playbin", "playbin"); - if(m_gst_playbin) + if (m_gst_playbin) { hal_info("%s:%s - m_gst_playbin\n", FILENAME, __FUNCTION__); - if(isHTTP) + if (isHTTP) { - g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (playbinNotifySource), this); + g_signal_connect(G_OBJECT(m_gst_playbin), "notify::source", G_CALLBACK(playbinNotifySource), this); // set buffer size g_object_set(G_OBJECT(m_gst_playbin), "buffer-size", m_buffer_size, NULL); @@ -611,12 +616,12 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, flags |= GST_PLAY_FLAG_BUFFERING; } - g_object_set(G_OBJECT (m_gst_playbin), "flags", flags, NULL); + g_object_set(G_OBJECT(m_gst_playbin), "flags", flags, NULL); - g_object_set(G_OBJECT (m_gst_playbin), "uri", uri, NULL); + g_object_set(G_OBJECT(m_gst_playbin), "uri", uri, NULL); //gstbus handler - GstBus * bus = gst_pipeline_get_bus( GST_PIPELINE(m_gst_playbin) ); + GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(m_gst_playbin)); gst_bus_set_sync_handler(bus, Gst_bus_call, NULL, NULL); if (bus) gst_object_unref(bus); @@ -624,7 +629,7 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, first = true; // state playing - if(isHTTP) + if (isHTTP) { gst_element_set_state(GST_ELEMENT(m_gst_playbin), GST_STATE_PLAYING); playstate = STATE_PLAY; @@ -652,12 +657,12 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, bool cPlayback::Play(void) { - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - if(playing == true) + if (playing == true) return true; - if(m_gst_playbin) + if (m_gst_playbin) { gst_element_set_state(GST_ELEMENT(m_gst_playbin), GST_STATE_PLAYING); @@ -671,19 +676,19 @@ bool cPlayback::Play(void) bool cPlayback::Stop(void) { - if(playing == false) + if (playing == false) return false; - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); // stop - if(m_gst_playbin) + if (m_gst_playbin) { gst_element_set_state(m_gst_playbin, GST_STATE_NULL); } playing = false; - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); playstate = STATE_STOP; @@ -696,15 +701,16 @@ bool cPlayback::SetAPid(int pid, bool /*ac3*/) int to_audio = pid; - for (unsigned int i = 0; i < REC_MAX_APIDS; i++) { + for (unsigned int i = 0; i < REC_MAX_APIDS; i++) + { if (real_apids[i]) if (real_apids[i] == pid) to_audio = i; } - if(to_audio != mAudioStream) + if (to_audio != mAudioStream) { - g_object_set (G_OBJECT (m_gst_playbin), "current-audio", to_audio, NULL); + g_object_set(G_OBJECT(m_gst_playbin), "current-audio", to_audio, NULL); printf("%s: switched to audio stream %i\n", __FUNCTION__, to_audio); mAudioStream = to_audio; } @@ -721,7 +727,7 @@ void cPlayback::trickSeek(int ratio) if (gst_element_query_position(m_gst_playbin, fmt, &pos)) { - if(ratio >= 0.0) + if (ratio >= 0.0) gst_element_seek(m_gst_playbin, ratio, fmt, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, -1); else gst_element_seek(m_gst_playbin, ratio, fmt, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, pos); @@ -730,7 +736,7 @@ void cPlayback::trickSeek(int ratio) bool cPlayback::SetSpeed(int speed) { - hal_info( "%s:%s speed %d\n", FILENAME, __FUNCTION__, speed); + hal_info("%s:%s speed %d\n", FILENAME, __FUNCTION__, speed); if (!decoders_closed) { @@ -740,20 +746,20 @@ bool cPlayback::SetSpeed(int speed) usleep(500000); } - if(playing == false) + if (playing == false) return false; - if(m_gst_playbin) + if (m_gst_playbin) { // pause - if(speed == 0) + if (speed == 0) { gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED); //trickSeek(0); playstate = STATE_PAUSE; } // play/continue - else if(speed == 1) + else if (speed == 1) { trickSeek(1); //gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING); @@ -761,14 +767,14 @@ bool cPlayback::SetSpeed(int speed) playstate = STATE_PLAY; } //ff - else if(speed > 1) + else if (speed > 1) { trickSeek(speed); // playstate = STATE_FF; } //rf - else if(speed < 0) + else if (speed < 0) { trickSeek(speed); // @@ -777,7 +783,7 @@ bool cPlayback::SetSpeed(int speed) if (init_jump > -1) { - SetPosition(init_jump,true); + SetPosition(init_jump, true); init_jump = -1; } } @@ -789,12 +795,12 @@ bool cPlayback::SetSpeed(int speed) bool cPlayback::SetSlow(int slow) { - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - if(playing == false) + if (playing == false) return false; - if(m_gst_playbin) + if (m_gst_playbin) { trickSeek(0.5); } @@ -816,17 +822,17 @@ bool cPlayback::GetSpeed(int &speed) const // in milliseconds bool cPlayback::GetPosition(int &position, int &duration) { - if(playing == false) + if (playing == false) return false; //EOF - if(end_eof) + if (end_eof) { end_eof = 0; return false; } - if(m_gst_playbin) + if (m_gst_playbin) { //position GstFormat fmt = GST_FORMAT_TIME; //Returns time in nanosecs @@ -836,14 +842,14 @@ bool cPlayback::GetPosition(int &position, int &duration) g_signal_emit_by_name(audioSink ? audioSink : videoSink, "get-decoder-time", &pts); if (!GST_CLOCK_TIME_IS_VALID(pts)) { - hal_info( "%s - %d failed\n", __FUNCTION__, __LINE__); + hal_info("%s - %d failed\n", __FUNCTION__, __LINE__); } } else { - if(!gst_element_query_position(m_gst_playbin, fmt, &pts)) + if (!gst_element_query_position(m_gst_playbin, fmt, &pts)) { - hal_info( "%s - %d failed\n", __FUNCTION__, __LINE__); + hal_info("%s - %d failed\n", __FUNCTION__, __LINE__); } } position = pts / 1000000.0; @@ -854,7 +860,7 @@ bool cPlayback::GetPosition(int &position, int &duration) gst_element_query_duration(m_gst_playbin, fmt_d, &len); length = len / 1000000.0; - if(length < 0) + if (length < 0) length = 0; duration = (int)(length); @@ -868,12 +874,13 @@ bool cPlayback::SetPosition(int position, bool absolute) hal_info("%s: pos %d abs %d playing %d\n", __func__, position, absolute, playing); - if(m_gst_playbin) + if (m_gst_playbin) { - if(first){ + if (first) + { GstState state; gst_element_get_state(m_gst_playbin, &state, NULL, GST_CLOCK_TIME_NONE); - if ( (state == GST_STATE_PAUSED) && first) + if ((state == GST_STATE_PAUSED) && first) { init_jump = position; first = false; @@ -888,7 +895,7 @@ bool cPlayback::SetPosition(int position, bool absolute) { gst_element_query_position(m_gst_playbin, fmt, &pos); time_nanoseconds = pos + (position * 1000000.0); - if(time_nanoseconds < 0) + if (time_nanoseconds < 0) time_nanoseconds = 0; } else @@ -902,82 +909,82 @@ bool cPlayback::SetPosition(int position, bool absolute) return true; } -void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string * language) +void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language) { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); language->clear(); *numpida = 0; - if(m_gst_playbin) + if (m_gst_playbin) { gint i, n_audio = 0; // get audio - g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL); + g_object_get(m_gst_playbin, "n-audio", &n_audio, NULL); hal_info("%s: %d audio\n", __FUNCTION__, n_audio); - if(n_audio == 0) + if (n_audio == 0) return; for (i = 0; i < n_audio && i < REC_MAX_APIDS; i++) { // apids - apids[i]= real_apids[i] ? real_apids[i] : i; + apids[i] = real_apids[i] ? real_apids[i] : i; - GstPad * pad = 0; - g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad); + GstPad *pad = 0; + g_signal_emit_by_name(m_gst_playbin, "get-audio-pad", i, &pad); - GstCaps * caps = gst_pad_get_current_caps(pad); + GstCaps *caps = gst_pad_get_current_caps(pad); if (pad) gst_object_unref(pad); if (!caps) continue; - GstStructure * structure = gst_caps_get_structure(caps, 0); - GstTagList * tags = NULL; - gchar * g_lang = NULL; + GstStructure *structure = gst_caps_get_structure(caps, 0); + GstTagList *tags = NULL; + gchar *g_lang = NULL; // ac3flags - if ( gst_structure_has_name (structure, "audio/mpeg")) + if (gst_structure_has_name(structure, "audio/mpeg")) { gint mpegversion; - if (!gst_structure_get_int (structure, "mpegversion", &mpegversion)) + if (!gst_structure_get_int(structure, "mpegversion", &mpegversion)) ac3flags[i] = 0; switch (mpegversion) { - case 1: - ac3flags[i] = 4; - case 2: - //return atAAC; - ac3flags[i] = 5; - case 4: - //return atAAC; - ac3flags[i] = 5; - default: - //return atUnknown; - ac3flags[i] = 0; + case 1: + ac3flags[i] = 4; + case 2: + //return atAAC; + ac3flags[i] = 5; + case 4: + //return atAAC; + ac3flags[i] = 5; + default: + //return atUnknown; + ac3flags[i] = 0; } } - else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") ) + else if (gst_structure_has_name(structure, "audio/x-ac3") || gst_structure_has_name(structure, "audio/ac3")) //return atAC3; ac3flags[i] = 1; - else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") ) + else if (gst_structure_has_name(structure, "audio/x-dts") || gst_structure_has_name(structure, "audio/dts")) //return atDTS; ac3flags[i] = 6; - else if ( gst_structure_has_name (structure, "audio/x-raw-int") ) + else if (gst_structure_has_name(structure, "audio/x-raw-int")) //return atPCM; ac3flags[i] = 0; if (caps) gst_caps_unref(caps); - //(ac3flags[i] > 2) ? ac3flags[i] = 1 : ac3flags[i] = 0; + //(ac3flags[i] > 2) ? ac3flags[i] = 1 : ac3flags[i] = 0; - g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags); + g_signal_emit_by_name(m_gst_playbin, "get-audio-tags", i, &tags); if (tags) { if (GST_IS_TAG_LIST(tags) && gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang)) @@ -997,21 +1004,21 @@ void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *nu gst_tag_list_free(tags); } } - *numpida=i; + *numpida = i; } } void cPlayback::getMeta() { - if(playing) + if (playing) return; } bool cPlayback::SyncAV(void) { - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - if(playing == false ) + if (playing == false) return false; return true; @@ -1056,18 +1063,20 @@ void cPlayback::GetMetadata(std::vector &keys, std::vector &keys, std::vector &positions, std::vector &titles); - void GetMetadata(std::vector &keys, std::vector &values); - AVFormatContext *GetAVFormatContext(); - void ReleaseAVFormatContext(); - std::string extra_headers; - std::string user_agent; + void trickSeek(int ratio); + bool SetSpeed(int speed); + bool SetSlow(int slow); + bool GetSpeed(int &speed) const; + bool GetPosition(int &position, int &duration); + void GetPts(uint64_t &pts); + int GetAPid(void); + int GetVPid(void); + int GetSubtitlePid(void); + bool SetPosition(int position, bool absolute = false); + void FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language); + void FindAllPids(uint16_t *apids, unsigned short *ac3flags, uint16_t *numpida, std::string *language) + { + FindAllPids((int *) apids, (unsigned int *) ac3flags, (unsigned int *) numpida, language); + }; + void FindAllSubs(int *pids, unsigned int *supported, unsigned int *numpida, std::string *language); + void FindAllSubs(uint16_t *pids, unsigned short *supported, uint16_t *numpida, std::string *language) + { + FindAllSubs((int *) pids, (unsigned int *) supported, (unsigned int *) numpida, language); + }; + bool SelectSubtitles(int pid, std::string charset = ""); + void FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language); + void FindAllTeletextsubtitlePids(int *pids, unsigned int *numpidt, std::string *tlanguage, int *mags, int *pages); + void RequestAbort(void); + uint64_t GetReadCount(void); + void GetChapters(std::vector &positions, std::vector &titles); + void GetMetadata(std::vector &keys, std::vector &values); + AVFormatContext *GetAVFormatContext(); + void ReleaseAVFormatContext(); + std::string extra_headers; + std::string user_agent; - void GetTitles(std::vector &playlists, std::vector &titles, int ¤t); - void SetTitle(int title); + void GetTitles(std::vector &playlists, std::vector &titles, int ¤t); + void SetTitle(int title); - // - ~cPlayback(); - void getMeta(); + // + ~cPlayback(); + void getMeta(); }; #endif // __PLAYBACK_GST_H__ diff --git a/libarmbox/playback_hisilicon.cpp b/libarmbox/playback_hisilicon.cpp index 787bc0b..855ce68 100644 --- a/libarmbox/playback_hisilicon.cpp +++ b/libarmbox/playback_hisilicon.cpp @@ -1,20 +1,20 @@ /* - Copyright (C) 2018 TangoCash + Copyright (C) 2018 TangoCash - License: GPLv2 + License: GPLv2 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define __USE_FILE_OFFSET64 1 @@ -93,14 +93,14 @@ void cPlayback::Close(void) hal_info("%s\n", __func__); //Dagobert: movieplayer does not call stop, it calls close ;) - if(playing) + if (playing) Stop(); } bool cPlayback::Start(std::string filename, std::string headers, std::string filename2) { - return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers,filename2); + return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers, filename2); } bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, int, std::string headers __attribute__((unused)), std::string filename2 __attribute__((unused))) @@ -132,13 +132,13 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in { uint32_t size; void *arg; - } *argdata = (struct argdata*)cmd.raw.data; + } *argdata = (struct argdata *)cmd.raw.data; cmd.cmd = 101; /* set url */ - argdata->arg = (void*)filename; + argdata->arg = (void *)filename; argdata->size = strlen(filename) + 1; ::ioctl(videoDecoder->fd, VIDEO_COMMAND, &cmd); cmd.cmd = 102; /* set useragent */ - argdata->arg = (void*)headers.c_str(); + argdata->arg = (void *)headers.c_str(); argdata->size = headers.length() + 1; ::ioctl(videoDecoder->fd, VIDEO_COMMAND, &cmd); } @@ -152,7 +152,7 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in ::ioctl(videoDecoder->fd, VIDEO_CONTINUE); } else return false; - + if (audioDecoder->fd >= 0) { ::ioctl(audioDecoder->fd, AUDIO_PLAY); @@ -314,17 +314,17 @@ void cPlayback::GetPts(uint64_t &pts) /* if (videoDecoder->fd >= 0) { - if (::ioctl(videoDecoder->fd, VIDEO_GET_PTS, &pts) >= 0) - { - return; - } + if (::ioctl(videoDecoder->fd, VIDEO_GET_PTS, &pts) >= 0) + { + return; + } } if (audioDecoder->fd >= 0) { - if (::ioctl(audioDecoder->fd, AUDIO_GET_PTS, &pts) >= 0) - { - return; - } + if (::ioctl(audioDecoder->fd, AUDIO_GET_PTS, &pts) >= 0) + { + return; + } }*/ } @@ -493,121 +493,121 @@ const char *cPlayback::getVidFormatStr(uint32_t format) { switch (format) { - case HI_FORMAT_VIDEO_MPEG2: - return "MPEG2"; - break; + case HI_FORMAT_VIDEO_MPEG2: + return "MPEG2"; + break; - case HI_FORMAT_VIDEO_MPEG4: - return "MPEG4"; - break; + case HI_FORMAT_VIDEO_MPEG4: + return "MPEG4"; + break; - case HI_FORMAT_VIDEO_AVS: - return "AVS"; - break; + case HI_FORMAT_VIDEO_AVS: + return "AVS"; + break; - case HI_FORMAT_VIDEO_H263: - return "H263"; - break; + case HI_FORMAT_VIDEO_H263: + return "H263"; + break; - case HI_FORMAT_VIDEO_H264: - return "H264"; - break; + case HI_FORMAT_VIDEO_H264: + return "H264"; + break; - case HI_FORMAT_VIDEO_REAL8: - return "REAL8"; - break; + case HI_FORMAT_VIDEO_REAL8: + return "REAL8"; + break; - case HI_FORMAT_VIDEO_REAL9: - return "REAL9"; - break; + case HI_FORMAT_VIDEO_REAL9: + return "REAL9"; + break; - case HI_FORMAT_VIDEO_VC1: - return "VC1"; - break; + case HI_FORMAT_VIDEO_VC1: + return "VC1"; + break; - case HI_FORMAT_VIDEO_VP6: - return "VP6"; - break; + case HI_FORMAT_VIDEO_VP6: + return "VP6"; + break; - case HI_FORMAT_VIDEO_DIVX3: - return "DIVX3"; - break; + case HI_FORMAT_VIDEO_DIVX3: + return "DIVX3"; + break; - case HI_FORMAT_VIDEO_RAW: - return "RAW"; - break; + case HI_FORMAT_VIDEO_RAW: + return "RAW"; + break; - case HI_FORMAT_VIDEO_JPEG: - return "JPEG"; - break; + case HI_FORMAT_VIDEO_JPEG: + return "JPEG"; + break; - case HI_FORMAT_VIDEO_MJPEG: - return "MJPEG"; - break; - case HI_FORMAT_VIDEO_MJPEGB: - return "MJPEGB"; - break; - case HI_FORMAT_VIDEO_SORENSON: - return "SORENSON"; - break; + case HI_FORMAT_VIDEO_MJPEG: + return "MJPEG"; + break; + case HI_FORMAT_VIDEO_MJPEGB: + return "MJPEGB"; + break; + case HI_FORMAT_VIDEO_SORENSON: + return "SORENSON"; + break; - case HI_FORMAT_VIDEO_VP6F: - return "VP6F"; - break; + case HI_FORMAT_VIDEO_VP6F: + return "VP6F"; + break; - case HI_FORMAT_VIDEO_VP6A: - return "VP6A"; - break; + case HI_FORMAT_VIDEO_VP6A: + return "VP6A"; + break; - case HI_FORMAT_VIDEO_VP8: - return "VP8"; - break; - case HI_FORMAT_VIDEO_MVC: - return "MVC"; - break; - case HI_FORMAT_VIDEO_SVQ1: - return "SORENSON1"; - break; - case HI_FORMAT_VIDEO_SVQ3: - return "SORENSON3"; - break; - case HI_FORMAT_VIDEO_DV: - return "DV"; - break; - case HI_FORMAT_VIDEO_WMV1: - return "WMV1"; - break; - case HI_FORMAT_VIDEO_WMV2: - return "WMV2"; - break; - case HI_FORMAT_VIDEO_MSMPEG4V1: - return "MICROSOFT MPEG4V1"; - break; - case HI_FORMAT_VIDEO_MSMPEG4V2: - return "MICROSOFT MPEG4V2"; - break; - case HI_FORMAT_VIDEO_CINEPAK: - return "CINEPACK"; - break; - case HI_FORMAT_VIDEO_RV10: - return "RV10"; - break; - case HI_FORMAT_VIDEO_RV20: - return "RV20"; - break; - case HI_FORMAT_VIDEO_INDEO4: - return "INDEO4"; - break; - case HI_FORMAT_VIDEO_INDEO5: - return "INDEO5"; - break; - case HI_FORMAT_VIDEO_HEVC: - return "H265"; - case HI_FORMAT_VIDEO_VP9: - return "VP9"; - default: - return "UNKNOWN"; - break; + case HI_FORMAT_VIDEO_VP8: + return "VP8"; + break; + case HI_FORMAT_VIDEO_MVC: + return "MVC"; + break; + case HI_FORMAT_VIDEO_SVQ1: + return "SORENSON1"; + break; + case HI_FORMAT_VIDEO_SVQ3: + return "SORENSON3"; + break; + case HI_FORMAT_VIDEO_DV: + return "DV"; + break; + case HI_FORMAT_VIDEO_WMV1: + return "WMV1"; + break; + case HI_FORMAT_VIDEO_WMV2: + return "WMV2"; + break; + case HI_FORMAT_VIDEO_MSMPEG4V1: + return "MICROSOFT MPEG4V1"; + break; + case HI_FORMAT_VIDEO_MSMPEG4V2: + return "MICROSOFT MPEG4V2"; + break; + case HI_FORMAT_VIDEO_CINEPAK: + return "CINEPACK"; + break; + case HI_FORMAT_VIDEO_RV10: + return "RV10"; + break; + case HI_FORMAT_VIDEO_RV20: + return "RV20"; + break; + case HI_FORMAT_VIDEO_INDEO4: + return "INDEO4"; + break; + case HI_FORMAT_VIDEO_INDEO5: + return "INDEO5"; + break; + case HI_FORMAT_VIDEO_HEVC: + return "H265"; + case HI_FORMAT_VIDEO_VP9: + return "VP9"; + default: + return "UNKNOWN"; + break; } return "UNKNOWN"; @@ -617,218 +617,218 @@ const char *cPlayback::getAudFormatStr(uint32_t format) { switch (format) { - case HI_FORMAT_AUDIO_MP2: - return "MPEG2"; - break; - case HI_FORMAT_AUDIO_MP3: - return "MPEG3"; - break; - case HI_FORMAT_AUDIO_AAC: - return "AAC"; - break; - case HI_FORMAT_AUDIO_AC3: - return "AC3"; - break; - case HI_FORMAT_AUDIO_DTS: - return "DTS"; - break; - case HI_FORMAT_AUDIO_VORBIS: - return "VORBIS"; - break; - case HI_FORMAT_AUDIO_DVAUDIO: - return "DVAUDIO"; - break; - case HI_FORMAT_AUDIO_WMAV1: - return "WMAV1"; - break; - case HI_FORMAT_AUDIO_WMAV2: - return "WMAV2"; - break; - case HI_FORMAT_AUDIO_MACE3: - return "MACE3"; - break; - case HI_FORMAT_AUDIO_MACE6: - return "MACE6"; - break; - case HI_FORMAT_AUDIO_VMDAUDIO: - return "VMDAUDIO"; - break; - case HI_FORMAT_AUDIO_SONIC: - return "SONIC"; - break; - case HI_FORMAT_AUDIO_SONIC_LS: - return "SONIC_LS"; - break; - case HI_FORMAT_AUDIO_FLAC: - return "FLAC"; - break; - case HI_FORMAT_AUDIO_MP3ADU: - return "MP3ADU"; - break; - case HI_FORMAT_AUDIO_MP3ON4: - return "MP3ON4"; - break; - case HI_FORMAT_AUDIO_SHORTEN: - return "SHORTEN"; - break; - case HI_FORMAT_AUDIO_ALAC: - return "ALAC"; - break; - case HI_FORMAT_AUDIO_WESTWOOD_SND1: - return "WESTWOOD_SND1"; - break; - case HI_FORMAT_AUDIO_GSM: - return "GSM"; - break; - case HI_FORMAT_AUDIO_QDM2: - return "QDM2"; - break; - case HI_FORMAT_AUDIO_COOK: - return "COOK"; - break; - case HI_FORMAT_AUDIO_TRUESPEECH: - return "TRUESPEECH"; - break; - case HI_FORMAT_AUDIO_TTA: - return "TTA"; - break; - case HI_FORMAT_AUDIO_SMACKAUDIO: - return "SMACKAUDIO"; - break; - case HI_FORMAT_AUDIO_QCELP: - return "QCELP"; - break; - case HI_FORMAT_AUDIO_WAVPACK: - return "WAVPACK"; - break; - case HI_FORMAT_AUDIO_DSICINAUDIO: - return "DSICINAUDIO"; - break; - case HI_FORMAT_AUDIO_IMC: - return "IMC"; - break; - case HI_FORMAT_AUDIO_MUSEPACK7: - return "MUSEPACK7"; - break; - case HI_FORMAT_AUDIO_MLP: - return "MLP"; - break; - case HI_FORMAT_AUDIO_GSM_MS: - return "GSM_MS"; - break; - case HI_FORMAT_AUDIO_ATRAC3: - return "ATRAC3"; - break; - case HI_FORMAT_AUDIO_VOXWARE: - return "VOXWARE"; - break; - case HI_FORMAT_AUDIO_APE: - return "APE"; - break; - case HI_FORMAT_AUDIO_NELLYMOSER: - return "NELLYMOSER"; - break; - case HI_FORMAT_AUDIO_MUSEPACK8: - return "MUSEPACK8"; - break; - case HI_FORMAT_AUDIO_SPEEX: - return "SPEEX"; - break; - case HI_FORMAT_AUDIO_WMAVOICE: - return "WMAVOICE"; - break; - case HI_FORMAT_AUDIO_WMAPRO: - return "WMAPRO"; - break; - case HI_FORMAT_AUDIO_WMALOSSLESS: - return "WMALOSSLESS"; - break; - case HI_FORMAT_AUDIO_ATRAC3P: - return "ATRAC3P"; - break; - case HI_FORMAT_AUDIO_EAC3: - return "EAC3"; - break; - case HI_FORMAT_AUDIO_SIPR: - return "SIPR"; - break; - case HI_FORMAT_AUDIO_MP1: - return "MP1"; - break; - case HI_FORMAT_AUDIO_TWINVQ: - return "TWINVQ"; - break; - case HI_FORMAT_AUDIO_TRUEHD: - return "TRUEHD"; - break; - case HI_FORMAT_AUDIO_MP4ALS: - return "MP4ALS"; - break; - case HI_FORMAT_AUDIO_ATRAC1: - return "ATRAC1"; - break; - case HI_FORMAT_AUDIO_BINKAUDIO_RDFT: - return "BINKAUDIO_RDFT"; - break; - case HI_FORMAT_AUDIO_BINKAUDIO_DCT: - return "BINKAUDIO_DCT"; - break; - case HI_FORMAT_AUDIO_DRA: - return "DRA"; - break; + case HI_FORMAT_AUDIO_MP2: + return "MPEG2"; + break; + case HI_FORMAT_AUDIO_MP3: + return "MPEG3"; + break; + case HI_FORMAT_AUDIO_AAC: + return "AAC"; + break; + case HI_FORMAT_AUDIO_AC3: + return "AC3"; + break; + case HI_FORMAT_AUDIO_DTS: + return "DTS"; + break; + case HI_FORMAT_AUDIO_VORBIS: + return "VORBIS"; + break; + case HI_FORMAT_AUDIO_DVAUDIO: + return "DVAUDIO"; + break; + case HI_FORMAT_AUDIO_WMAV1: + return "WMAV1"; + break; + case HI_FORMAT_AUDIO_WMAV2: + return "WMAV2"; + break; + case HI_FORMAT_AUDIO_MACE3: + return "MACE3"; + break; + case HI_FORMAT_AUDIO_MACE6: + return "MACE6"; + break; + case HI_FORMAT_AUDIO_VMDAUDIO: + return "VMDAUDIO"; + break; + case HI_FORMAT_AUDIO_SONIC: + return "SONIC"; + break; + case HI_FORMAT_AUDIO_SONIC_LS: + return "SONIC_LS"; + break; + case HI_FORMAT_AUDIO_FLAC: + return "FLAC"; + break; + case HI_FORMAT_AUDIO_MP3ADU: + return "MP3ADU"; + break; + case HI_FORMAT_AUDIO_MP3ON4: + return "MP3ON4"; + break; + case HI_FORMAT_AUDIO_SHORTEN: + return "SHORTEN"; + break; + case HI_FORMAT_AUDIO_ALAC: + return "ALAC"; + break; + case HI_FORMAT_AUDIO_WESTWOOD_SND1: + return "WESTWOOD_SND1"; + break; + case HI_FORMAT_AUDIO_GSM: + return "GSM"; + break; + case HI_FORMAT_AUDIO_QDM2: + return "QDM2"; + break; + case HI_FORMAT_AUDIO_COOK: + return "COOK"; + break; + case HI_FORMAT_AUDIO_TRUESPEECH: + return "TRUESPEECH"; + break; + case HI_FORMAT_AUDIO_TTA: + return "TTA"; + break; + case HI_FORMAT_AUDIO_SMACKAUDIO: + return "SMACKAUDIO"; + break; + case HI_FORMAT_AUDIO_QCELP: + return "QCELP"; + break; + case HI_FORMAT_AUDIO_WAVPACK: + return "WAVPACK"; + break; + case HI_FORMAT_AUDIO_DSICINAUDIO: + return "DSICINAUDIO"; + break; + case HI_FORMAT_AUDIO_IMC: + return "IMC"; + break; + case HI_FORMAT_AUDIO_MUSEPACK7: + return "MUSEPACK7"; + break; + case HI_FORMAT_AUDIO_MLP: + return "MLP"; + break; + case HI_FORMAT_AUDIO_GSM_MS: + return "GSM_MS"; + break; + case HI_FORMAT_AUDIO_ATRAC3: + return "ATRAC3"; + break; + case HI_FORMAT_AUDIO_VOXWARE: + return "VOXWARE"; + break; + case HI_FORMAT_AUDIO_APE: + return "APE"; + break; + case HI_FORMAT_AUDIO_NELLYMOSER: + return "NELLYMOSER"; + break; + case HI_FORMAT_AUDIO_MUSEPACK8: + return "MUSEPACK8"; + break; + case HI_FORMAT_AUDIO_SPEEX: + return "SPEEX"; + break; + case HI_FORMAT_AUDIO_WMAVOICE: + return "WMAVOICE"; + break; + case HI_FORMAT_AUDIO_WMAPRO: + return "WMAPRO"; + break; + case HI_FORMAT_AUDIO_WMALOSSLESS: + return "WMALOSSLESS"; + break; + case HI_FORMAT_AUDIO_ATRAC3P: + return "ATRAC3P"; + break; + case HI_FORMAT_AUDIO_EAC3: + return "EAC3"; + break; + case HI_FORMAT_AUDIO_SIPR: + return "SIPR"; + break; + case HI_FORMAT_AUDIO_MP1: + return "MP1"; + break; + case HI_FORMAT_AUDIO_TWINVQ: + return "TWINVQ"; + break; + case HI_FORMAT_AUDIO_TRUEHD: + return "TRUEHD"; + break; + case HI_FORMAT_AUDIO_MP4ALS: + return "MP4ALS"; + break; + case HI_FORMAT_AUDIO_ATRAC1: + return "ATRAC1"; + break; + case HI_FORMAT_AUDIO_BINKAUDIO_RDFT: + return "BINKAUDIO_RDFT"; + break; + case HI_FORMAT_AUDIO_BINKAUDIO_DCT: + return "BINKAUDIO_DCT"; + break; + case HI_FORMAT_AUDIO_DRA: + return "DRA"; + break; - case HI_FORMAT_AUDIO_PCM: /* various PCM "codecs" */ - return "PCM"; - break; + case HI_FORMAT_AUDIO_PCM: /* various PCM "codecs" */ + return "PCM"; + break; - case HI_FORMAT_AUDIO_ADPCM: /* various ADPCM codecs */ - return "ADPCM"; - break; + case HI_FORMAT_AUDIO_ADPCM: /* various ADPCM codecs */ + return "ADPCM"; + break; - case HI_FORMAT_AUDIO_AMR_NB: /* AMR */ - return "AMR_NB"; - break; - case HI_FORMAT_AUDIO_AMR_WB: - return "AMR_WB"; - break; - case HI_FORMAT_AUDIO_AMR_AWB: - return "AMR_AWB"; - break; + case HI_FORMAT_AUDIO_AMR_NB: /* AMR */ + return "AMR_NB"; + break; + case HI_FORMAT_AUDIO_AMR_WB: + return "AMR_WB"; + break; + case HI_FORMAT_AUDIO_AMR_AWB: + return "AMR_AWB"; + break; - case HI_FORMAT_AUDIO_RA_144: /* RealAudio codecs*/ - return "RA_144"; - break; - case HI_FORMAT_AUDIO_RA_288: - return "RA_288"; - break; + case HI_FORMAT_AUDIO_RA_144: /* RealAudio codecs*/ + return "RA_144"; + break; + case HI_FORMAT_AUDIO_RA_288: + return "RA_288"; + break; - case HI_FORMAT_AUDIO_DPCM: /* various DPCM codecs */ - return "DPCM"; - break; + case HI_FORMAT_AUDIO_DPCM: /* various DPCM codecs */ + return "DPCM"; + break; - case HI_FORMAT_AUDIO_G711: /* various G.7xx codecs */ - return "G711"; - break; - case HI_FORMAT_AUDIO_G722: - return "G722"; - break; - case HI_FORMAT_AUDIO_G7231: - return "G7231"; - break; - case HI_FORMAT_AUDIO_G726: - return "G726"; - break; - case HI_FORMAT_AUDIO_G728: - return "G728"; - break; - case HI_FORMAT_AUDIO_G729AB: - return "G729AB"; - break; - case HI_FORMAT_AUDIO_PCM_BLURAY: - return "PCM_BLURAY"; - break; - default: - break; + case HI_FORMAT_AUDIO_G711: /* various G.7xx codecs */ + return "G711"; + break; + case HI_FORMAT_AUDIO_G722: + return "G722"; + break; + case HI_FORMAT_AUDIO_G7231: + return "G7231"; + break; + case HI_FORMAT_AUDIO_G726: + return "G726"; + break; + case HI_FORMAT_AUDIO_G728: + return "G728"; + break; + case HI_FORMAT_AUDIO_G729AB: + return "G729AB"; + break; + case HI_FORMAT_AUDIO_PCM_BLURAY: + return "PCM_BLURAY"; + break; + default: + break; } return "UNKNOWN"; @@ -838,42 +838,42 @@ const char *cPlayback::getSubFormatStr(uint32_t format) { switch (format) { - case HI_FORMAT_SUBTITLE_ASS: - return "ASS"; - break; - case HI_FORMAT_SUBTITLE_LRC: - return "LRC"; - break; - case HI_FORMAT_SUBTITLE_SRT: - return "SRT"; - break; - case HI_FORMAT_SUBTITLE_SMI: - return "SMI"; - break; - case HI_FORMAT_SUBTITLE_SUB: - return "SUB"; - break; - case HI_FORMAT_SUBTITLE_TXT: - return "TEXT"; - break; - case HI_FORMAT_SUBTITLE_HDMV_PGS: - return "HDMV_PGS"; - break; - case HI_FORMAT_SUBTITLE_DVB_SUB: - return "DVB_SUB_BMP"; - break; - case HI_FORMAT_SUBTITLE_DVD_SUB: - return "DVD_SUB_BMP"; - break; - default: - return "UNKNOWN"; - break; + case HI_FORMAT_SUBTITLE_ASS: + return "ASS"; + break; + case HI_FORMAT_SUBTITLE_LRC: + return "LRC"; + break; + case HI_FORMAT_SUBTITLE_SRT: + return "SRT"; + break; + case HI_FORMAT_SUBTITLE_SMI: + return "SMI"; + break; + case HI_FORMAT_SUBTITLE_SUB: + return "SUB"; + break; + case HI_FORMAT_SUBTITLE_TXT: + return "TEXT"; + break; + case HI_FORMAT_SUBTITLE_HDMV_PGS: + return "HDMV_PGS"; + break; + case HI_FORMAT_SUBTITLE_DVB_SUB: + return "DVB_SUB_BMP"; + break; + case HI_FORMAT_SUBTITLE_DVD_SUB: + return "DVD_SUB_BMP"; + break; + default: + return "UNKNOWN"; + break; } return "UNKNOWN"; } -netlink_event * netlink_event::netlink_event_instance = NULL; +netlink_event *netlink_event::netlink_event_instance = NULL; netlink_event::netlink_event() { @@ -889,7 +889,7 @@ netlink_event::~netlink_event() } } -netlink_event* netlink_event::getInstance() +netlink_event *netlink_event::getInstance() { if (netlink_event_instance == NULL) { @@ -899,7 +899,7 @@ netlink_event* netlink_event::getInstance() return netlink_event_instance; } -bool netlink_event::Start(cPlayback * _player) +bool netlink_event::Start(cPlayback *_player) { if (running) return false; @@ -914,7 +914,7 @@ bool netlink_event::Start(cPlayback * _player) src_addr.nl_family = AF_NETLINK; src_addr.nl_pid = getpid(); /* self pid */ netlink_socket = socket(PF_NETLINK, SOCK_RAW, 30); - bind(netlink_socket, (struct sockaddr*)&src_addr, sizeof(src_addr)); + bind(netlink_socket, (struct sockaddr *)&src_addr, sizeof(src_addr)); nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD)); @@ -984,244 +984,244 @@ void netlink_event::Receive() int readlen = receive_netlink_message(); if (readlen > 0) { - int decoder = *((uint32_t*)NLMSG_DATA(nlh)) >> 24; - int msgtype = *((uint32_t*)NLMSG_DATA(nlh)) & 0xffffff; + int decoder = *((uint32_t *)NLMSG_DATA(nlh)) >> 24; + int msgtype = *((uint32_t *)NLMSG_DATA(nlh)) & 0xffffff; switch (msgtype) { #if 0 - case 2: /* subtitle data */ - if (m_currentSubtitleStream >= 0 && m_subtitle_widget && !m_paused) - { - struct subtitleheader + case 2: /* subtitle data */ + if (m_currentSubtitleStream >= 0 && m_subtitle_widget && !m_paused) { - uint64_t pts; - uint32_t duration; - uint32_t datasize; - } header; - memcpy(&header, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(header)); - ePangoSubtitlePage pango_page; - gRGB rgbcol(0xD0,0xD0,0xD0); - pango_page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)NLMSG_DATA(nlh) + sizeof(uint32_t) + sizeof(header))); - pango_page.m_show_pts = header.pts; /* ignored by widget (TODO?) */ - pango_page.m_timeout = 8000; - m_subtitle_widget->setPage(pango_page); - } - break; - case 3: /* clear subtitles */ - if (m_currentSubtitleStream >= 0 && m_subtitle_widget) - { - ePangoSubtitlePage pango_page; - pango_page.m_show_pts = 0; - pango_page.m_timeout = 0; - m_subtitle_widget->setPage(pango_page); - } - break; + struct subtitleheader + { + uint64_t pts; + uint32_t duration; + uint32_t datasize; + } header; + memcpy(&header, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(header)); + ePangoSubtitlePage pango_page; + gRGB rgbcol(0xD0, 0xD0, 0xD0); + pango_page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char *)NLMSG_DATA(nlh) + sizeof(uint32_t) + sizeof(header))); + pango_page.m_show_pts = header.pts; /* ignored by widget (TODO?) */ + pango_page.m_timeout = 8000; + m_subtitle_widget->setPage(pango_page); + } + break; + case 3: /* clear subtitles */ + if (m_currentSubtitleStream >= 0 && m_subtitle_widget) + { + ePangoSubtitlePage pango_page; + pango_page.m_show_pts = 0; + pango_page.m_timeout = 0; + m_subtitle_widget->setPage(pango_page); + } + break; #endif - case 4: /* file info */ - memcpy(&fileinfo, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(fileinfo)); - fileinfo.pastProgramInfo = (HI_FORMAT_PROGRAM_INFO_S*)malloc(fileinfo.u32ProgramNum * sizeof(HI_FORMAT_PROGRAM_INFO_S)); - fileinfo.u32ProgramNum = 0; - break; - case 5: /* program info */ - memcpy(&fileinfo.pastProgramInfo[fileinfo.u32ProgramNum], (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(HI_FORMAT_PROGRAM_INFO_S)); - fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].pastVidStream = (HI_FORMAT_VID_INFO_S*)malloc(fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32VidStreamNum * sizeof(HI_FORMAT_VID_INFO_S)); - fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32VidStreamNum = 0; - fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].pastAudStream = (HI_FORMAT_AUD_INFO_S*)malloc(fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32AudStreamNum * sizeof(HI_FORMAT_AUD_INFO_S)); - fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32AudStreamNum = 0; - fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].pastSubStream = (HI_FORMAT_SUB_INFO_S*)malloc(fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32SubStreamNum * sizeof(HI_FORMAT_SUB_INFO_S)); - fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32SubStreamNum = 0; - fileinfo.u32ProgramNum++; - break; - case 6: /* video stream */ - memcpy(&fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].pastVidStream[fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32VidStreamNum], (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(HI_FORMAT_VID_INFO_S)); - fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32VidStreamNum++; - break; - case 7: /* audio stream */ - memcpy(&fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].pastAudStream[fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32AudStreamNum], (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(HI_FORMAT_AUD_INFO_S)); - fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32AudStreamNum++; - break; - case 8: /* subtitle stream */ - memcpy(&fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].pastSubStream[fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32SubStreamNum], (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(HI_FORMAT_SUB_INFO_S)); - fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32SubStreamNum++; - break; - case 9: /* stream id */ - memcpy(&streamid, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(streamid)); - hal_debug("[HSP] streamid: program %u, video %u, audio %u, subtitle %u", streamid.programid, streamid.videostreamid, streamid.audiostreamid, streamid.subtitlestreamid); - player->mAudioStream = streamid.audiostreamid; - player->mSubtitleStream = streamid.subtitlestreamid; - break; - case 10: /* player state */ - { - int32_t state; - memcpy(&state, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(state)); - hal_debug("[HSP] player state %d-->%d", m_player_state, state); - switch (state) + case 4: /* file info */ + memcpy(&fileinfo, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(fileinfo)); + fileinfo.pastProgramInfo = (HI_FORMAT_PROGRAM_INFO_S *)malloc(fileinfo.u32ProgramNum * sizeof(HI_FORMAT_PROGRAM_INFO_S)); + fileinfo.u32ProgramNum = 0; + break; + case 5: /* program info */ + memcpy(&fileinfo.pastProgramInfo[fileinfo.u32ProgramNum], (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(HI_FORMAT_PROGRAM_INFO_S)); + fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].pastVidStream = (HI_FORMAT_VID_INFO_S *)malloc(fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32VidStreamNum * sizeof(HI_FORMAT_VID_INFO_S)); + fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32VidStreamNum = 0; + fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].pastAudStream = (HI_FORMAT_AUD_INFO_S *)malloc(fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32AudStreamNum * sizeof(HI_FORMAT_AUD_INFO_S)); + fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32AudStreamNum = 0; + fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].pastSubStream = (HI_FORMAT_SUB_INFO_S *)malloc(fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32SubStreamNum * sizeof(HI_FORMAT_SUB_INFO_S)); + fileinfo.pastProgramInfo[fileinfo.u32ProgramNum].u32SubStreamNum = 0; + fileinfo.u32ProgramNum++; + break; + case 6: /* video stream */ + memcpy(&fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].pastVidStream[fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32VidStreamNum], (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(HI_FORMAT_VID_INFO_S)); + fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32VidStreamNum++; + break; + case 7: /* audio stream */ + memcpy(&fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].pastAudStream[fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32AudStreamNum], (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(HI_FORMAT_AUD_INFO_S)); + fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32AudStreamNum++; + break; + case 8: /* subtitle stream */ + memcpy(&fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].pastSubStream[fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32SubStreamNum], (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(HI_FORMAT_SUB_INFO_S)); + fileinfo.pastProgramInfo[fileinfo.u32ProgramNum - 1].u32SubStreamNum++; + break; + case 9: /* stream id */ + memcpy(&streamid, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(streamid)); + hal_debug("[HSP] streamid: program %u, video %u, audio %u, subtitle %u", streamid.programid, streamid.videostreamid, streamid.audiostreamid, streamid.subtitlestreamid); + player->mAudioStream = streamid.audiostreamid; + player->mSubtitleStream = streamid.subtitlestreamid; + break; + case 10: /* player state */ { - case 0: /* init */ - break; - case 1: /* deinit */ - break; - case 2: /* play */ - if (m_state != stRunning) + int32_t state; + memcpy(&state, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(state)); + hal_debug("[HSP] player state %d-->%d", m_player_state, state); + switch (state) { - m_state = stRunning; + case 0: /* init */ + break; + case 1: /* deinit */ + break; + case 2: /* play */ + if (m_state != stRunning) + { + m_state = stRunning; + } + m_paused = false; + break; + case 3: /* fast forward */ + break; + case 4: /* rewind */ + break; + case 5: /* pause */ + m_paused = true; + break; + case 6: /* stop */ + m_paused = false; + break; + case 7: /* preparing */ + break; } - m_paused = false; - break; - case 3: /* fast forward */ - break; - case 4: /* rewind */ - break; - case 5: /* pause */ - m_paused = true; - break; - case 6: /* stop */ - m_paused = false; - break; - case 7: /* preparing */ - break; + m_player_state = state; + player->playing = (state < 6); } - m_player_state = state; - player->playing = (state < 6); - } - break; - case 11: /* error */ - { - int32_t error; - memcpy(&error, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(error)); - switch (error) + break; + case 11: /* error */ { - case 0: /* no error */ - break; - case 1: /* video playback failed */ - m_errorInfo.error_message = "video playback failed"; - break; - case 2: /* audio playback failed */ - m_errorInfo.error_message = "audio playback failed"; - break; - case 3: /* subtitle playback failed */ - m_errorInfo.error_message = "subtitle playback failed"; - break; - case 4: /* media playback failed */ - m_errorInfo.error_message = "media playback failed"; - break; - case 5: /* timeout */ - m_errorInfo.error_message = "timeout"; - break; - case 6: /* file format not supported */ - m_errorInfo.error_message = "format not supported"; - break; - case 7: /* unknown error */ - m_errorInfo.error_message = "unknown error"; - break; - case 8: /* I-frame decoding error */ - break; - } - hal_debug("[HSP] error %s (%d)", m_errorInfo.error_message.c_str(), error); - } - break; - case 12: /* buffering */ - { - struct bufferinfo - { - uint32_t status; - uint32_t percentage; - } info; - memcpy(&info, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(info)); - hal_debug("[HSP] buffering %u %u%%", info.status, info.percentage); - m_bufferpercentage = info.percentage; - switch (info.status) - { - case 0: /* empty */ - case 1: /* insufficient */ - if (!m_buffering) + int32_t error; + memcpy(&error, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(error)); + switch (error) { - m_buffering = true; - hal_debug("[HSP] start buffering....pause playback"); - player->SetSpeed(0); + case 0: /* no error */ + break; + case 1: /* video playback failed */ + m_errorInfo.error_message = "video playback failed"; + break; + case 2: /* audio playback failed */ + m_errorInfo.error_message = "audio playback failed"; + break; + case 3: /* subtitle playback failed */ + m_errorInfo.error_message = "subtitle playback failed"; + break; + case 4: /* media playback failed */ + m_errorInfo.error_message = "media playback failed"; + break; + case 5: /* timeout */ + m_errorInfo.error_message = "timeout"; + break; + case 6: /* file format not supported */ + m_errorInfo.error_message = "format not supported"; + break; + case 7: /* unknown error */ + m_errorInfo.error_message = "unknown error"; + break; + case 8: /* I-frame decoding error */ + break; } - break; - case 2: /* enough */ - case 3: /* full */ - if (m_buffering) + hal_debug("[HSP] error %s (%d)", m_errorInfo.error_message.c_str(), error); + } + break; + case 12: /* buffering */ + { + struct bufferinfo + { + uint32_t status; + uint32_t percentage; + } info; + memcpy(&info, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(info)); + hal_debug("[HSP] buffering %u %u%%", info.status, info.percentage); + m_bufferpercentage = info.percentage; + switch (info.status) + { + case 0: /* empty */ + case 1: /* insufficient */ + if (!m_buffering) + { + m_buffering = true; + hal_debug("[HSP] start buffering....pause playback"); + player->SetSpeed(0); + } + break; + case 2: /* enough */ + case 3: /* full */ + if (m_buffering) + { + m_buffering = false; + hal_debug("[HSP] end buffering....continue playback"); + player->SetSpeed(1); + } + break; + default: + break; + } + } + break; + case 13: /* network info */ + { + struct networkinfo + { + uint32_t status; + int32_t errorcode; + } info; + memcpy(&info, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(info)); + switch (info.status) + { + case 0: /* network: unknown error */ + m_errorInfo.error_message = "network: error"; + break; + case 1: /* network: failed to connect */ + m_errorInfo.error_message = "network: connection failed"; + break; + case 2: /* network: timeout */ + m_errorInfo.error_message = "network: timeout"; + break; + case 3: /* network: disconnected */ + m_errorInfo.error_message = "network: disconnected"; + break; + case 4: /* network: file not found */ + m_errorInfo.error_message = "network: file not found"; + break; + case 5: /* network: status ok */ + m_errorInfo.error_message = "network: status ok"; + break; + case 6: /* network: http errorcode */ + m_errorInfo.error_message = "network: http errorcode"; + break; + case 7: /* network: bitrate adjusted */ + m_errorInfo.error_message = "network: bitrate adjusted"; + break; + } + hal_debug("[HSP] network info %s (%u) %d", m_errorInfo.error_message.c_str(), info.status, info.errorcode); + } + break; + case 14: /* event */ + { + int32_t event; + memcpy(&event, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(event)); + switch (event) + { + case 0: /* SOF */ + hal_debug("[HSP] event: SOF"); + /* reached SOF while rewinding */ + break; + case 1: /* EOF */ + hal_debug("[HSP] event: EOF"); + break; + } + } + break; + case 15: /* seekable */ + memcpy(&m_seekable, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(m_seekable)); + break; + case 16: /* download progress */ + memcpy(&m_download_progress, (unsigned char *)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(m_download_progress)); + hal_debug("[HSP] dl progress: %d", m_download_progress); + if (m_download_progress >= 100) { - m_buffering = false; - hal_debug("[HSP] end buffering....continue playback"); player->SetSpeed(1); } break; default: break; - } - } - break; - case 13: /* network info */ - { - struct networkinfo - { - uint32_t status; - int32_t errorcode; - } info; - memcpy(&info, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(info)); - switch (info.status) - { - case 0: /* network: unknown error */ - m_errorInfo.error_message = "network: error"; - break; - case 1: /* network: failed to connect */ - m_errorInfo.error_message = "network: connection failed"; - break; - case 2: /* network: timeout */ - m_errorInfo.error_message = "network: timeout"; - break; - case 3: /* network: disconnected */ - m_errorInfo.error_message = "network: disconnected"; - break; - case 4: /* network: file not found */ - m_errorInfo.error_message = "network: file not found"; - break; - case 5: /* network: status ok */ - m_errorInfo.error_message = "network: status ok"; - break; - case 6: /* network: http errorcode */ - m_errorInfo.error_message = "network: http errorcode"; - break; - case 7: /* network: bitrate adjusted */ - m_errorInfo.error_message = "network: bitrate adjusted"; - break; - } - hal_debug("[HSP] network info %s (%u) %d", m_errorInfo.error_message.c_str(), info.status, info.errorcode); - } - break; - case 14: /* event */ - { - int32_t event; - memcpy(&event, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(event)); - switch (event) - { - case 0: /* SOF */ - hal_debug("[HSP] event: SOF"); - /* reached SOF while rewinding */ - break; - case 1: /* EOF */ - hal_debug("[HSP] event: EOF"); - break; - } - } - break; - case 15: /* seekable */ - memcpy(&m_seekable, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(m_seekable)); - break; - case 16: /* download progress */ - memcpy(&m_download_progress, (unsigned char*)NLMSG_DATA(nlh) + sizeof(uint32_t), sizeof(m_download_progress)); - hal_debug("[HSP] dl progress: %d", m_download_progress); - if (m_download_progress >= 100) - { - player->SetSpeed(1); - } - break; - default: - break; } } } diff --git a/libarmbox/playback_hisilicon.h b/libarmbox/playback_hisilicon.h index b6bc7d0..225e5c4 100644 --- a/libarmbox/playback_hisilicon.h +++ b/libarmbox/playback_hisilicon.h @@ -1,20 +1,20 @@ /* - Copyright (C) 2018 TangoCash + Copyright (C) 2018 TangoCash - License: GPLv2 + License: GPLv2 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __HAL_PLAYBACK_H @@ -44,141 +44,141 @@ struct errorInfo class cPlayback { - friend class CStreamInfo2; - friend class netlink_event; + friend class CStreamInfo2; + friend class netlink_event; -private: - int m_video_fd; - int m_audio_fd; - bool enabled; - bool playing, first; - bool no_probe; - bool got_vpts_ts; - int nPlaybackSpeed; - int mAudioStream; - int mSubtitleStream; - int mTeletextStream; - int64_t vpts_ts; - bool Stop(void); - bool decoders_closed; - playmode_t pm; - std::string fn_ts; - std::string fn_xml; - off64_t last_size; - int init_jump; - const char *getVidFormatStr(uint32_t format); - const char *getAudFormatStr(uint32_t format); - const char *getSubFormatStr(uint32_t format); + private: + int m_video_fd; + int m_audio_fd; + bool enabled; + bool playing, first; + bool no_probe; + bool got_vpts_ts; + int nPlaybackSpeed; + int mAudioStream; + int mSubtitleStream; + int mTeletextStream; + int64_t vpts_ts; + bool Stop(void); + bool decoders_closed; + playmode_t pm; + std::string fn_ts; + std::string fn_xml; + off64_t last_size; + int init_jump; + const char *getVidFormatStr(uint32_t format); + const char *getAudFormatStr(uint32_t format); + const char *getSubFormatStr(uint32_t format); -public: - cPlayback(int num = 0); - ~cPlayback(); + public: + cPlayback(int num = 0); + ~cPlayback(); - bool Open(playmode_t PlayMode); - void Close(void); - bool Start(char *filename, int vpid, int vtype, int apid, int ac3, int duration, std::string headers = "", std::string filename2 = ""); - bool Start(std::string filename, std::string headers = "", std::string filename2 = ""); - bool SetAPid(int pid, bool ac3 = false); - bool SetVPid(int /*pid*/); - bool SetSubtitlePid(int pid); - bool SetTeletextPid(int pid); - int GetAPid(void) - { - return mAudioStream; - } - int GetVPid(void) - { - return 0; - } - int GetSubtitlePid(void) - { - return mSubtitleStream; - } - int GetTeletextPid(void); - bool SetSpeed(int speed); - bool GetSpeed(int &speed) const; - bool GetPosition(int &position, int &duration); - void GetPts(uint64_t &pts); - bool SetPosition(int position, bool absolute = false); - void FindAllPids(short unsigned int *apids, short unsigned int *ac3flags, short unsigned int *numpida, std::string *language); - void FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language); - void FindAllTeletextsubtitlePids(int */*pids*/, unsigned int *numpidt, std::string */*tlanguage*/, int */*mags*/, int */*pages*/); - void FindAllSubs(short unsigned int *pids, short unsigned int *supported, short unsigned int *numpida, std::string *language); - bool SelectSubtitles(int pid, std::string charset = ""); - void RequestAbort(void); - bool IsPlaying(void); - uint64_t GetReadCount(void); + bool Open(playmode_t PlayMode); + void Close(void); + bool Start(char *filename, int vpid, int vtype, int apid, int ac3, int duration, std::string headers = "", std::string filename2 = ""); + bool Start(std::string filename, std::string headers = "", std::string filename2 = ""); + bool SetAPid(int pid, bool ac3 = false); + bool SetVPid(int /*pid*/); + bool SetSubtitlePid(int pid); + bool SetTeletextPid(int pid); + int GetAPid(void) + { + return mAudioStream; + } + int GetVPid(void) + { + return 0; + } + int GetSubtitlePid(void) + { + return mSubtitleStream; + } + int GetTeletextPid(void); + bool SetSpeed(int speed); + bool GetSpeed(int &speed) const; + bool GetPosition(int &position, int &duration); + void GetPts(uint64_t &pts); + bool SetPosition(int position, bool absolute = false); + void FindAllPids(short unsigned int *apids, short unsigned int *ac3flags, short unsigned int *numpida, std::string *language); + void FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language); + void FindAllTeletextsubtitlePids(int */*pids*/, unsigned int *numpidt, std::string */*tlanguage*/, int */*mags*/, int */*pages*/); + void FindAllSubs(short unsigned int *pids, short unsigned int *supported, short unsigned int *numpida, std::string *language); + bool SelectSubtitles(int pid, std::string charset = ""); + void RequestAbort(void); + bool IsPlaying(void); + uint64_t GetReadCount(void); - void GetChapters(std::vector &positions, std::vector &titles); - void GetMetadata(std::vector &keys, std::vector &values); + void GetChapters(std::vector &positions, std::vector &titles); + void GetMetadata(std::vector &keys, std::vector &values); - AVFormatContext *GetAVFormatContext(); - void ReleaseAVFormatContext(); - void GetTitles(std::vector &playlists, std::vector &titles, int ¤t); - void SetTitle(int title); + AVFormatContext *GetAVFormatContext(); + void ReleaseAVFormatContext(); + void GetTitles(std::vector &playlists, std::vector &titles, int ¤t); + void SetTitle(int title); }; class netlink_event : public OpenThreads::Thread { - friend class cPlayback; + friend class cPlayback; -protected: - bool running; -private: - netlink_event(); - ~netlink_event(); - static netlink_event *netlink_event_instance; - cPlayback *player; - int m_player_state; - enum - { - stIdle, stRunning, stStopped, - }; - struct streamid - { - uint16_t programid; - uint16_t videostreamid; - uint16_t audiostreamid; - uint16_t subtitlestreamid; - } streamid; - int m_state; - bool m_paused; - bool m_buffering; - HI_FORMAT_FILE_INFO_S fileinfo; - struct nlmsghdr *nlh; - int m_bufferpercentage; - uint32_t m_seekable; - uint32_t m_download_progress; - int netlink_socket; - int receive_netlink_message(); - errorInfo m_errorInfo; - void run(); - void Receive(); -public: - static netlink_event* getInstance(); - uint64_t getDuration() - { - return fileinfo.s64Duration; - }; - bool Start(cPlayback *player); - bool Stop(); + protected: + bool running; + private: + netlink_event(); + ~netlink_event(); + static netlink_event *netlink_event_instance; + cPlayback *player; + int m_player_state; + enum + { + stIdle, stRunning, stStopped, + }; + struct streamid + { + uint16_t programid; + uint16_t videostreamid; + uint16_t audiostreamid; + uint16_t subtitlestreamid; + } streamid; + int m_state; + bool m_paused; + bool m_buffering; + HI_FORMAT_FILE_INFO_S fileinfo; + struct nlmsghdr *nlh; + int m_bufferpercentage; + uint32_t m_seekable; + uint32_t m_download_progress; + int netlink_socket; + int receive_netlink_message(); + errorInfo m_errorInfo; + void run(); + void Receive(); + public: + static netlink_event *getInstance(); + uint64_t getDuration() + { + return fileinfo.s64Duration; + }; + bool Start(cPlayback *player); + bool Stop(); }; #if 0 // for later use, maybe class video_event : public OpenThreads::Thread { - friend class cPlayback; + friend class cPlayback; -protected: - bool running; -private: - int m_video_fd; - void run(); - void Receive(); -public: - bool Start(int video_fd); - bool Stop(); + protected: + bool running; + private: + int m_video_fd; + void run(); + void Receive(); + public: + bool Start(int video_fd); + bool Stop(); }; #endif #endif diff --git a/libarmbox/playback_libeplayer3.cpp b/libarmbox/playback_libeplayer3.cpp index 2338584..02cbfdc 100644 --- a/libarmbox/playback_libeplayer3.cpp +++ b/libarmbox/playback_libeplayer3.cpp @@ -11,11 +11,11 @@ extern "C" { #include -extern OutputHandler_t OutputHandler; -extern PlaybackHandler_t PlaybackHandler; -extern ContainerHandler_t ContainerHandler; -extern ManagerHandler_t ManagerHandler; -extern int32_t ffmpeg_av_dict_set( const char *key, const char *value, int32_t flags); + extern OutputHandler_t OutputHandler; + extern PlaybackHandler_t PlaybackHandler; + extern ContainerHandler_t ContainerHandler; + extern ManagerHandler_t ManagerHandler; + extern int32_t ffmpeg_av_dict_set(const char *key, const char *value, int32_t flags); } #include "playback_libeplayer3.h" @@ -88,7 +88,7 @@ void cPlayback::Close(void) //Dagobert: movieplayer does not call stop, it calls close ;) mutex.lock(); - if(playing) + if (playing) Stop(); mutex.unlock(); @@ -102,7 +102,7 @@ void cPlayback::Close(void) bool cPlayback::Start(std::string filename, std::string headers, std::string filename2) { - return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers,filename2); + return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers, filename2); } bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, int, std::string headers, std::string filename2) @@ -140,7 +140,7 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in else isHTTP = true; - if(isHTTP && headers.empty()) + if (isHTTP && headers.empty()) { size_t pos = file.find('#'); if (pos != std::string::npos) @@ -148,17 +148,19 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in headers = file.substr(pos + 1); pos = headers.find("User-Agent="); if (pos != std::string::npos) - headers.replace(pos+10, 1, ": "); + headers.replace(pos + 10, 1, ": "); } } - if(!headers.empty()){ + if (!headers.empty()) + { const char hkey[] = "headers"; ffmpeg_av_dict_set(hkey, headers.c_str(), 0); } std::string szSecondFile; char *file2 = NULL; - if(!filename2.empty()){ + if (!filename2.empty()) + { szSecondFile = filename2; file2 = (char *) szSecondFile.c_str(); } @@ -180,7 +182,7 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in //AUDIO if (player && player->manager && player->manager->audio) { - char ** TrackList = NULL; + char **TrackList = NULL; player->manager->audio->Command(player, MANAGER_LIST, &TrackList); if (TrackList != NULL) { @@ -199,13 +201,13 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in //SUB if (player && player->manager && player->manager->subtitle) { - char ** TrackList = NULL; + char **TrackList = NULL; player->manager->subtitle->Command(player, MANAGER_LIST, &TrackList); if (TrackList != NULL) { printf("SubtitleTrack List\n"); int i = 0; - for (i = 0; TrackList[i] != NULL; i+=2) + for (i = 0; TrackList[i] != NULL; i += 2) { printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); free(TrackList[i]); @@ -219,27 +221,27 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in //Teletext if (player && player->manager && player->manager->teletext) { - char ** TrackList = NULL; - player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("TeletextTrack List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i += 2) - { - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - } + char ** TrackList = NULL; + player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); + if (TrackList != NULL) + { + printf("TeletextTrack List\n"); + int i = 0; + for (i = 0; TrackList[i] != NULL; i += 2) + { + printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); + free(TrackList[i]); + free(TrackList[i + 1]); + } + free(TrackList); + } } */ //Chapters if (player && player->manager && player->manager->chapter) { - char ** TrackList = NULL; + char **TrackList = NULL; player->manager->chapter->Command(player, MANAGER_LIST, &TrackList); if (TrackList != NULL) { @@ -334,7 +336,7 @@ bool cPlayback::SetTeletextPid(int pid) if (pid != mTeletextStream) { //if (player && player->playback) - // player->playback->Command(player, PLAYBACK_SWITCH_TELETEXT, (void*)&i); + // player->playback->Command(player, PLAYBACK_SWITCH_TELETEXT, (void*)&i); mTeletextStream = pid; } return true; @@ -364,7 +366,7 @@ bool cPlayback::SetSpeed(int speed) if (player && player->playback) { int result = 0; - if(nPlaybackSpeed == 0 && speed > 1) + if (nPlaybackSpeed == 0 && speed > 1) { result = player->playback->Command(player, PLAYBACK_CONTINUE, NULL); } @@ -654,36 +656,36 @@ void cPlayback::FindAllTeletextsubtitlePids(int */*pids*/, unsigned int *numpids //int max_numpids = *numpids; *numpids = 0; -/* if (player && player->manager && player->manager->teletext) - { - char **TrackList = NULL; - player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("Teletext List\n"); - int i = 0, j = 0; - for (i = 0, j = 0; TrackList[i] != NULL; i += 2) - { - int type = 0; - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - if (j < max_numpids) - { - int _pid; - if (2 != sscanf(TrackList[i], "%d %*s %d %*d %*d", &_pid, &type)) - continue; - if (type != 2 && type != 5) // return subtitles only - continue; - pids[j] = _pid; - language[j] = std::string(TrackList[i]); - j++; - } - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - *numpids = j; - } - } */ + /* if (player && player->manager && player->manager->teletext) + { + char **TrackList = NULL; + player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); + if (TrackList != NULL) + { + printf("Teletext List\n"); + int i = 0, j = 0; + for (i = 0, j = 0; TrackList[i] != NULL; i += 2) + { + int type = 0; + printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); + if (j < max_numpids) + { + int _pid; + if (2 != sscanf(TrackList[i], "%d %*s %d %*d %*d", &_pid, &type)) + continue; + if (type != 2 && type != 5) // return subtitles only + continue; + pids[j] = _pid; + language[j] = std::string(TrackList[i]); + j++; + } + free(TrackList[i]); + free(TrackList[i + 1]); + } + free(TrackList); + *numpids = j; + } + } */ } int cPlayback::GetTeletextPid(void) @@ -691,31 +693,31 @@ int cPlayback::GetTeletextPid(void) hal_info("%s\n", __func__); int pid = -1; -/* if (player && player->manager && player->manager->teletext) - { - char **TrackList = NULL; - player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("Teletext List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i += 2) - { - int type = 0; - printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); - if (pid < 0) - { - if (2 != sscanf(TrackList[i], "%*d %d %*s %d %*d %*d", &pid, &type)) - continue; - if (type != 1) - pid = -1; - } - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - } - } */ + /* if (player && player->manager && player->manager->teletext) + { + char **TrackList = NULL; + player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); + if (TrackList != NULL) + { + printf("Teletext List\n"); + int i = 0; + for (i = 0; TrackList[i] != NULL; i += 2) + { + int type = 0; + printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); + if (pid < 0) + { + if (2 != sscanf(TrackList[i], "%*d %d %*s %d %*d %*d", &pid, &type)) + continue; + if (type != 1) + pid = -1; + } + free(TrackList[i]); + free(TrackList[i + 1]); + } + free(TrackList); + } + } */ printf("teletext pid id %d (0x%x)\n", pid, pid); return pid; @@ -828,9 +830,9 @@ void cPlayback::RequestAbort() Stop(); player->playback->abortRequested = 1; } - else if(player->playback->isHttp && !player->playback->isPlaying &&!player->playback->abortRequested) + else if (player->playback->isHttp && !player->playback->isPlaying && !player->playback->abortRequested) { - player->playback->abortRequested = 1; + player->playback->abortRequested = 1; } mutex.unlock(); diff --git a/libarmbox/playback_libeplayer3.h b/libarmbox/playback_libeplayer3.h index 1e20d77..b5f308c 100644 --- a/libarmbox/playback_libeplayer3.h +++ b/libarmbox/playback_libeplayer3.h @@ -15,7 +15,7 @@ struct AVFormatContext; class cPlayback { - friend class CStreamInfo2; + friend class CStreamInfo2; private: static OpenThreads::Mutex mutex; @@ -48,9 +48,18 @@ class cPlayback bool SetVPid(int /*pid*/); bool SetSubtitlePid(int pid); bool SetTeletextPid(int pid); - int GetAPid(void) { return mAudioStream; } - int GetVPid(void) { return 0; } - int GetSubtitlePid(void) { return mSubtitleStream; } + int GetAPid(void) + { + return mAudioStream; + } + int GetVPid(void) + { + return 0; + } + int GetSubtitlePid(void) + { + return mSubtitleStream; + } int GetTeletextPid(void); bool SetSpeed(int speed); bool GetSpeed(int &speed) const; diff --git a/libarmbox/record.cpp b/libarmbox/record.cpp index 6662aa8..fd9946c 100644 --- a/libarmbox/record.cpp +++ b/libarmbox/record.cpp @@ -1,5 +1,5 @@ /* - * (C) + * (C) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -150,17 +150,21 @@ bool cRecord::ChangePids(unsigned short /*vpid*/, unsigned short *apids, int num bool found; unsigned short pid; hal_info("%s\n", __func__); - if (!dmx) { + if (!dmx) + { hal_info("%s: DMX = NULL\n", __func__); return false; } pids = dmx->pesfds; /* the first PID is the video pid, so start with the second PID... */ - for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) { + for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) + { found = false; pid = (*i).pid; - for (j = 0; j < numapids; j++) { - if (pid == apids[j]) { + for (j = 0; j < numapids; j++) + { + if (pid == apids[j]) + { found = true; break; } @@ -168,10 +172,13 @@ bool cRecord::ChangePids(unsigned short /*vpid*/, unsigned short *apids, int num if (!found) dmx->removePid(pid); } - for (j = 0; j < numapids; j++) { + for (j = 0; j < numapids; j++) + { found = false; - for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) { - if ((*i).pid == apids[j]) { + for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) + { + if ((*i).pid == apids[j]) + { found = true; break; } @@ -186,12 +193,14 @@ bool cRecord::AddPid(unsigned short pid) { std::vector pids; hal_info("%s: \n", __func__); - if (!dmx) { + if (!dmx) + { hal_info("%s: DMX = NULL\n", __func__); return false; } pids = dmx->pesfds; - for (std::vector::const_iterator i = pids.begin(); i != pids.end(); ++i) { + for (std::vector::const_iterator i = pids.begin(); i != pids.end(); ++i) + { if ((*i).pid == pid) return true; /* or is it an error to try to add the same PID twice? */ } @@ -203,14 +212,16 @@ void cRecord::WriterThread() char threadname[17]; strncpy(threadname, "WriterThread", sizeof(threadname)); threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); + prctl(PR_SET_NAME, (unsigned long)&threadname); unsigned int chunk = 0; - while (!sem_wait(&sem)) { + while (!sem_wait(&sem)) + { if (!io_len[chunk]) // empty, assume end of recording return; unsigned char *p_buf = io_buf[chunk]; size_t p_len = io_len[chunk]; - while (p_len) { + while (p_len) + { ssize_t written = write(file_fd, p_buf, p_len); if (written < 0) break; @@ -230,7 +241,7 @@ void cRecord::RecordThread() char threadname[17]; strncpy(threadname, "RecordThread", sizeof(threadname)); threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); + prctl(PR_SET_NAME, (unsigned long)&threadname); int readsize = bufsize / 16; int buf_pos = 0; int count = 0; @@ -251,7 +262,7 @@ void cRecord::RecordThread() } int val = fcntl(file_fd, F_GETFL); - if (fcntl(file_fd, F_SETFL, val|O_APPEND)) + if (fcntl(file_fd, F_SETFL, val | O_APPEND)) hal_info("%s: O_APPEND? (%m)\n", __func__); memset(&a, 0, sizeof(a)); @@ -266,7 +277,8 @@ void cRecord::RecordThread() { if (buf_pos < bufsize) { - if (overflow_count) { + if (overflow_count) + { hal_info("%s: Overflow cleared after %d iterations\n", __func__, overflow_count); overflow_count = 0; } @@ -275,7 +287,7 @@ void cRecord::RecordThread() toread = readsize; ssize_t s = dmx->Read(buf + buf_pos, toread, 50); hal_debug("%s: buf_pos %6d s %6d / %6d\n", __func__, - buf_pos, (int)s, bufsize - buf_pos); + buf_pos, (int)s, bufsize - buf_pos); if (s < 0) { if (errno != EAGAIN && (errno != EOVERFLOW || !overflow)) @@ -378,9 +390,9 @@ void cRecord::RecordThread() eventServer.registerEvent2(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, "/tmp/neutrino.sock"); stream2file_status2_t s; s.status = exit_flag; - strncpy(s.filename,basename(myfilename),512); + strncpy(s.filename, basename(myfilename), 512); s.filename[511] = '\0'; - strncpy(s.dir,dirname(myfilename),100); + strncpy(s.dir, dirname(myfilename), 100); s.dir[99] = '\0'; eventServer.sendEvent(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, &s, sizeof(s)); printf("[stream2file]: pthreads exit code: %i, dir: '%s', filename: '%s' myfilename: '%s'\n", exit_flag, s.dir, s.filename, myfilename); diff --git a/libarmbox/record_lib.h b/libarmbox/record_lib.h index 9e554cd..8cde3f6 100644 --- a/libarmbox/record_lib.h +++ b/libarmbox/record_lib.h @@ -9,13 +9,14 @@ #define REC_STATUS_OVERFLOW 2 #define REC_STATUS_STOPPED 4 -typedef enum { +typedef enum +{ RECORD_RUNNING, RECORD_STOPPED, - RECORD_FAILED_READ, /* failed to read from DMX */ - RECORD_FAILED_OVERFLOW, /* cannot write fast enough */ - RECORD_FAILED_FILE, /* cannot write to file */ - RECORD_FAILED_MEMORY /* out of memory */ + RECORD_FAILED_READ, /* failed to read from DMX */ + RECORD_FAILED_OVERFLOW, /* cannot write fast enough */ + RECORD_FAILED_FILE, /* cannot write to file */ + RECORD_FAILED_MEMORY /* out of memory */ } record_state_t; class cRecord @@ -38,8 +39,12 @@ class cRecord unsigned char *io_buf[RECORD_WRITER_CHUNKS]; size_t io_len[RECORD_WRITER_CHUNKS]; public: - cRecord(int num = 0, int bs_dmx = 2048 * 1024, int bs = 4096 * 1024); - void setFailureCallback(void (*f)(void *), void *d) { failureCallback = f; failureData = d; } + cRecord(int num = 0, int bs_dmx = 2048 * 1024, int bs = 4096 * 1024); + void setFailureCallback(void (*f)(void *), void *d) + { + failureCallback = f; + failureData = d; + } ~cRecord(); bool Open(); diff --git a/libarmbox/video.cpp b/libarmbox/video.cpp index 879a8c6..24c7351 100644 --- a/libarmbox/video.cpp +++ b/libarmbox/video.cpp @@ -53,17 +53,17 @@ extern "C" #define hal_debug_c(args...) _hal_debug(HAL_DEBUG_VIDEO, NULL, args) #define hal_info_c(args...) _hal_info(HAL_DEBUG_VIDEO, NULL, args) -#define fop(cmd, args...) ({ \ - int _r; \ - if (fd >= 0) { \ - if ((_r = ::cmd(fd, args)) < 0) \ - hal_info(#cmd"(fd, "#args")\n");\ - else \ - hal_debug(#cmd"(fd, "#args")\n");\ - } \ - else { _r = fd; } \ - _r; \ -}) +#define fop(cmd, args...) ({ \ + int _r; \ + if (fd >= 0) { \ + if ((_r = ::cmd(fd, args)) < 0) \ + hal_info(#cmd"(fd, "#args")\n");\ + else \ + hal_debug(#cmd"(fd, "#args")\n");\ + } \ + else { _r = fd; } \ + _r; \ + }) #ifndef VIDEO_GET_SIZE #define VIDEO_GET_SIZE _IOR('o', 55, video_size_t) @@ -73,108 +73,120 @@ extern "C" #endif enum -{ ENCODER, +{ + ENCODER, AUX }; -cVideo * videoDecoder = NULL; -cVideo * pipDecoder = NULL; +cVideo *videoDecoder = NULL; +cVideo *pipDecoder = NULL; int system_rev = 0; static bool stillpicture = false; -static const char *VDEV[] = { +static const char *VDEV[] = +{ "/dev/dvb/adapter0/video0", "/dev/dvb/adapter0/video1", "/dev/dvb/adapter0/video2", "/dev/dvb/adapter0/video3" }; -static const char *VMPEG_aspect[] = { +static const char *VMPEG_aspect[] = +{ "/proc/stb/vmpeg/0/aspect", "/proc/stb/vmpeg/1/aspect", "/proc/stb/vmpeg/2/aspect", "/proc/stb/vmpeg/3/aspect" }; -static const char *VMPEG_xres[] = { +static const char *VMPEG_xres[] = +{ "/proc/stb/vmpeg/0/xres", "/proc/stb/vmpeg/1/xres", "/proc/stb/vmpeg/2/xres", "/proc/stb/vmpeg/3/xres" }; -static const char *VMPEG_yres[] = { +static const char *VMPEG_yres[] = +{ "/proc/stb/vmpeg/0/yres", "/proc/stb/vmpeg/1/yres", "/proc/stb/vmpeg/2/yres", "/proc/stb/vmpeg/3/yres" }; -static const char *VMPEG_dst_height[] = { +static const char *VMPEG_dst_height[] = +{ "/proc/stb/vmpeg/0/dst_height", "/proc/stb/vmpeg/1/dst_height", "/proc/stb/vmpeg/2/dst_height", "/proc/stb/vmpeg/3/dst_height" }; -static const char *VMPEG_dst_width[] = { +static const char *VMPEG_dst_width[] = +{ "/proc/stb/vmpeg/0/dst_width", "/proc/stb/vmpeg/1/dst_width", "/proc/stb/vmpeg/2/dst_width", "/proc/stb/vmpeg/3/dst_width" }; -static const char *VMPEG_dst_top[] = { +static const char *VMPEG_dst_top[] = +{ "/proc/stb/vmpeg/0/dst_top", "/proc/stb/vmpeg/1/dst_top", "/proc/stb/vmpeg/2/dst_top", "/proc/stb/vmpeg/3/dst_top" }; -static const char *VMPEG_dst_left[] = { +static const char *VMPEG_dst_left[] = +{ "/proc/stb/vmpeg/0/dst_left", "/proc/stb/vmpeg/1/dst_left", "/proc/stb/vmpeg/2/dst_left", "/proc/stb/vmpeg/3/dst_left" }; -static const char *VMPEG_framerate[] = { +static const char *VMPEG_framerate[] = +{ "/proc/stb/vmpeg/0/framerate", "/proc/stb/vmpeg/1/framerate", "/proc/stb/vmpeg/2/framerate", "/proc/stb/vmpeg/3/framerate" }; -static const char *VMPEG_visible[] = { +static const char *VMPEG_visible[] = +{ "/proc/stb/vmpeg/0/visible", "/proc/stb/vmpeg/1/visible", "/proc/stb/vmpeg/2/visible", "/proc/stb/vmpeg/3/visible" }; -static const char *vid_modes[] = { - "pal", // VIDEO_STD_NTSC - "pal", // VIDEO_STD_SECAM - "pal", // VIDEO_STD_PAL - "480p", // VIDEO_STD_480P - "576p50", // VIDEO_STD_576P - "720p60", // VIDEO_STD_720P60 - "1080i60", // VIDEO_STD_1080I60 - "720p50", // VIDEO_STD_720P50 - "1080i50", // VIDEO_STD_1080I50 - "1080p30", // VIDEO_STD_1080P30 - "1080p24", // VIDEO_STD_1080P24 - "1080p25", // VIDEO_STD_1080P25 - "1080p50", // VIDEO_STD_1080P50 - "1080p60", // VIDEO_STD_1080P60 - "1080p2397", // VIDEO_STD_1080P2397 - "1080p2997", // VIDEO_STD_1080P2997 - "2160p24", // VIDEO_STD_2160P24 - "2160p25", // VIDEO_STD_2160P25 - "2160p30", // VIDEO_STD_2160P30 - "2160p50", // VIDEO_STD_2160P50 - "720p50" // VIDEO_STD_AUTO +static const char *vid_modes[] = +{ + "pal", // VIDEO_STD_NTSC + "pal", // VIDEO_STD_SECAM + "pal", // VIDEO_STD_PAL + "480p", // VIDEO_STD_480P + "576p50", // VIDEO_STD_576P + "720p60", // VIDEO_STD_720P60 + "1080i60", // VIDEO_STD_1080I60 + "720p50", // VIDEO_STD_720P50 + "1080i50", // VIDEO_STD_1080I50 + "1080p30", // VIDEO_STD_1080P30 + "1080p24", // VIDEO_STD_1080P24 + "1080p25", // VIDEO_STD_1080P25 + "1080p50", // VIDEO_STD_1080P50 + "1080p60", // VIDEO_STD_1080P60 + "1080p2397", // VIDEO_STD_1080P2397 + "1080p2997", // VIDEO_STD_1080P2997 + "2160p24", // VIDEO_STD_2160P24 + "2160p25", // VIDEO_STD_2160P25 + "2160p30", // VIDEO_STD_2160P30 + "2160p50", // VIDEO_STD_2160P50 + "720p50" // VIDEO_STD_AUTO }; #define VIDEO_STREAMTYPE_MPEG2 0 @@ -189,7 +201,7 @@ static const char *vid_modes[] = { ssize_t write_all(int fd, const void *buf, size_t count) { int retval; - char *ptr = (char*)buf; + char *ptr = (char *)buf; size_t handledcount = 0; while (handledcount < count) { @@ -207,23 +219,26 @@ ssize_t write_all(int fd, const void *buf, size_t count) return handledcount; } -void init_parameters(AVFrame* in_frame, AVCodecContext *codec_context) +void init_parameters(AVFrame *in_frame, AVCodecContext *codec_context) { /* put sample parameters */ codec_context->bit_rate = 400000; /* resolution must be a multiple of two */ - codec_context->width = (in_frame->width/2)*2; - codec_context->height = (in_frame->height/2)*2; + codec_context->width = (in_frame->width / 2) * 2; + codec_context->height = (in_frame->height / 2) * 2; /* frames per second */ - codec_context->time_base = (AVRational ) { 1, 60 }; + codec_context->time_base = (AVRational) + { + 1, 60 + }; codec_context->gop_size = 10; /* emit one intra frame every ten frames */ codec_context->max_b_frames = 1; codec_context->pix_fmt = AV_PIX_FMT_YUV420P; } -void write_frame(AVFrame* in_frame, int fd) +void write_frame(AVFrame *in_frame, int fd) { - if(in_frame == NULL) + if (in_frame == NULL) return; static const unsigned char pes_header[] = {0x0, 0x0, 0x1, 0xe0, 0x00, 0x00, 0x80, 0x80, 0x5, 0x21, 0x0, 0x1, 0x0, 0x1}; @@ -234,38 +249,47 @@ void write_frame(AVFrame* in_frame, int fd) if (codec_context) { init_parameters(in_frame, codec_context); - if (avcodec_open2(codec_context, codec, 0) != -1){ + if (avcodec_open2(codec_context, codec, 0) != -1) + { AVPacket pkt; av_init_packet(&pkt); /* encode the image */ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) int got_output = 0; int ret = avcodec_encode_video2(codec_context, &pkt, in_frame, &got_output); - if (ret != -1){ + if (ret != -1) + { #else int ret = avcodec_send_frame(codec_context, in_frame); - if (!ret) { + if (!ret) + { /* signalling end of stream */ ret = avcodec_send_frame(codec_context, NULL); } - if (!ret) { + if (!ret) + { #endif int i = 1; /* get the delayed frames */ in_frame->pts = i; #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) ret = avcodec_encode_video2(codec_context, &pkt, 0, &got_output); - if (ret != -1 && got_output){ + if (ret != -1 && got_output) + { #else ret = avcodec_receive_packet(codec_context, &pkt); - if (!ret) { + if (!ret) + { #endif - if ((pkt.data[3] >> 4) != 0xE){ + if ((pkt.data[3] >> 4) != 0xE) + { write_all(fd, pes_header, sizeof(pes_header)); - }else{ + } + else + { pkt.data[4] = pkt.data[5] = 0x00; } - write_all(fd,pkt.data, pkt.size); + write_all(fd, pkt.data, pkt.size); av_packet_unref(&pkt); } } @@ -276,13 +300,15 @@ void write_frame(AVFrame* in_frame, int fd) } } -int decode_frame(AVCodecContext *codecContext,AVPacket &packet, int fd) +int decode_frame(AVCodecContext *codecContext, AVPacket &packet, int fd) { AVFrame *frame = av_frame_alloc(); - if(frame){ + if (frame) + { #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) int decode_ok = 0; - if ((avcodec_decode_video2(codecContext, frame, &decode_ok, &packet)) < 0 || !decode_ok){ + if ((avcodec_decode_video2(codecContext, frame, &decode_ok, &packet)) < 0 || !decode_ok) + { av_frame_free(&frame); return -1; } @@ -291,25 +317,29 @@ int decode_frame(AVCodecContext *codecContext,AVPacket &packet, int fd) ret = avcodec_send_packet(codecContext, &packet); // In particular, we don't expect AVERROR(EAGAIN), because we read all // decoded frames with avcodec_receive_frame() until done. - if (ret < 0) { + if (ret < 0) + { av_frame_free(&frame); return -1; } ret = avcodec_receive_frame(codecContext, frame); - if (ret < 0) { + if (ret < 0) + { av_frame_free(&frame); return -1; } #endif AVFrame *dest_frame = av_frame_alloc(); - if(dest_frame){ - dest_frame->height = (frame->height/2)*2; - dest_frame->width = (frame->width/2)*2; + if (dest_frame) + { + dest_frame->height = (frame->height / 2) * 2; + dest_frame->width = (frame->width / 2) * 2; dest_frame->format = AV_PIX_FMT_YUV420P; av_frame_get_buffer(dest_frame, 32); struct SwsContext *convert = NULL; convert = sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format, dest_frame->width, dest_frame->height, AV_PIX_FMT_YUVJ420P, SWS_FAST_BILINEAR, NULL, NULL, NULL); - if(convert){ + if (convert) + { sws_scale(convert, frame->data, frame->linesize, 0, frame->height, dest_frame->data, dest_frame->linesize); sws_freeContext(convert); } @@ -322,19 +352,23 @@ int decode_frame(AVCodecContext *codecContext,AVPacket &packet, int fd) } -AVCodecContext* open_codec(AVMediaType mediaType, AVFormatContext* formatContext) +AVCodecContext *open_codec(AVMediaType mediaType, AVFormatContext *formatContext) { - AVCodec * codec = NULL; - AVCodecContext * codecContext = NULL; + AVCodec *codec = NULL; + AVCodecContext *codecContext = NULL; int stream_index; #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(57,25,101) stream_index = av_find_best_stream(formatContext, mediaType, -1, -1, NULL, 0); - if (stream_index >= 0) { + if (stream_index >= 0) + { codecContext = formatContext->streams[stream_index]->codec; - if (codecContext) { + if (codecContext) + { codec = avcodec_find_decoder(codecContext->codec_id); - if (codec) { - if ((avcodec_open2(codecContext, codec, NULL)) != 0) { + if (codec) + { + if ((avcodec_open2(codecContext, codec, NULL)) != 0) + { return NULL; } } @@ -344,13 +378,17 @@ AVCodecContext* open_codec(AVMediaType mediaType, AVFormatContext* formatContext return NULL; #else stream_index = av_find_best_stream(formatContext, mediaType, -1, -1, &codec, 0); - if (stream_index >= 0) { + if (stream_index >= 0) + { codec = avcodec_find_decoder(formatContext->streams[stream_index]->codecpar->codec_id); - if (codec) { + if (codec) + { codecContext = avcodec_alloc_context3(codec); } - if (codecContext) { - if ((avcodec_open2(codecContext, codec, NULL)) != 0) { + if (codecContext) + { + if ((avcodec_open2(codecContext, codec, NULL)) != 0) + { return NULL; } return codecContext; @@ -369,16 +407,20 @@ int image_to_mpeg2(const char *image_name, int fd) #endif AVFormatContext *formatContext = avformat_alloc_context(); - if (formatContext && (ret = avformat_open_input(&formatContext, image_name, NULL, NULL)) == 0){ + if (formatContext && (ret = avformat_open_input(&formatContext, image_name, NULL, NULL)) == 0) + { AVCodecContext *codecContext = open_codec(AVMEDIA_TYPE_VIDEO, formatContext); - if(codecContext){ + if (codecContext) + { AVPacket packet; av_init_packet(&packet); - if ((ret = av_read_frame(formatContext, &packet)) !=-1){ - if((ret = decode_frame(codecContext, packet, fd)) != 1){ - /* add sequence end code to have a real mpeg file */ + if ((ret = av_read_frame(formatContext, &packet)) != -1) + { + if ((ret = decode_frame(codecContext, packet, fd)) != 1) + { + /* add sequence end code to have a real mpeg file */ uint8_t endcode[] = { 0, 0, 1, 0xb7 }; - write_all(fd,endcode, sizeof(endcode)); + write_all(fd, endcode, sizeof(endcode)); } av_packet_unref(&packet); } @@ -411,7 +453,8 @@ void cVideo::close_AVInput_Device(void) { hal_debug("%s\n", __func__); - if (fdd) { + if (fdd) + { fop(ioctl, VIDEO_STOP); fop(ioctl, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX); } @@ -422,11 +465,15 @@ void cVideo::setAVInput(int val) { hal_info("%s - switching to: %s\n", __func__, val == AUX ? "AUX" : "ENCODER"); - if (val == AUX) { + if (val == AUX) + { setBlank(1); open_AVInput_Device(); - } else { - if (fdd) { + } + else + { + if (fdd) + { close_AVInput_Device(); setBlank(0); } @@ -434,7 +481,8 @@ void cVideo::setAVInput(int val) #if 0 // not working int input_fd = open("/proc/stb/avs/0/input", O_WRONLY); - if(input_fd){ + if (input_fd) + { const char *input[] = {"encoder", "aux"}; write(input_fd, input[val], strlen(input[val])); close(input_fd); @@ -452,10 +500,12 @@ cVideo::cVideo(int, void *, void *, unsigned int unit) hue = -1; video_standby = 0; blank_mode = 0; - if (unit > 1) { + if (unit > 1) + { hal_info("%s: unit %d out of range, setting to 0\n", __func__, unit); devnum = 0; - } else + } + else devnum = unit; fd = -1; fdd = false; @@ -468,7 +518,7 @@ cVideo::cVideo(int, void *, void *, unsigned int unit) cVideo::~cVideo(void) { #if 0 - if(fd >= 0) + if (fd >= 0) setAVInput(AUX); #endif if (hdmi_cec::getInstance()->standby_cec_activ && fd >= 0) @@ -485,7 +535,7 @@ void cVideo::openDevice(void) if (fd != -1) /* already open */ return; retry: - if ((fd = open(VDEV[devnum], O_RDWR|O_CLOEXEC)) < 0) + if ((fd = open(VDEV[devnum], O_RDWR | O_CLOEXEC)) < 0) { if (errno == EBUSY) { @@ -521,7 +571,7 @@ int cVideo::setAspectRatio(int aspect, int mode) #endif int n; - int mo = (mode < 0||mode > 3) ? 4 : mode; + int mo = (mode < 0 || mode > 3) ? 4 : mode; hal_debug("%s: a:%d m:%d %s\n", __func__, aspect, mode, m[mo]); if (aspect > 3 || aspect == 0) @@ -592,7 +642,8 @@ int cVideo::Start(void * /*PcrChannel*/, unsigned short /*PcrPid*/, unsigned sho fop(ioctl, MPEG_VID_CONTINUE); #endif /* implicitly do StopPicture() on video->Start() */ - if (stillpicture) { + if (stillpicture) + { hal_info("%s: stillpicture == true, doing implicit StopPicture()\n", __func__); stillpicture = false; Stop(1); @@ -603,19 +654,23 @@ int cVideo::Start(void * /*PcrChannel*/, unsigned short /*PcrPid*/, unsigned sho #if BOXMODEL_HISILICON fop(ioctl, VIDEO_CONTINUE); #endif - if (brightness > -1) { + if (brightness > -1) + { SetControl(VIDEO_CONTROL_BRIGHTNESS, brightness); brightness = -1; } - if (contrast > -1) { + if (contrast > -1) + { SetControl(VIDEO_CONTROL_CONTRAST, contrast); contrast = -1; } - if (saturation > -1) { + if (saturation > -1) + { SetControl(VIDEO_CONTROL_SATURATION, saturation); saturation = -1; } - if (hue > -1) { + if (hue > -1) + { SetControl(VIDEO_CONTROL_HUE, hue); hue = -1; } @@ -674,7 +729,7 @@ int cVideo::SetVideoSystem(int video_system, bool remember) Stop(); stopped = true; } - ret = proc_put("/proc/stb/video/videomode", vid_modes[video_system],strlen(vid_modes[video_system])); + ret = proc_put("/proc/stb/video/videomode", vid_modes[video_system], strlen(vid_modes[video_system])); if (stopped) Start(); @@ -698,10 +753,12 @@ void cVideo::GetVideoSystemFormatName(cs_vs_format_t *format, int system) { if (system == -1) system = GetVideoSystem(); - if (system < 0 || system > VIDEO_STD_1080P50) { + if (system < 0 || system > VIDEO_STD_1080P50) + { hal_info("%s: invalid system %d\n", __func__, system); strcpy(format->format, "invalid"); - } else + } + else strcpy(format->format, vid_modes[system]); } @@ -719,7 +776,7 @@ void cVideo::SetVideoMode(analog_mode_t mode) return; } const char *m; - switch(mode) + switch (mode) { case ANALOG_SD_YPRPB_SCART: m = "yuv"; @@ -735,7 +792,7 @@ void cVideo::SetVideoMode(analog_mode_t mode) proc_put("/proc/stb/avs/0/colorformat", m, strlen(m)); } -bool cVideo::ShowPicture(const char * fname) +bool cVideo::ShowPicture(const char *fname) { bool ret = false; hal_debug("%s(%s)\n", __func__, fname); @@ -753,7 +810,8 @@ bool cVideo::ShowPicture(const char * fname) } struct stat st; - if (stat(fname, &st)){ + if (stat(fname, &st)) + { return ret; } closeDevice(); @@ -769,7 +827,7 @@ bool cVideo::ShowPicture(const char * fname) ioctl(fd, VIDEO_CLEAR_BUFFER); image_to_mpeg2(fname, fd); unsigned char iframe[8192]; - memset(iframe,0xff,sizeof(iframe)); + memset(iframe, 0xff, sizeof(iframe)); write_all(fd, iframe, 8192); usleep(150000); ioctl(fd, VIDEO_STOP, 0); @@ -938,7 +996,8 @@ void cVideo::SetSyncMode(AVSYNC_TYPE mode) int cVideo::SetStreamType(VIDEO_FORMAT type) { - static const char *VF[] = { + static const char *VF[] = + { "VIDEO_FORMAT_MPEG2", "VIDEO_FORMAT_MPEG4", "VIDEO_FORMAT_VC1", @@ -990,66 +1049,68 @@ void cVideo::SetDemux(cDemux *) void cVideo::SetControl(int control, int value) { const char *p = NULL; - switch (control) { - case VIDEO_CONTROL_BRIGHTNESS: - brightness = value; - p = "/proc/stb/vmpeg/0/pep_brightness"; - break; - case VIDEO_CONTROL_CONTRAST: - contrast = value; - p = "/proc/stb/vmpeg/0/pep_contrast"; - break; - case VIDEO_CONTROL_SATURATION: - saturation = value; - p = "/proc/stb/vmpeg/0/pep_saturation"; - break; - case VIDEO_CONTROL_HUE: - hue = value; - p = "/proc/stb/vmpeg/0/pep_hue"; - break; - case VIDEO_CONTROL_SHARPNESS: - sharpness = value; - p = "/proc/stb/vmpeg/0/pep_sharpness"; - break; - case VIDEO_CONTROL_BLOCK_NOISE_REDUCTION: - block_noise_reduction = value; - p = "/proc/stb/vmpeg/0/pep_block_noise_reduction"; - break; - case VIDEO_CONTROL_MOSQUITO_NOISE_REDUCTION: - mosquito_noise_reduction = value; - p = "/proc/stb/vmpeg/0/pep_mosquito_noise_reduction"; - break; - case VIDEO_CONTROL_DIGITAL_CONTOUR_REMOVAL: - digital_contour_removal = value; - p = "/proc/stb/vmpeg/0/pep_digital_contour_removal"; - break; - case VIDEO_CONTROL_AUTO_FLESH: - auto_flesh = value; - p = "/proc/stb/vmpeg/0/pep_auto_flesh"; - break; - case VIDEO_CONTROL_GREEN_BOOST: - green_boost = value; - p = "/proc/stb/vmpeg/0/pep_green_boost"; - break; - case VIDEO_CONTROL_BLUE_BOOST: - blue_boost = value; - p = "/proc/stb/vmpeg/0/pep_blue_boost"; - break; - case VIDEO_CONTROL_DYNAMIC_CONTRAST: - dynamic_contrast = value; - p = "/proc/stb/vmpeg/0/pep_dynamic_contrast"; - break; - case VIDEO_CONTROL_SCALER_SHARPNESS: - scaler_sharpness = value; - p = "/proc/stb/vmpeg/0/pep_scaler_sharpness"; - break; - case VIDEO_CONTROL_ZAPPING_MODE: - zapping_mode = value; - const char *mode_zapping[] = { "mute", "hold", "mutetilllock", "holdtilllock"}; - proc_put("/proc/stb/video/zapmode", mode_zapping[zapping_mode], strlen(mode_zapping[zapping_mode])); - break; + switch (control) + { + case VIDEO_CONTROL_BRIGHTNESS: + brightness = value; + p = "/proc/stb/vmpeg/0/pep_brightness"; + break; + case VIDEO_CONTROL_CONTRAST: + contrast = value; + p = "/proc/stb/vmpeg/0/pep_contrast"; + break; + case VIDEO_CONTROL_SATURATION: + saturation = value; + p = "/proc/stb/vmpeg/0/pep_saturation"; + break; + case VIDEO_CONTROL_HUE: + hue = value; + p = "/proc/stb/vmpeg/0/pep_hue"; + break; + case VIDEO_CONTROL_SHARPNESS: + sharpness = value; + p = "/proc/stb/vmpeg/0/pep_sharpness"; + break; + case VIDEO_CONTROL_BLOCK_NOISE_REDUCTION: + block_noise_reduction = value; + p = "/proc/stb/vmpeg/0/pep_block_noise_reduction"; + break; + case VIDEO_CONTROL_MOSQUITO_NOISE_REDUCTION: + mosquito_noise_reduction = value; + p = "/proc/stb/vmpeg/0/pep_mosquito_noise_reduction"; + break; + case VIDEO_CONTROL_DIGITAL_CONTOUR_REMOVAL: + digital_contour_removal = value; + p = "/proc/stb/vmpeg/0/pep_digital_contour_removal"; + break; + case VIDEO_CONTROL_AUTO_FLESH: + auto_flesh = value; + p = "/proc/stb/vmpeg/0/pep_auto_flesh"; + break; + case VIDEO_CONTROL_GREEN_BOOST: + green_boost = value; + p = "/proc/stb/vmpeg/0/pep_green_boost"; + break; + case VIDEO_CONTROL_BLUE_BOOST: + blue_boost = value; + p = "/proc/stb/vmpeg/0/pep_blue_boost"; + break; + case VIDEO_CONTROL_DYNAMIC_CONTRAST: + dynamic_contrast = value; + p = "/proc/stb/vmpeg/0/pep_dynamic_contrast"; + break; + case VIDEO_CONTROL_SCALER_SHARPNESS: + scaler_sharpness = value; + p = "/proc/stb/vmpeg/0/pep_scaler_sharpness"; + break; + case VIDEO_CONTROL_ZAPPING_MODE: + zapping_mode = value; + const char *mode_zapping[] = { "mute", "hold", "mutetilllock", "holdtilllock"}; + proc_put("/proc/stb/video/zapmode", mode_zapping[zapping_mode], strlen(mode_zapping[zapping_mode])); + break; } - if (p) { + if (p) + { char buf[20]; int fix_value = value * 256; int len = snprintf(buf, sizeof(buf), "%.8X", fix_value); @@ -1061,34 +1122,35 @@ void cVideo::SetControl(int control, int value) void cVideo::SetColorFormat(COLOR_FORMAT color_format) { const char *p = NULL; - switch(color_format) { - case COLORFORMAT_RGB: - p = "rgb"; - break; - case COLORFORMAT_YUV: - p = "yuv"; - break; - case COLORFORMAT_CVBS: - p = "cvbs"; - break; - case COLORFORMAT_SVIDEO: - p = "svideo"; - break; - case COLORFORMAT_HDMI_AUTO: - p = "Edid(Auto)"; - break; - case COLORFORMAT_HDMI_RGB: - p = "Hdmi_Rgb"; - break; - case COLORFORMAT_HDMI_YCBCR444: - p = "444"; - break; - case COLORFORMAT_HDMI_YCBCR422: - p = "422"; - break; - case COLORFORMAT_HDMI_YCBCR420: - p = "420"; - break; + switch (color_format) + { + case COLORFORMAT_RGB: + p = "rgb"; + break; + case COLORFORMAT_YUV: + p = "yuv"; + break; + case COLORFORMAT_CVBS: + p = "cvbs"; + break; + case COLORFORMAT_SVIDEO: + p = "svideo"; + break; + case COLORFORMAT_HDMI_AUTO: + p = "Edid(Auto)"; + break; + case COLORFORMAT_HDMI_RGB: + p = "Hdmi_Rgb"; + break; + case COLORFORMAT_HDMI_YCBCR444: + p = "444"; + break; + case COLORFORMAT_HDMI_YCBCR422: + p = "422"; + break; + case COLORFORMAT_HDMI_YCBCR420: + p = "420"; + break; } if (p) proc_put("/proc/stb/video/hdmi_colorspace", p, strlen(p)); @@ -1097,16 +1159,18 @@ void cVideo::SetColorFormat(COLOR_FORMAT color_format) bool getvideo2(unsigned char *video, int xres, int yres) { bool ret = false; - if(video == NULL) + if (video == NULL) return ret; char videosnapshot[] = "/dev/dvb/adapter0/video0"; int fd_video = open(videosnapshot, O_RDONLY); - if (fd_video < 0) { + if (fd_video < 0) + { perror(videosnapshot); return ret; } ssize_t r = read(fd_video, video, xres * yres * 3); - if(r){ + if (r) + { ret = true; } close(fd_video); @@ -1118,42 +1182,49 @@ static bool swscale(unsigned char *src, unsigned char *dst, int sw, int sh, int int len = 0; struct SwsContext *scale = NULL; scale = sws_getCachedContext(scale, sw, sh, sfmt, dw, dh, AV_PIX_FMT_RGB32, SWS_BICUBIC, 0, 0, 0); - if (!scale) { + if (!scale) + { hal_info_c("%s: ERROR setting up SWS context\n", __func__); return ret; } AVFrame *sframe = av_frame_alloc(); AVFrame *dframe = av_frame_alloc(); - if (sframe && dframe) { + if (sframe && dframe) + { len = av_image_fill_arrays(sframe->data, sframe->linesize, &(src)[0], sfmt, sw, sh, 1); - if(len>-1) + if (len > -1) ret = true; - if(ret && (len = av_image_fill_arrays(dframe->data, dframe->linesize, &(dst)[0], AV_PIX_FMT_RGB32, dw, dh, 1)<0)) + if (ret && (len = av_image_fill_arrays(dframe->data, dframe->linesize, &(dst)[0], AV_PIX_FMT_RGB32, dw, dh, 1) < 0)) ret = false; - if(ret && (len = sws_scale(scale, sframe->data, sframe->linesize, 0, sh, dframe->data, dframe->linesize)<0)) + if (ret && (len = sws_scale(scale, sframe->data, sframe->linesize, 0, sh, dframe->data, dframe->linesize) < 0)) ret = false; else ret = true; - }else{ + } + else + { hal_info_c("%s: could not alloc sframe (%p) or dframe (%p)\n", __func__, sframe, dframe); ret = false; } - if(sframe){ + if (sframe) + { av_frame_free(&sframe); sframe = NULL; } - if(dframe){ + if (dframe) + { av_frame_free(&dframe); dframe = NULL; } - if(scale){ + if (scale) + { sws_freeContext(scale); scale = NULL; } - hal_info_c("%s: %s scale %ix%i to %ix%i ,len %i\n",ret?" ":"ERROR",__func__, sw, sh, dw, dh,len); + hal_info_c("%s: %s scale %ix%i to %ix%i ,len %i\n", ret ? " " : "ERROR", __func__, sw, sh, dw, dh, len); return ret; } @@ -1161,7 +1232,7 @@ static bool swscale(unsigned char *src, unsigned char *dst, int sw, int sh, int // grabing the osd picture void get_osd_size(int &xres, int &yres, int &bits_per_pixel) { - int fb=open("/dev/fb/0", O_RDWR); + int fb = open("/dev/fb/0", O_RDWR); if (fb == -1) { fprintf(stderr, "Framebuffer failed\n"); @@ -1169,7 +1240,7 @@ void get_osd_size(int &xres, int &yres, int &bits_per_pixel) } struct fb_var_screeninfo var_screeninfo; - if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) + if (ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) { fprintf(stderr, "Framebuffer: \n"); close(fb); @@ -1178,9 +1249,9 @@ void get_osd_size(int &xres, int &yres, int &bits_per_pixel) close(fb); bits_per_pixel = var_screeninfo.bits_per_pixel; - xres=var_screeninfo.xres; - yres=var_screeninfo.yres; - fprintf(stderr, "... Framebuffer-Size: %d x %d\n",xres,yres); + xres = var_screeninfo.xres; + yres = var_screeninfo.yres; + fprintf(stderr, "... Framebuffer-Size: %d x %d\n", xres, yres); } void get_osd_buf(unsigned char *osd_data) @@ -1188,40 +1259,40 @@ void get_osd_buf(unsigned char *osd_data) struct fb_fix_screeninfo fix_screeninfo; struct fb_var_screeninfo var_screeninfo; - int fb=open("/dev/fb/0", O_RDONLY); + int fb = open("/dev/fb/0", O_RDONLY); if (fb == -1) { fprintf(stderr, "Framebuffer failed\n"); return; } - if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) + if (ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) { fprintf(stderr, "Framebuffer: \n"); close(fb); return; } - if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) + if (ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) { fprintf(stderr, "Framebuffer: \n"); close(fb); return; } - void *lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ , MAP_SHARED, fb, 0); - if(lfb == MAP_FAILED) + void *lfb = (unsigned char *)mmap(0, fix_screeninfo.smem_len, PROT_READ, MAP_SHARED, fb, 0); + if (lfb == MAP_FAILED) { fprintf(stderr, "Framebuffer: \n"); close(fb); return; } - if ( var_screeninfo.bits_per_pixel == 32 ) + if (var_screeninfo.bits_per_pixel == 32) { fprintf(stderr, "Grabbing 32bit Framebuffer ...\n"); // get 32bit framebuffer - memcpy(osd_data,lfb,fix_screeninfo.line_length*var_screeninfo.yres); + memcpy(osd_data, lfb, fix_screeninfo.line_length * var_screeninfo.yres); } if (munmap(lfb, fix_screeninfo.smem_len) == -1) @@ -1232,8 +1303,10 @@ void get_osd_buf(unsigned char *osd_data) close(fb); } -inline void rgb24torgb32(unsigned char *src, unsigned char *dest,int picsize) { - for (int i = 0; i < picsize; i++) { +inline void rgb24torgb32(unsigned char *src, unsigned char *dest, int picsize) +{ + for (int i = 0; i < picsize; i++) + { *dest++ = *src++; *dest++ = *src++; *dest++ = *src++; @@ -1242,30 +1315,32 @@ inline void rgb24torgb32(unsigned char *src, unsigned char *dest,int picsize) { } /* TODO: aspect ratio correction and PIP */ -bool cVideo::GetScreenImage(unsigned char * &out_data, int &xres, int &yres, bool get_video, bool get_osd, bool scale_to_video) +bool cVideo::GetScreenImage(unsigned char *&out_data, int &xres, int &yres, bool get_video, bool get_osd, bool scale_to_video) { #define VDEC_PIXFMT AV_PIX_FMT_BGR24 hal_info("%s: out_data 0x%p xres %d yres %d vid %d osd %d scale %d\n", - __func__, out_data, xres, yres, get_video, get_osd, scale_to_video); + __func__, out_data, xres, yres, get_video, get_osd, scale_to_video); int aspect = 0; getPictureInfo(xres, yres, aspect); /* aspect is dummy here */ aspect = getAspectRatio(); - if(xres < 1 || yres < 1 ) + if (xres < 1 || yres < 1) get_video = false; - if(!get_video && !get_osd) + if (!get_video && !get_osd) return false; int osd_w = 0; int osd_h = 0; int bits_per_pixel = 0; - if(get_osd){ + if (get_osd) + { get_osd_size(osd_w, osd_h, bits_per_pixel); - if(osd_w < 1 || osd_h < 1 || bits_per_pixel != 32) + if (osd_w < 1 || osd_h < 1 || bits_per_pixel != 32) get_osd = false; - if(!scale_to_video && get_osd){ + if (!scale_to_video && get_osd) + { xres = osd_w; yres = osd_h; } @@ -1275,41 +1350,52 @@ bool cVideo::GetScreenImage(unsigned char * &out_data, int &xres, int &yres, boo if (out_data == NULL) return false; - if (get_video) { - const int grab_w = 1920; const int grab_h = 1080; //hd51 video0 is always 1920x1080 + if (get_video) + { + const int grab_w = 1920; + const int grab_h = 1080; //hd51 video0 is always 1920x1080 unsigned char *video_src = (unsigned char *)malloc(grab_w * grab_h * 3); if (video_src == NULL) return false; - if(getvideo2(video_src, grab_w,grab_h) == false){ + if (getvideo2(video_src, grab_w, grab_h) == false) + { free(out_data); free(video_src); return false; } - if (grab_w != xres || grab_h != yres){ /* scale video into data... */ - bool ret = swscale(video_src, out_data, grab_w, grab_h, xres, yres,VDEC_PIXFMT); - if(!ret){ + if (grab_w != xres || grab_h != yres) /* scale video into data... */ + { + bool ret = swscale(video_src, out_data, grab_w, grab_h, xres, yres, VDEC_PIXFMT); + if (!ret) + { free(out_data); free(video_src); return false; } - }else{ /* get_video and no fancy scaling needed */ + } + else /* get_video and no fancy scaling needed */ + { rgb24torgb32(video_src, out_data, grab_w * grab_h); } free(video_src); } - if(get_osd){ + if (get_osd) + { osd_data = (unsigned char *)malloc(osd_w * osd_h * 4); - if(osd_data) + if (osd_data) get_osd_buf(osd_data); } - if (get_osd && (osd_w != xres || osd_h != yres)) { + if (get_osd && (osd_w != xres || osd_h != yres)) + { /* rescale osd */ unsigned char *osd_src = (unsigned char *)malloc(xres * yres * 4); - if(osd_src){ - bool ret = swscale(osd_data, osd_src, osd_w, osd_h, xres, yres,AV_PIX_FMT_RGB32); - if(!ret){ + if (osd_src) + { + bool ret = swscale(osd_data, osd_src, osd_w, osd_h, xres, yres, AV_PIX_FMT_RGB32); + if (!ret) + { free(out_data); free(osd_data); free(osd_src); @@ -1318,30 +1404,38 @@ bool cVideo::GetScreenImage(unsigned char * &out_data, int &xres, int &yres, boo free(osd_data); osd_data = NULL; osd_data = osd_src; - }else{ + } + else + { free(out_data); free(osd_data); return false; } } - if (get_video && get_osd) { + if (get_video && get_osd) + { /* alpha blend osd onto out_data (video). TODO: maybe libavcodec can do this? */ uint32_t *d = (uint32_t *)out_data; uint32_t *pixpos = (uint32_t *) osd_data; - for (int count = 0; count < yres; count++) { - for (int count2 = 0; count2 < xres; count2++ ) { + for (int count = 0; count < yres; count++) + { + for (int count2 = 0; count2 < xres; count2++) + { uint32_t pix = *pixpos; if ((pix & 0xff000000) == 0xff000000) *d = pix; - else { + else + { uint8_t *in = (uint8_t *)(pixpos); uint8_t *out = (uint8_t *)d; - int a = in[3]; /* TODO: big/little endian? */ + int a = in[3]; /* TODO: big/little endian? */ *out = (*out + ((*in - *out) * a) / 256); - in++; out++; + in++; + out++; *out = (*out + ((*in - *out) * a) / 256); - in++; out++; + in++; + out++; *out = (*out + ((*in - *out) * a) / 256); } d++; @@ -1352,7 +1446,7 @@ bool cVideo::GetScreenImage(unsigned char * &out_data, int &xres, int &yres, boo else if (get_osd) /* only get_osd, out_data is not yet populated */ memcpy(out_data, osd_data, xres * yres * sizeof(uint32_t)); - if(osd_data) + if (osd_data) free(osd_data); return true; diff --git a/libarmbox/video_lib.h b/libarmbox/video_lib.h index 962dfc8..9ad4f74 100644 --- a/libarmbox/video_lib.h +++ b/libarmbox/video_lib.h @@ -10,7 +10,8 @@ typedef struct cs_vs_format_t char format[16]; } cs_vs_format_struct_t; -typedef enum { +typedef enum +{ ANALOG_SD_RGB_CINCH = 0x00, ANALOG_SD_YPRPB_CINCH, ANALOG_HD_RGB_CINCH, @@ -22,7 +23,8 @@ typedef enum { ANALOG_SCART_MASK = 0x10 } analog_mode_t; -typedef enum { +typedef enum +{ COLORFORMAT_RGB = 0x10, // keep compatible with analog_mode_t COLORFORMAT_YUV, COLORFORMAT_CVBS, @@ -34,7 +36,8 @@ typedef enum { COLORFORMAT_HDMI_YCBCR420 } COLOR_FORMAT; -typedef enum { +typedef enum +{ VIDEO_FORMAT_MPEG2 = 0, VIDEO_FORMAT_MPEG4_H264, VIDEO_FORMAT_VC1, @@ -45,7 +48,8 @@ typedef enum { VIDEO_FORMAT_AVS = 16 } VIDEO_FORMAT; -typedef enum { +typedef enum +{ VIDEO_SD = 0, VIDEO_HD, VIDEO_120x60i, @@ -54,7 +58,8 @@ typedef enum { VIDEO_360x288i } VIDEO_DEFINITION; -typedef enum { +typedef enum +{ VIDEO_FRAME_RATE_23_976 = 0, VIDEO_FRAME_RATE_24, VIDEO_FRAME_RATE_25, @@ -65,7 +70,8 @@ typedef enum { VIDEO_FRAME_RATE_60 } VIDEO_FRAME_RATE; -typedef enum { +typedef enum +{ DISPLAY_AR_1_1, DISPLAY_AR_4_3, DISPLAY_AR_14_9, @@ -74,20 +80,23 @@ typedef enum { DISPLAY_AR_RAW } DISPLAY_AR; -typedef enum { +typedef enum +{ DISPLAY_AR_MODE_PANSCAN = 0, DISPLAY_AR_MODE_LETTERBOX, DISPLAY_AR_MODE_NONE, DISPLAY_AR_MODE_PANSCAN2 } DISPLAY_AR_MODE; -typedef enum { +typedef enum +{ VIDEO_DB_DR_NEITHER = 0, VIDEO_DB_ON, VIDEO_DB_DR_BOTH } VIDEO_DB_DR; -typedef enum { +typedef enum +{ VIDEO_PLAY_STILL = 0, VIDEO_PLAY_CLIP, VIDEO_PLAY_TRICK, @@ -95,7 +104,8 @@ typedef enum { VIDEO_PLAY_MOTION_NO_SYNC } VIDEO_PLAY_MODE; -typedef enum { +typedef enum +{ VIDEO_STD_NTSC, VIDEO_STD_SECAM, VIDEO_STD_PAL, @@ -120,13 +130,15 @@ typedef enum { VIDEO_STD_MAX = VIDEO_STD_AUTO } VIDEO_STD; -typedef enum { +typedef enum +{ VIDEO_HDMI_CEC_MODE_OFF = 0, VIDEO_HDMI_CEC_MODE_TUNER = 3, VIDEO_HDMI_CEC_MODE_RECORDER = 1 } VIDEO_HDMI_CEC_MODE; -typedef enum { +typedef enum +{ VIDEO_HDMI_CEC_VOL_OFF = 0, VIDEO_HDMI_CEC_VOL_AUDIOSYSTEM = 1, VIDEO_HDMI_CEC_VOL_TV = 2 @@ -156,8 +168,8 @@ class cPlayback; class cVideo { - friend class cPlayback; - friend class cDemux; + friend class cPlayback; + friend class cDemux; private: /* video device */ int fd; @@ -210,8 +222,14 @@ class cVideo void setAVInput(int val); - void * GetTVEnc() { return NULL; }; - void * GetTVEncSD() { return NULL; }; + void *GetTVEnc() + { + return NULL; + }; + void *GetTVEncSD() + { + return NULL; + }; /* aspect ratio */ int getAspectRatio(void); @@ -236,7 +254,7 @@ class cVideo /* get video system infos */ int GetVideoSystem(void); /* when system = -1 then use current video system */ - void GetVideoSystemFormatName(cs_vs_format_t* format, int system); + void GetVideoSystemFormatName(cs_vs_format_t *format, int system); /* set video_system */ int SetVideoSystem(int video_system, bool remember = true); @@ -247,7 +265,7 @@ class cVideo void SetCECAutoStandby(bool); int GetAudioDestination(); void SetAudioDestination(int audio_dest); - bool ShowPicture(const char * fname); + bool ShowPicture(const char *fname); void StopPicture(); void Standby(unsigned int bOn); void ShowPig(int _x); @@ -255,16 +273,37 @@ class cVideo void SetControl(int, int); void setContrast(int val); void SetVideoMode(analog_mode_t mode); - void SetDBDR(int) { return; }; - void SetAudioHandle(void *) { return; }; - void SetAutoModes(int [VIDEO_STD_MAX]) { return; }; - int OpenVBI(int) { return 0; }; - int CloseVBI(void) { return 0; }; - int StartVBI(unsigned short) { return 0; }; - int StopVBI(void) { return 0; }; + void SetDBDR(int) + { + return; + }; + void SetAudioHandle(void *) + { + return; + }; + void SetAutoModes(int [VIDEO_STD_MAX]) + { + return; + }; + int OpenVBI(int) + { + return 0; + }; + int CloseVBI(void) + { + return 0; + }; + int StartVBI(unsigned short) + { + return 0; + }; + int StopVBI(void) + { + return 0; + }; void SetDemux(cDemux *dmx); void SetColorFormat(COLOR_FORMAT color_format); - bool GetScreenImage(unsigned char * &data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); + bool GetScreenImage(unsigned char *&data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); }; #endif // __VIDEO_LIB_H__ diff --git a/libduckbox/init.cpp b/libduckbox/init.cpp index 36c5303..b245f69 100644 --- a/libduckbox/init.cpp +++ b/libduckbox/init.cpp @@ -29,7 +29,7 @@ void hal_api_init() /* this is a strange hack: the drivers seem to only work correctly after * demux0 has been used once. After that, we can use demux1,2,... */ struct dmx_pes_filter_params p; - int dmx = open("/dev/dvb/adapter0/demux0", O_RDWR|O_CLOEXEC); + int dmx = open("/dev/dvb/adapter0/demux0", O_RDWR | O_CLOEXEC); if (dmx < 0) hal_info("%s: ERROR open /dev/dvb/adapter0/demux0 (%m)\n", __func__); else diff --git a/libdvbci/_dh_params.h b/libdvbci/_dh_params.h index 904a552..52b42e9 100644 --- a/libdvbci/_dh_params.h +++ b/libdvbci/_dh_params.h @@ -1,6 +1,7 @@ /* DH */ -unsigned char dh_p[256] = { /* prime */ +unsigned char dh_p[256] = /* prime */ +{ 0xd6, 0x27, 0x14, 0x7a, 0x7c, 0x0c, 0x26, 0x63, 0x9d, 0x82, 0xeb, 0x1f, 0x4a, 0x18, 0xff, 0x6c, 0x34, 0xad, 0xea, 0xa6, 0xc0, 0x23, 0xe6, 0x65, 0xfc, 0x8e, 0x32, 0xc3, 0x33, 0xf4, 0x91, 0xa7, 0xcc, 0x88, 0x58, 0xd7, 0xf3, 0xb3, 0x17, 0x5e, 0xb0, 0xa8, 0xeb, 0x5c, 0xd4, 0xd8, 0x3a, 0xae, @@ -19,7 +20,8 @@ unsigned char dh_p[256] = { /* prime */ 0x15, 0xb8, 0x3c, 0x8d, 0x80, 0x92, 0x1c, 0xa1, 0x03, 0xd0, 0x83, 0x2f, 0x5f, 0xe3, 0x07, 0x69 }; -unsigned char dh_g[256] = { /* generator */ +unsigned char dh_g[256] = /* generator */ +{ 0x95, 0x7d, 0xd1, 0x49, 0x68, 0xc1, 0xa5, 0xf1, 0x48, 0xe6, 0x50, 0x4f, 0xa1, 0x10, 0x72, 0xc4, 0xef, 0x12, 0xec, 0x2d, 0x94, 0xbe, 0xc7, 0x20, 0x2c, 0x94, 0xf9, 0x68, 0x67, 0x0e, 0x22, 0x17, 0xb5, 0x5c, 0x0b, 0xca, 0xac, 0x9f, 0x25, 0x9c, 0xd2, 0xa6, 0x1a, 0x20, 0x10, 0x16, 0x6a, 0x42, diff --git a/libdvbci/aes_xcbc_mac.cpp b/libdvbci/aes_xcbc_mac.cpp index 39da7c9..99e0d26 100644 --- a/libdvbci/aes_xcbc_mac.cpp +++ b/libdvbci/aes_xcbc_mac.cpp @@ -11,7 +11,8 @@ int aes_xcbc_mac_init(struct aes_xcbc_mac_ctx *ctx, const uint8_t *key) AES_set_encrypt_key(key, 128, &aes_key); - for (y = 0; y < 3; y++) { + for (y = 0; y < 3; y++) + { for (x = 0; x < 16; x++) ctx->K[y][x] = y + 1; AES_ecb_encrypt(ctx->K[y], ctx->K[y], &aes_key, 1); @@ -28,8 +29,10 @@ int aes_xcbc_mac_init(struct aes_xcbc_mac_ctx *ctx, const uint8_t *key) int aes_xcbc_mac_process(struct aes_xcbc_mac_ctx *ctx, const uint8_t *in, unsigned int len) { - while (len) { - if (ctx->buflen == 16) { + while (len) + { + if (ctx->buflen == 16) + { AES_ecb_encrypt(ctx->IV, ctx->IV, &ctx->key, 1); ctx->buflen = 0; } @@ -44,11 +47,14 @@ int aes_xcbc_mac_done(struct aes_xcbc_mac_ctx *ctx, uint8_t *out) { int i; - if (ctx->buflen == 16) { + if (ctx->buflen == 16) + { /* K2 */ for (i = 0; i < 16; i++) ctx->IV[i] ^= ctx->K[1][i]; - } else { + } + else + { ctx->IV[ctx->buflen] ^= 0x80; /* K3 */ for (i = 0; i < 16; i++) diff --git a/libdvbci/aes_xcbc_mac.h b/libdvbci/aes_xcbc_mac.h index d233cc4..80f54eb 100644 --- a/libdvbci/aes_xcbc_mac.h +++ b/libdvbci/aes_xcbc_mac.h @@ -1,7 +1,8 @@ #ifndef __AES_XCBC_H_ #define __AES_XCBC_H_ -struct aes_xcbc_mac_ctx { +struct aes_xcbc_mac_ctx +{ uint8_t K[3][16]; uint8_t IV[16]; AES_KEY key; diff --git a/libdvbci/descrambler.cpp b/libdvbci/descrambler.cpp index 6345f0a..5ec6147 100644 --- a/libdvbci/descrambler.cpp +++ b/libdvbci/descrambler.cpp @@ -13,13 +13,14 @@ #include -static const char * FILENAME = "[descrambler]"; +static const char *FILENAME = "[descrambler]"; static int desc_fd = -1; static int desc_user_count = 0; #ifndef CA_SET_PID -typedef struct ca_pid { +typedef struct ca_pid +{ unsigned int pid; int index; /* -1 == disable*/ } ca_pid_t; @@ -28,17 +29,20 @@ typedef struct ca_pid { #endif #ifndef CA_SET_DESCR_DATA -enum ca_descr_data_type { +enum ca_descr_data_type +{ CA_DATA_IV, CA_DATA_KEY, }; -enum ca_descr_parity { +enum ca_descr_parity +{ CA_PARITY_EVEN, CA_PARITY_ODD, }; -struct ca_descr_data { +struct ca_descr_data +{ unsigned int index; enum ca_descr_parity parity; enum ca_descr_data_type data_type; @@ -173,8 +177,9 @@ bool descrambler_open(void) { if (desc_fd > 0) return true; - desc_fd = open(descrambler_filename, O_RDWR | O_NONBLOCK ); - if (desc_fd <= 0) { + desc_fd = open(descrambler_filename, O_RDWR | O_NONBLOCK); + if (desc_fd <= 0) + { printf("cannot open %s\n", descrambler_filename); return false; } diff --git a/libdvbci/dh_rsa_misc.cpp b/libdvbci/dh_rsa_misc.cpp index 5b6be9b..84f4cb6 100644 --- a/libdvbci/dh_rsa_misc.cpp +++ b/libdvbci/dh_rsa_misc.cpp @@ -20,8 +20,9 @@ static int pkcs_1_mgf1(const uint8_t *seed, unsigned long seedlen, uint8_t *mask hLen = 20; /* SHA1 */ /* allocate memory */ - buf = (uint8_t*)malloc(hLen); - if (buf == NULL) { + buf = (uint8_t *)malloc(hLen); + if (buf == NULL) + { printf("error mem\n"); return -1; } @@ -29,7 +30,8 @@ static int pkcs_1_mgf1(const uint8_t *seed, unsigned long seedlen, uint8_t *mask /* start counter */ counter = 0; - while (masklen > 0) { + while (masklen > 0) + { /* handle counter */ BYTE32(buf, counter); ++counter; @@ -50,8 +52,8 @@ static int pkcs_1_mgf1(const uint8_t *seed, unsigned long seedlen, uint8_t *mask } static int pkcs_1_pss_encode(const uint8_t *msghash, unsigned int msghashlen, - unsigned long saltlen, unsigned long modulus_bitlen, - uint8_t *out, unsigned int outlen) + unsigned long saltlen, unsigned long modulus_bitlen, + uint8_t *out, unsigned int outlen) { unsigned char *DB, *mask, *salt, *hash; unsigned long x, y, hLen, modulus_len; @@ -63,22 +65,25 @@ static int pkcs_1_pss_encode(const uint8_t *msghash, unsigned int msghashlen, modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0); /* allocate ram for DB/mask/salt/hash of size modulus_len */ - DB = (unsigned char*)malloc(modulus_len); - mask = (unsigned char*)malloc(modulus_len); - salt = (unsigned char*)malloc(modulus_len); - hash = (unsigned char*)malloc(modulus_len); + DB = (unsigned char *)malloc(modulus_len); + mask = (unsigned char *)malloc(modulus_len); + salt = (unsigned char *)malloc(modulus_len); + hash = (unsigned char *)malloc(modulus_len); hashbuflen = 8 + msghashlen + saltlen; - hashbuf = (unsigned char*)malloc(hashbuflen); + hashbuf = (unsigned char *)malloc(hashbuflen); - if (!(DB && mask && salt && hash && hashbuf)) { + if (!(DB && mask && salt && hash && hashbuf)) + { printf("out of memory\n"); goto LBL_ERR; } /* generate random salt */ - if (saltlen > 0) { - if (get_random(salt, saltlen) != (long)saltlen) { + if (saltlen > 0) + { + if (get_random(salt, saltlen) != (long)saltlen) + { printf("rnd failed\n"); goto LBL_ERR; } @@ -107,7 +112,8 @@ static int pkcs_1_pss_encode(const uint8_t *msghash, unsigned int msghashlen, DB[y] ^= mask[y]; /* output is DB || hash || 0xBC */ - if (outlen < modulus_len) { + if (outlen < modulus_len) + { err = -1; printf("error overflow\n"); goto LBL_ERR; @@ -168,7 +174,8 @@ int dh_gen_exp(uint8_t *dest, int dest_len, uint8_t *dh_g, int dh_g_len, uint8_t DH_get0_key(dh, &pub_key, &priv_key); len = BN_num_bytes(priv_key); #endif - if (len > dest_len) { + if (len > dest_len) + { printf("len > dest_len\n"); return -1; } @@ -206,7 +213,8 @@ int dh_mod_exp(uint8_t *dest, int dest_len, uint8_t *base, int base_len, uint8_t len = BN_num_bytes(bn_dest); - if (len > dest_len) { + if (len > dest_len) + { printf("len > dest_len\n"); return -1; } @@ -251,7 +259,8 @@ int dh_dhph_signature(uint8_t *out, uint8_t *nonce, uint8_t *dhph, RSA *r) SHA1(dest, 0x12e, hash); - if (pkcs_1_pss_encode(hash, 20, 20, 0x800, dbuf, sizeof(dbuf))) { + if (pkcs_1_pss_encode(hash, 20, 20, 0x800, dbuf, sizeof(dbuf))) + { printf("pss encode failed\n"); return -1; } diff --git a/libdvbci/dvbci_appmgr.cpp b/libdvbci/dvbci_appmgr.cpp index 1e69bfa..aab8157 100644 --- a/libdvbci/dvbci_appmgr.cpp +++ b/libdvbci/dvbci_appmgr.cpp @@ -6,7 +6,7 @@ #include "dvbci_appmgr.h" -/* prevent possibly segfaults: read at end of this file */ +/* prevent possibly segfaults: read at end of this file */ #define yy_debug 0 eDVBCIApplicationManagerSession::eDVBCIApplicationManagerSession(eDVBCISlot *tslot) @@ -26,7 +26,7 @@ int eDVBCIApplicationManagerSession::receivedAPDU(const unsigned char *tag, cons { printf("[CI AM] SESSION(%d)/APP %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); for (int i = 0; i < len; i++) - printf("%02x ", ((const unsigned char*)data)[i]); + printf("%02x ", ((const unsigned char *)data)[i]); printf("\n"); if ((tag[0] == 0x9f) && (tag[1] == 0x80)) @@ -38,21 +38,21 @@ int eDVBCIApplicationManagerSession::receivedAPDU(const unsigned char *tag, cons int dl; printf("[CI AM] application info:\n"); printf("[CI AM] len: %d\n", len); - printf("[CI AM] application_type: %d\n", ((unsigned char*)data)[0]); - printf("[CI AM] application_manufacturer: %02x %02x\n", ((unsigned char*)data)[2], ((unsigned char*)data)[1]); - printf("[CI AM] manufacturer_code: %02x %02x\n", ((unsigned char*)data)[4], ((unsigned char*)data)[3]); + printf("[CI AM] application_type: %d\n", ((unsigned char *)data)[0]); + printf("[CI AM] application_manufacturer: %02x %02x\n", ((unsigned char *)data)[2], ((unsigned char *)data)[1]); + printf("[CI AM] manufacturer_code: %02x %02x\n", ((unsigned char *)data)[4], ((unsigned char *)data)[3]); printf(" menu string: "); - dl = ((unsigned char*)data)[5]; + dl = ((unsigned char *)data)[5]; if ((dl + 6) > len) { printf("[CI AM] warning, invalid length (%d vs %d)\n", dl + 6, len); dl = len - 6; } char str[dl + 1]; - memcpy(str, ((char*)data) + 6, dl); + memcpy(str, ((char *)data) + 6, dl); str[dl] = '\0'; for (int i = 0; i < dl; ++i) - printf("%c", ((unsigned char*)data)[i + 6]); + printf("%c", ((unsigned char *)data)[i + 6]); printf("\n"); strcpy(slot->name, str); @@ -111,16 +111,16 @@ int eDVBCIApplicationManagerSession::startMMI() bool eDVBCIApplicationManagerSession::readBlist() { int rc, i; - char cSid[4] = {0,0,0,0}; + char cSid[4] = {0, 0, 0, 0}; u16 Sid; FILE *fd; char blacklist_file[32]; - sprintf(blacklist_file,"/etc/blacklist_slot_%d",slot->slot); + sprintf(blacklist_file, "/etc/blacklist_slot_%d", slot->slot); if (access(blacklist_file, F_OK) != 0) return false; - fd = fopen(blacklist_file,"r"); + fd = fopen(blacklist_file, "r"); if (!fd) return false; else @@ -139,7 +139,8 @@ bool eDVBCIApplicationManagerSession::readBlist() Sid = (u16)strtol(cSid, NULL, 16); slot->bsids.push_back(Sid); } - } while (rc != EOF); + } + while (rc != EOF); fin: fclose(fd); } @@ -153,7 +154,7 @@ int eDVBCIApplicationManagerSession::checkBlist() { if (readBlist()) { -/* out commented: causes sometimes segfault when reboot....don't know why :( */ + /* out commented: causes sometimes segfault when reboot....don't know why :( */ #if yy_debug printf("Blacked sids: %d > ", slot->bsids.size()); for (unsigned int i = 0; i < slot->bsids.size(); i++) diff --git a/libdvbci/dvbci_appmgr.h b/libdvbci/dvbci_appmgr.h index 0f7d04d..390a753 100644 --- a/libdvbci/dvbci_appmgr.h +++ b/libdvbci/dvbci_appmgr.h @@ -5,22 +5,23 @@ class eDVBCIApplicationManagerSession: public eDVBCISession { - enum { - stateFinal=statePrivate - }; + enum + { + stateFinal = statePrivate + }; - eDVBCISlot *slot; + eDVBCISlot *slot; - int wantmenu; - int receivedAPDU(const unsigned char *tag, const void *data, int len); - int doAction(); - bool readBlist(); - int checkBlist(); -public: - eDVBCIApplicationManagerSession(eDVBCISlot *tslot); - ~eDVBCIApplicationManagerSession(); - int enterMenu(); - int startMMI(); + int wantmenu; + int receivedAPDU(const unsigned char *tag, const void *data, int len); + int doAction(); + bool readBlist(); + int checkBlist(); + public: + eDVBCIApplicationManagerSession(eDVBCISlot *tslot); + ~eDVBCIApplicationManagerSession(); + int enterMenu(); + int startMMI(); }; #endif diff --git a/libdvbci/dvbci_camgr.cpp b/libdvbci/dvbci_camgr.cpp index 88ac727..2138b77 100644 --- a/libdvbci/dvbci_camgr.cpp +++ b/libdvbci/dvbci_camgr.cpp @@ -20,7 +20,7 @@ int eDVBCICAManagerSession::receivedAPDU(const unsigned char *tag, const void *d { printf("[CI CA] SESSION(%d)/CA %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); for (int i = 0; i < len; i++) - printf("%02x ", ((const unsigned char*)data)[i]); + printf("%02x ", ((const unsigned char *)data)[i]); printf("\n"); if ((tag[0] == 0x9f) && (tag[1] == 0x80)) @@ -32,8 +32,8 @@ int eDVBCICAManagerSession::receivedAPDU(const unsigned char *tag, const void *d printf("[CI CA] ca info:\n"); for (int i = 0; i < len; i += 2) { - printf("%04x ", (((const unsigned char*)data)[i] << 8) | (((const unsigned char*)data)[i + 1])); - caids.push_back((((const unsigned char*)data)[i] << 8) | (((const unsigned char*)data)[i + 1])); + printf("%04x ", (((const unsigned char *)data)[i] << 8) | (((const unsigned char *)data)[i + 1])); + caids.push_back((((const unsigned char *)data)[i] << 8) | (((const unsigned char *)data)[i + 1])); } if (!caids.empty()) { @@ -85,7 +85,7 @@ int eDVBCICAManagerSession::doAction() } case stateFinal: printf("[CI CA] stateFinal and action should not happen\n"); - // fall through + // fall through default: return 0; } diff --git a/libdvbci/dvbci_camgr.h b/libdvbci/dvbci_camgr.h index 647057a..932ebff 100644 --- a/libdvbci/dvbci_camgr.h +++ b/libdvbci/dvbci_camgr.h @@ -7,18 +7,22 @@ class eDVBCICAManagerSession: public eDVBCISession { - enum { - stateFinal=statePrivate - }; - std::vector caids; - int receivedAPDU(const unsigned char *tag, const void *data, int len); - int doAction(); -public: - eDVBCICAManagerSession(eDVBCISlot *tslot); - ~eDVBCICAManagerSession(); + enum + { + stateFinal = statePrivate + }; + std::vector caids; + int receivedAPDU(const unsigned char *tag, const void *data, int len); + int doAction(); + public: + eDVBCICAManagerSession(eDVBCISlot *tslot); + ~eDVBCICAManagerSession(); - const std::vector &getCAIDs() const { return caids; } - int sendCAPMT(unsigned char *pmt, int len); + const std::vector &getCAIDs() const + { + return caids; + } + int sendCAPMT(unsigned char *pmt, int len); }; #endif diff --git a/libdvbci/dvbci_ccmgr.cpp b/libdvbci/dvbci_ccmgr.cpp index 418a1eb..a6e065b 100644 --- a/libdvbci/dvbci_ccmgr.cpp +++ b/libdvbci/dvbci_ccmgr.cpp @@ -28,15 +28,16 @@ #define x_debug 0 #define y_debug 0 -static const char * FILENAME = "[dvbci_ccmgr]"; +static const char *FILENAME = "[dvbci_ccmgr]"; /* storage & load of authenticated data (HostID & DHSK & AKH) */ static void CheckFile(char *file) { - if (access(file, F_OK) != 0) { + if (access(file, F_OK) != 0) + { printf("No File: %s\n", file); - FILE* fd; + FILE *fd; fd = fopen(file, "w"); fclose(fd); } @@ -64,19 +65,23 @@ static bool get_authdata(uint8_t *host_id, uint8_t *dhsk, uint8_t *akh, unsigned get_authdata_filename(filename, sizeof(filename), slot); fd = open(filename, O_RDONLY); - if (fd <= 0) { + if (fd <= 0) + { fprintf(stderr, "cannot open %s\n", filename); return false; } - for (i = 0; i < 5; i++) { - if (read(fd, chunk, sizeof(chunk)) != sizeof(chunk)) { + for (i = 0; i < 5; i++) + { + if (read(fd, chunk, sizeof(chunk)) != sizeof(chunk)) + { fprintf(stderr, "cannot read auth_data\n"); close(fd); return false; } - if (i == index) { + if (i == index) + { memcpy(host_id, chunk, 8); memcpy(dhsk, &chunk[8], 256); memcpy(akh, &chunk[8 + 256], 32); @@ -100,13 +105,15 @@ static bool write_authdata(unsigned int slot, const uint8_t *host_id, const uint unsigned int i; bool ret = false; - for (entries = 0; entries < 5; entries++) { + for (entries = 0; entries < 5; entries++) + { int offset = (8 + 256 + 32) * entries; if (!get_authdata(&buf[offset], &buf[offset + 8], &buf[offset + 8 + 256], slot, entries)) break; /* check if we got this pair already */ - if (!memcmp(&buf[offset + 8 + 256], akh, 32)) { + if (!memcmp(&buf[offset + 8 + 256], akh, 32)) + { printf("data already stored\n"); return true; } @@ -117,23 +124,27 @@ static bool write_authdata(unsigned int slot, const uint8_t *host_id, const uint get_authdata_filename(filename, sizeof(filename), slot); fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); - if (fd <= 0) { + if (fd <= 0) + { printf("cannot open %s for writing - authdata not stored\n", filename); return false; } /* store new entry first */ - if (write(fd, host_id, 8) != 8) { + if (write(fd, host_id, 8) != 8) + { fprintf(stderr, "error in write\n"); goto end; } - if (write(fd, dhsk, 256) != 256) { + if (write(fd, dhsk, 256) != 256) + { fprintf(stderr, "error in write\n"); goto end; } - if (write(fd, akh, 32) != 32) { + if (write(fd, akh, 32) != 32) + { fprintf(stderr, "error in write\n"); goto end; } @@ -142,9 +153,11 @@ static bool write_authdata(unsigned int slot, const uint8_t *host_id, const uint if (entries > 3) entries = 3; - for (i = 0; i < entries; i++) { + for (i = 0; i < entries; i++) + { int offset = (8 + 256 + 32) * i; - if (write(fd, &buf[offset], (8 + 256 + 32)) != (8 + 256 + 32)) { + if (write(fd, &buf[offset], (8 + 256 + 32)) != (8 + 256 + 32)) + { fprintf(stderr, "error in write\n"); goto end; } @@ -159,7 +172,8 @@ end: /* CI+ certificates */ -struct cert_ctx { +struct cert_ctx +{ X509_STORE *store; /* Host */ @@ -173,7 +187,8 @@ struct cert_ctx { static int verify_cb(int /*ok*/, X509_STORE_CTX *ctx) { - if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_NOT_YET_VALID) { + if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_NOT_YET_VALID) + { time_t now = time(NULL); struct tm *t = localtime(&now); if (t->tm_year < 2015) @@ -193,7 +208,8 @@ static RSA *rsa_privatekey_open(const char *filename) RSA *r = NULL; fp = fopen(filename, "r"); - if (!fp) { + if (!fp) + { fprintf(stderr, "cannot open %s\n", filename); return NULL; } @@ -213,7 +229,8 @@ static X509 *certificate_open(const char *filename) X509 *cert; fp = fopen(filename, "r"); - if (!fp) { + if (!fp) + { fprintf(stderr, "cannot open %s\n", filename); return NULL; } @@ -256,15 +273,18 @@ static X509 *certificate_load_and_check(struct cert_ctx *ctx, const char *filena { X509 *cert; - if (!ctx->store) { + if (!ctx->store) + { /* we assume this is the first certificate added - so its root-ca */ ctx->store = X509_STORE_new(); - if (!ctx->store) { + if (!ctx->store) + { fprintf(stderr, "cannot create cert_store\n"); exit(-1); } - if (X509_STORE_load_locations(ctx->store, filename, NULL) != 1) { + if (X509_STORE_load_locations(ctx->store, filename, NULL) != 1) + { fprintf(stderr, "load of first certificate (root_ca) failed\n"); exit(-1); } @@ -273,19 +293,22 @@ static X509 *certificate_load_and_check(struct cert_ctx *ctx, const char *filena } cert = certificate_open(filename); - if (!cert) { + if (!cert) + { fprintf(stderr, "cannot open certificate %s\n", filename); return NULL; } - if (!certificate_validate(ctx, cert)) { + if (!certificate_validate(ctx, cert)) + { fprintf(stderr, "cannot vaildate certificate\n"); X509_free(cert); return NULL; } /* push into store - create a chain */ - if (X509_STORE_load_locations(ctx->store, filename, NULL) != 1) { + if (X509_STORE_load_locations(ctx->store, filename, NULL) != 1) + { fprintf(stderr, "load of certificate failed\n"); X509_free(cert); return NULL; @@ -299,12 +322,14 @@ static X509 *certificate_import_and_check(struct cert_ctx *ctx, const uint8_t *d X509 *cert; cert = d2i_X509(NULL, &data, len); - if (!cert) { + if (!cert) + { fprintf(stderr, "cannot read certificate\n"); return NULL; } - if (!certificate_validate(ctx, cert)) { + if (!certificate_validate(ctx, cert)) + { fprintf(stderr, "cannot vaildate certificate\n"); X509_free(cert); return NULL; @@ -320,7 +345,8 @@ static X509 *certificate_import_and_check(struct cert_ctx *ctx, const uint8_t *d #define MAX_ELEMENTS 33 -uint32_t datatype_sizes[MAX_ELEMENTS] = { +uint32_t datatype_sizes[MAX_ELEMENTS] = +{ 0, 50, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 32, 256, 256, 0, 0, 256, 256, 32, 8, 8, 32, 32, @@ -328,14 +354,16 @@ uint32_t datatype_sizes[MAX_ELEMENTS] = { 32 }; -struct element { +struct element +{ uint8_t *data; uint32_t size; /* buffer valid */ bool valid; }; -struct cc_ctrl_data { +struct cc_ctrl_data +{ /* parent */ //struct ci_session *session; eDVBCISlot *slot; @@ -370,7 +398,8 @@ struct cc_ctrl_data { static struct element *element_get(struct cc_ctrl_data *cc_data, unsigned int id) { /* array index */ - if ((id < 1) || (id >= MAX_ELEMENTS)) { + if ((id < 1) || (id >= MAX_ELEMENTS)) + { fprintf(stderr, "element_get: invalid id\n"); return NULL; } @@ -383,7 +412,8 @@ static void element_invalidate(struct cc_ctrl_data *cc_data, unsigned int id) struct element *e; e = element_get(cc_data, id); - if (e) { + if (e) + { free(e->data); memset(e, 0, sizeof(struct element)); } @@ -406,13 +436,14 @@ static bool element_set(struct cc_ctrl_data *cc_data, unsigned int id, const uin return false; /* check size */ - if ((datatype_sizes[id] != 0) && (datatype_sizes[id] != size)) { + if ((datatype_sizes[id] != 0) && (datatype_sizes[id] != size)) + { fprintf(stderr, "size %d of datatype_id %d doesn't match\n", size, id); return false; } free(e->data); - e->data = (uint8_t*)malloc(size); + e->data = (uint8_t *)malloc(size); memcpy(e->data, data, size); e->size = size; e->valid = true; @@ -428,12 +459,14 @@ static bool element_set_certificate(struct cc_ctrl_data *cc_data, unsigned int i int cert_len; cert_len = i2d_X509(cert, &cert_der); - if (cert_len <= 0) { + if (cert_len <= 0) + { printf("cannot get data in DER format\n"); return false; } - if (!element_set(cc_data, id, cert_der, cert_len)) { + if (!element_set(cc_data, id, cert_der, cert_len)) + { printf("cannot store element (%d)\n", id); return false; } @@ -448,7 +481,8 @@ static bool element_set_hostid_from_certificate(struct cc_ctrl_data *cc_data, un char hostid[20]; uint8_t bin_hostid[8]; - if ((id != 5) && (id != 6)) { + if ((id != 5) && (id != 6)) + { printf("wrong datatype_id for hostid\n"); return false; } @@ -456,14 +490,16 @@ static bool element_set_hostid_from_certificate(struct cc_ctrl_data *cc_data, un subject = X509_get_subject_name(cert); X509_NAME_get_text_by_NID(subject, nid_cn, hostid, sizeof(hostid)); - if (strlen(hostid) != 16) { + if (strlen(hostid) != 16) + { printf("malformed hostid\n"); return false; } str2bin(bin_hostid, hostid, 16); - if (!element_set(cc_data, id, bin_hostid, sizeof(bin_hostid))) { + if (!element_set(cc_data, id, bin_hostid, sizeof(bin_hostid))) + { printf("cannot set hostid\n"); return false; } @@ -488,12 +524,14 @@ static unsigned int element_get_buf(struct cc_ctrl_data *cc_data, uint8_t *dest, if (e == NULL) return 0; - if (!e->valid) { + if (!e->valid) + { fprintf(stderr, "element_get_buf: datatype %d not valid\n", id); return 0; } - if (!e->data) { + if (!e->data) + { fprintf(stderr, "element_get_buf: datatype %d doesn't exist\n", id); return 0; } @@ -508,7 +546,8 @@ static unsigned int element_get_req(struct cc_ctrl_data *cc_data, uint8_t *dest, { unsigned int len = element_get_buf(cc_data, &dest[3], id); - if (len == 0) { + if (len == 0) + { fprintf(stderr, "cannot get element %d\n", id); return 0; } @@ -528,12 +567,14 @@ static uint8_t *element_get_ptr(struct cc_ctrl_data *cc_data, unsigned int id) if (e == NULL) return NULL; - if (!e->valid) { + if (!e->valid) + { fprintf(stderr, "element_get_ptr: datatype %u not valid\n", id); return NULL; } - if (!e->data) { + if (!e->data) + { fprintf(stderr, "element_get_ptr: datatype %u doesn't exist\n", id); return NULL; } @@ -557,7 +598,8 @@ static bool sac_check_auth(const uint8_t *data, unsigned int len, uint8_t *sak) aes_xcbc_mac_process(&ctx, data, len - 16); aes_xcbc_mac_done(&ctx, calced_signature); - if (memcmp(&data[len - 16], calced_signature, 16)) { + if (memcmp(&data[len - 16], calced_signature, 16)) + { fprintf(stderr, "signature wrong\n"); return false; } @@ -654,7 +696,8 @@ static X509 *import_ci_certificates(struct cc_ctrl_data *cc_data, unsigned int i len = element_get_buf(cc_data, buf, id); cert = certificate_import_and_check(ctx, buf, len); - if (!cert) { + if (!cert) + { printf("cannot read/verify DER cert\n"); return NULL; } @@ -688,19 +731,22 @@ static int check_ci_certificates(struct cc_ctrl_data *cc_data) #endif /* import CICAM_BrandCert */ - if ((ctx->ci_cust_cert = import_ci_certificates(cc_data, 8)) == NULL) { + if ((ctx->ci_cust_cert = import_ci_certificates(cc_data, 8)) == NULL) + { printf("cannot import cert\n"); return -1; } /* import CICAM_DevCert */ - if ((ctx->ci_device_cert = import_ci_certificates(cc_data, 16)) == NULL) { + if ((ctx->ci_device_cert = import_ci_certificates(cc_data, 16)) == NULL) + { printf("cannot import cert\n"); return -1; } /* everything seems to be fine here - so extract the CICAM_id from cert */ - if (!element_set_hostid_from_certificate(cc_data, 6, ctx->ci_device_cert)) { + if (!element_set_hostid_from_certificate(cc_data, 6, ctx->ci_device_cert)) + { printf("cannot set cicam_id in elements\n"); return -1; } @@ -770,10 +816,13 @@ static int restart_dh_challenge(struct cc_ctrl_data *cc_data) printf("%s -> %s\n", FILENAME, __FUNCTION__); - if (!cc_data->cert_ctx) { - ctx = (struct cert_ctx*)calloc(1, sizeof(struct cert_ctx)); + if (!cc_data->cert_ctx) + { + ctx = (struct cert_ctx *)calloc(1, sizeof(struct cert_ctx)); cc_data->cert_ctx = ctx; - } else { + } + else + { ctx = cc_data->cert_ctx; } @@ -782,7 +831,8 @@ static int restart_dh_challenge(struct cc_ctrl_data *cc_data) ctx->cust_cert = certificate_load_and_check(ctx, CUSTOMER_CERT); ctx->device_cert = certificate_load_and_check(ctx, DEVICE_CERT); - if (!ctx->cust_cert || !ctx->device_cert) { + if (!ctx->cust_cert || !ctx->device_cert) + { fprintf(stderr, "cannot loader certificates\n"); return -1; } @@ -798,7 +848,8 @@ static int restart_dh_challenge(struct cc_ctrl_data *cc_data) fprintf(stderr, "cannot set hostid in elements\n"); cc_data->rsa_device_key = rsa_privatekey_open(DEVICE_CERT); - if (!cc_data->rsa_device_key) { + if (!cc_data->rsa_device_key) + { fprintf(stderr, "cannot read private key\n"); return -1; } @@ -901,46 +952,47 @@ static int data_get_handle_new(struct cc_ctrl_data *cc_data, unsigned int id) /* depends on new received items */ - switch (id) { - case 8: /* CICAM_BrandCert */ - case 14: /* DHPM */ - case 16: /* CICAM_DevCert */ - case 18: /* Signature_B */ - /* this results in CICAM_ID when cert-chain is verified and ok */ - if (check_ci_certificates(cc_data)) + switch (id) + { + case 8: /* CICAM_BrandCert */ + case 14: /* DHPM */ + case 16: /* CICAM_DevCert */ + case 18: /* Signature_B */ + /* this results in CICAM_ID when cert-chain is verified and ok */ + if (check_ci_certificates(cc_data)) + break; + /* generate DHSK & AKH */ + check_dh_challenge(cc_data); break; - /* generate DHSK & AKH */ - check_dh_challenge(cc_data); - break; - case 19: /* auth_nonce - triggers new dh keychallenge - invalidates DHSK & AKH */ - /* generate DHPH & Signature_A */ - restart_dh_challenge(cc_data); - break; + case 19: /* auth_nonce - triggers new dh keychallenge - invalidates DHSK & AKH */ + /* generate DHPH & Signature_A */ + restart_dh_challenge(cc_data); + break; - case 21: /* Ns_module - triggers SAC key calculation */ - generate_ns_host(cc_data); - generate_key_seed(cc_data); - generate_SAK_SEK(cc_data->sak, cc_data->sek, cc_data->ks_host); - break; + case 21: /* Ns_module - triggers SAC key calculation */ + generate_ns_host(cc_data); + generate_key_seed(cc_data); + generate_SAK_SEK(cc_data->sak, cc_data->sek, cc_data->ks_host); + break; - /* SAC data messages */ + /* SAC data messages */ - case 6: //CICAM_id - case 12: //keyprecursor - check_new_key(cc_data); - break; - case 26: //programm number - case 25: //uri_message - generate_uri_confirm(cc_data, cc_data->sak); - break; - case 28: //key register - check_new_key(cc_data); - break; + case 6: //CICAM_id + case 12: //keyprecursor + check_new_key(cc_data); + break; + case 26: //programm number + case 25: //uri_message + generate_uri_confirm(cc_data, cc_data->sak); + break; + case 28: //key register + check_new_key(cc_data); + break; - default: - printf("%s -> %s unhandled ID (%d)\n", FILENAME, __FUNCTION__, id); - break; + default: + printf("%s -> %s unhandled ID (%d)\n", FILENAME, __FUNCTION__, id); + break; } return 0; @@ -951,22 +1003,24 @@ static int data_req_handle_new(struct cc_ctrl_data *cc_data, unsigned int id) #if x_debug printf("%s -> %s ID = (%d)\n", FILENAME, __FUNCTION__, id); #endif - switch (id) { - case 22: /* AKH */ + switch (id) { - uint8_t akh[32], host_id[8]; - memset(akh, 0, sizeof(akh)); - if (cc_data->akh_index != 5) { - if (!get_authdata(host_id, cc_data->dhsk, akh, cc_data->slot->slot, cc_data->akh_index++)) - cc_data->akh_index = 5; - if (!element_set(cc_data, 22, akh, 32)) - printf("cannot set AKH in elements\n"); - if (!element_set(cc_data, 5, host_id, 8)) - printf("cannot set host_id in elements\n"); + case 22: /* AKH */ + { + uint8_t akh[32], host_id[8]; + memset(akh, 0, sizeof(akh)); + if (cc_data->akh_index != 5) + { + if (!get_authdata(host_id, cc_data->dhsk, akh, cc_data->slot->slot, cc_data->akh_index++)) + cc_data->akh_index = 5; + if (!element_set(cc_data, 22, akh, 32)) + printf("cannot set AKH in elements\n"); + if (!element_set(cc_data, 5, host_id, 8)) + printf("cannot set host_id in elements\n"); + } } - } - default: - break; + default: + break; } return 0; @@ -980,7 +1034,8 @@ static int data_get_loop(struct cc_ctrl_data *cc_data, const unsigned char *data #if x_debug printf("%s -> %s\n", FILENAME, __FUNCTION__); #endif - for (i = 0; i < items; i++) { + for (i = 0; i < items; i++) + { if (pos + 3 > datalen) return 0; @@ -1020,14 +1075,16 @@ static int data_req_loop(struct cc_ctrl_data *cc_data, unsigned char *dest, cons if (items > datalen) return -1; - for (i = 0; i < items; i++) { + for (i = 0; i < items; i++) + { dt_id = *data++; #if x_debug printf("req element %d\n", dt_id); #endif data_req_handle_new(cc_data, dt_id); /* check if there is any action needed before we answer */ len = element_get_req(cc_data, dest, dt_id); - if (len == 0) { + if (len == 0) + { printf("cannot get element %d\n", dt_id); return -1; } @@ -1054,13 +1111,15 @@ bool eDVBCIContentControlManagerSession::data_initialize(eDVBCISlot *tslot) printf("%s -> %s\n", FILENAME, __FUNCTION__); - if (tslot->private_data) { + if (tslot->private_data) + { fprintf(stderr, "strange private_data not null!\n"); return false; } - data = (struct cc_ctrl_data*)calloc(1, sizeof(struct cc_ctrl_data)); - if (!data) { + data = (struct cc_ctrl_data *)calloc(1, sizeof(struct cc_ctrl_data)); + if (!data) + { fprintf(stderr, "out of memory\n"); return false; } @@ -1084,7 +1143,8 @@ bool eDVBCIContentControlManagerSession::data_initialize(eDVBCISlot *tslot) /* load first AKH */ data->akh_index = 0; - if (!get_authdata(host_id, data->dhsk, buf, tslot->slot, data->akh_index)) { + if (!get_authdata(host_id, data->dhsk, buf, tslot->slot, data->akh_index)) + { /* no AKH available */ memset(buf, 0, sizeof(buf)); data->akh_index = 5; /* last one */ @@ -1114,7 +1174,7 @@ void eDVBCIContentControlManagerSession::ci_ccmgr_cc_open_cnf(eDVBCISlot *tslot) bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len) { - struct cc_ctrl_data *cc_data = (struct cc_ctrl_data*)(tslot->private_data); + struct cc_ctrl_data *cc_data = (struct cc_ctrl_data *)(tslot->private_data); uint8_t cc_data_cnf_tag[3] = { 0x9f, 0x90, 0x04 }; uint8_t dest[2048 * 2]; int dt_nr; @@ -1143,7 +1203,8 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_data_req(eDVBCISlot *tslot, dest[1] = dt_nr; answ_len = data_req_loop(cc_data, &dest[2], &data[rp], len - rp, dt_nr); - if (answ_len <= 0) { + if (answ_len <= 0) + { fprintf(stderr, "cannot req data\n"); return false; } @@ -1157,9 +1218,9 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_data_req(eDVBCISlot *tslot, void eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_sync_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int #if y_debug - len + len #endif - ) +) { const uint8_t sync_cnf_tag[3] = { 0x9f, 0x90, 0x10 }; uint8_t dest[64]; @@ -1193,7 +1254,7 @@ void eDVBCIContentControlManagerSession::ci_ccmgr_cc_sync_req() bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_send(eDVBCISlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos) { - struct cc_ctrl_data *cc_data = (struct cc_ctrl_data*)(tslot->private_data); + struct cc_ctrl_data *cc_data = (struct cc_ctrl_data *)(tslot->private_data); printf("%s -> %s (%02X%02X%02X) \n", FILENAME, __FUNCTION__, tag[0], tag[1], tag[2]); if (pos < 8) @@ -1217,7 +1278,7 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_send(eDVBCISlot *tslot, bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len) { - struct cc_ctrl_data *cc_data = (struct cc_ctrl_data*)(tslot->private_data); + struct cc_ctrl_data *cc_data = (struct cc_ctrl_data *)(tslot->private_data); const uint8_t data_cnf_tag[3] = { 0x9f, 0x90, 0x08 }; uint8_t dest[2048]; uint8_t tmp[len]; @@ -1240,7 +1301,8 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(eDVBCISlot *ts printf("%02x ", data[i]); printf("\n"); #endif - if (!sac_check_auth(data, len, cc_data->sak)) { + if (!sac_check_auth(data, len, cc_data->sak)) + { fprintf(stderr, "check_auth of message failed\n"); return false; } @@ -1269,7 +1331,8 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(eDVBCISlot *ts dest[pos++] = dt_nr; /* dt_nbr */ answ_len = data_req_loop(cc_data, &dest[pos], &data[rp], len - rp, dt_nr); - if (answ_len <= 0) { + if (answ_len <= 0) + { fprintf(stderr, "cannot req data\n"); return false; } @@ -1294,7 +1357,7 @@ eDVBCIContentControlManagerSession::~eDVBCIContentControlManagerSession() void eDVBCIContentControlManagerSession::ci_ccmgr_doClose(eDVBCISlot *tslot) { - struct cc_ctrl_data *data = (struct cc_ctrl_data*)(tslot->private_data); + struct cc_ctrl_data *data = (struct cc_ctrl_data *)(tslot->private_data); printf("%s -> %s\n", FILENAME, __FUNCTION__); descrambler_deinit(); @@ -1309,23 +1372,35 @@ int eDVBCIContentControlManagerSession::receivedAPDU(const unsigned char *tag, c printf("SESSION(%d)/CC %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); #if y_debug for (int i = 0; i < len; i++) - printf("%02x ", ((const unsigned char*)data)[i]); + printf("%02x ", ((const unsigned char *)data)[i]); #endif printf("\n"); - if ((tag[0] == 0x9f) && (tag[1] == 0x90)) { - switch (tag[2]) { - case 0x01: ci_ccmgr_cc_open_cnf(slot); break; - case 0x03: ci_ccmgr_cc_data_req(slot, (const uint8_t*)data, len); break; - case 0x05: ci_ccmgr_cc_sync_req(); break; - case 0x07: ci_ccmgr_cc_sac_data_req(slot, (const uint8_t*)data, len); break; - case 0x09: ci_ccmgr_cc_sac_sync_req(slot, (const uint8_t*)data, len); break; - default: - fprintf(stderr, "unknown apdu tag %02x\n", tag[2]); - break; + if ((tag[0] == 0x9f) && (tag[1] == 0x90)) + { + switch (tag[2]) + { + case 0x01: + ci_ccmgr_cc_open_cnf(slot); + break; + case 0x03: + ci_ccmgr_cc_data_req(slot, (const uint8_t *)data, len); + break; + case 0x05: + ci_ccmgr_cc_sync_req(); + break; + case 0x07: + ci_ccmgr_cc_sac_data_req(slot, (const uint8_t *)data, len); + break; + case 0x09: + ci_ccmgr_cc_sac_sync_req(slot, (const uint8_t *)data, len); + break; + default: + fprintf(stderr, "unknown apdu tag %02x\n", tag[2]); + break; } } - + return 0; } @@ -1342,7 +1417,7 @@ int eDVBCIContentControlManagerSession::doAction() } case stateFinal: printf("stateFinal und action! kann doch garnicht sein ;)\n"); - // fall through + // fall through default: return 0; } diff --git a/libdvbci/dvbci_ccmgr.h b/libdvbci/dvbci_ccmgr.h index a9046ee..0dfaf42 100644 --- a/libdvbci/dvbci_ccmgr.h +++ b/libdvbci/dvbci_ccmgr.h @@ -5,23 +5,24 @@ class eDVBCIContentControlManagerSession: public eDVBCISession { - bool data_initialize(eDVBCISlot *tslot); - bool ci_ccmgr_cc_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len); - bool ci_ccmgr_cc_sac_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len); - bool ci_ccmgr_cc_sac_send(eDVBCISlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos); - void ci_ccmgr_cc_sac_sync_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len); - void ci_ccmgr_cc_sync_req(); - void ci_ccmgr_cc_open_cnf(eDVBCISlot *slot); + bool data_initialize(eDVBCISlot *tslot); + bool ci_ccmgr_cc_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len); + bool ci_ccmgr_cc_sac_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len); + bool ci_ccmgr_cc_sac_send(eDVBCISlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos); + void ci_ccmgr_cc_sac_sync_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len); + void ci_ccmgr_cc_sync_req(); + void ci_ccmgr_cc_open_cnf(eDVBCISlot *slot); - enum { - stateFinal=statePrivate - }; - int receivedAPDU(const unsigned char *tag, const void *data, int len); - int doAction(); -public: - eDVBCIContentControlManagerSession(eDVBCISlot *tslot); - ~eDVBCIContentControlManagerSession(); - void ci_ccmgr_doClose(eDVBCISlot *tslot); - void resendKey(eDVBCISlot *tslot); + enum + { + stateFinal = statePrivate + }; + int receivedAPDU(const unsigned char *tag, const void *data, int len); + int doAction(); + public: + eDVBCIContentControlManagerSession(eDVBCISlot *tslot); + ~eDVBCIContentControlManagerSession(); + void ci_ccmgr_doClose(eDVBCISlot *tslot); + void resendKey(eDVBCISlot *tslot); }; #endif diff --git a/libdvbci/dvbci_datetimemgr.cpp b/libdvbci/dvbci_datetimemgr.cpp index d6206c2..9ce203e 100644 --- a/libdvbci/dvbci_datetimemgr.cpp +++ b/libdvbci/dvbci_datetimemgr.cpp @@ -22,7 +22,7 @@ int eDVBCIDateTimeSession::receivedAPDU(const unsigned char *tag, const void *da { printf("[CI DT] SESSION(%d)/DATETIME %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); for (int i = 0; i < len; i++) - printf("%02x ", ((const unsigned char*)data)[i]); + printf("%02x ", ((const unsigned char *)data)[i]); printf("\n"); if ((tag[0] == 0x9f) && (tag[1] == 0x84)) @@ -52,7 +52,7 @@ int eDVBCIDateTimeSession::doAction() return 0; case stateFinal: printf("stateFinal und action! kann doch garnicht sein ;)\n"); - // fall through + // fall through default: return 0; } @@ -66,7 +66,7 @@ void eDVBCIDateTimeSession::sendDateTime() unsigned char msg[7] = {0, 0, 0, 0, 0, 0, 0}; printf("[CI DT] -> %s\n", __FUNCTION__); time_t t = time(NULL); - if ( gmtime_r(&t, &tm_gmt) && localtime_r(&t, &tm_loc) ) + if (gmtime_r(&t, &tm_gmt) && localtime_r(&t, &tm_loc)) { int Y = tm_gmt.tm_year; int M = tm_gmt.tm_mon + 1; diff --git a/libdvbci/dvbci_datetimemgr.h b/libdvbci/dvbci_datetimemgr.h index 52f7492..338a853 100644 --- a/libdvbci/dvbci_datetimemgr.h +++ b/libdvbci/dvbci_datetimemgr.h @@ -5,15 +5,16 @@ class eDVBCIDateTimeSession: public eDVBCISession { - enum { - stateFinal=statePrivate, stateSendDateTime - }; - int receivedAPDU(const unsigned char *tag, const void *data, int len); - int doAction(); -public: - eDVBCIDateTimeSession(eDVBCISlot *tslot); - ~eDVBCIDateTimeSession(); - void sendDateTime(); + enum + { + stateFinal = statePrivate, stateSendDateTime + }; + int receivedAPDU(const unsigned char *tag, const void *data, int len); + int doAction(); + public: + eDVBCIDateTimeSession(eDVBCISlot *tslot); + ~eDVBCIDateTimeSession(); + void sendDateTime(); }; #endif diff --git a/libdvbci/dvbci_mmi.cpp b/libdvbci/dvbci_mmi.cpp index 5c87c09..3f9e726 100644 --- a/libdvbci/dvbci_mmi.cpp +++ b/libdvbci/dvbci_mmi.cpp @@ -17,7 +17,7 @@ eDVBCIMMISession::eDVBCIMMISession(eDVBCISlot *tslot) eDVBCIMMISession::~eDVBCIMMISession() { /* Send a message to Neutrino cam_menu handler */ - CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE)); + CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE)); memset(pMsg, 0, sizeof(CA_MESSAGE)); pMsg->MsgId = CA_MESSAGE_MSG_MMI_CLOSE; @@ -34,7 +34,7 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i { printf("[CI MMI] SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); for (int i = 0; i < len; i++) - printf("%02x ", ((const unsigned char*)data)[i]); + printf("%02x ", ((const unsigned char *)data)[i]); printf("\n"); if ((tag[0] == 0x9f) && (tag[1] == 0x88)) @@ -45,7 +45,7 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i case 0x00: /* close */ { /* Send a message to Neutrino cam_menu handler */ - CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE)); + CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE)); memset(pMsg, 0, sizeof(CA_MESSAGE)); pMsg->MsgId = CA_MESSAGE_MSG_MMI_CLOSE; @@ -61,10 +61,10 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i break; case 0x07: /* menu enq */ { - MMI_ENQUIRY_INFO* enquiry = (MMI_ENQUIRY_INFO*) malloc(sizeof(MMI_ENQUIRY_INFO)); + MMI_ENQUIRY_INFO *enquiry = (MMI_ENQUIRY_INFO *) malloc(sizeof(MMI_ENQUIRY_INFO)); memset(enquiry, 0, sizeof(MMI_ENQUIRY_INFO)); - unsigned char *d = (unsigned char*)data; - unsigned char *max = ((unsigned char*)d) + len; + unsigned char *d = (unsigned char *)data; + unsigned char *max = ((unsigned char *)d) + len; int textlen = len - 2; if ((d + 2) > max) @@ -77,7 +77,7 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i break; char str[textlen + 1]; - memcpy(str, ((char*)d), textlen); + memcpy(str, ((char *)d), textlen); str[textlen] = '\0'; printf("enq-text: %s", str); enquiry->slot = slot->slot; @@ -86,14 +86,14 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i strcpy(enquiry->enquiryText, str); /* Send a message to Neutrino cam_menu handler */ - CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE)); + CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE)); memset(pMsg, 0, sizeof(CA_MESSAGE)); pMsg->MsgId = CA_MESSAGE_MSG_MMI_REQ_INPUT; pMsg->SlotType = CA_SLOT_TYPE_CI; pMsg->Slot = slot->slot; pMsg->Flags = CA_MESSAGE_HAS_PARAM1_DATA; - pMsg->Msg.Data[0] = (uint8_t*)enquiry; + pMsg->Msg.Data[0] = (uint8_t *)enquiry; cCA::GetInstance()->SendMessage(pMsg); slot->mmiOpened = true; @@ -102,14 +102,14 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i case 0x09: /* menu last */ case 0x0c: /* list last */ { - MMI_MENU_LIST_INFO* listInfo = (MMI_MENU_LIST_INFO*) malloc(sizeof(MMI_MENU_LIST_INFO)); + MMI_MENU_LIST_INFO *listInfo = (MMI_MENU_LIST_INFO *) malloc(sizeof(MMI_MENU_LIST_INFO)); memset(listInfo, 0, sizeof(MMI_MENU_LIST_INFO)); listInfo->slot = slot->slot; listInfo->choice_nb = 0; - unsigned char *d = (unsigned char*)data; - unsigned char *max = ((unsigned char*)d) + len; + unsigned char *d = (unsigned char *)data; + unsigned char *max = ((unsigned char *)d) + len; int pos = 0; if (tag[2] == 0x09) @@ -142,7 +142,7 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i break; char str[textlen + 1]; - memcpy(str, ((char*)d), textlen); + memcpy(str, ((char *)d), textlen); str[textlen] = '\0'; int type = pos++; @@ -168,27 +168,27 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i if (tag[2] == 0x09) { /* Send a message to Neutrino cam_menu handler */ - CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE)); + CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE)); memset(pMsg, 0, sizeof(CA_MESSAGE)); pMsg->MsgId = CA_MESSAGE_MSG_MMI_MENU; pMsg->SlotType = CA_SLOT_TYPE_CI; pMsg->Slot = slot->slot; pMsg->Flags = CA_MESSAGE_HAS_PARAM1_DATA; - pMsg->Msg.Data[0] = (uint8_t*)listInfo; + pMsg->Msg.Data[0] = (uint8_t *)listInfo; cCA::GetInstance()->SendMessage(pMsg); } else { /* Send a message to Neutrino cam_menu handler */ - CA_MESSAGE* pMsg = (CA_MESSAGE*) malloc(sizeof(CA_MESSAGE)); + CA_MESSAGE *pMsg = (CA_MESSAGE *) malloc(sizeof(CA_MESSAGE)); memset(pMsg, 0, sizeof(CA_MESSAGE)); pMsg->MsgId = CA_MESSAGE_MSG_MMI_LIST; pMsg->SlotType = CA_SLOT_TYPE_CI; pMsg->Slot = slot->slot; pMsg->Flags = CA_MESSAGE_HAS_PARAM1_DATA; - pMsg->Msg.Data[0] = (uint8_t*)listInfo; + pMsg->Msg.Data[0] = (uint8_t *)listInfo; cCA::GetInstance()->SendMessage(pMsg); } } @@ -245,7 +245,7 @@ int eDVBCIMMISession::stopMMI() int eDVBCIMMISession::answerText(int answer) { - printf("[CI MMI] eDVBCIMMISession::answerText(%d)\n",answer); + printf("[CI MMI] eDVBCIMMISession::answerText(%d)\n", answer); unsigned char tag[] = {0x9f, 0x88, 0x0B}; unsigned char data[] = {0x00}; diff --git a/libdvbci/dvbci_mmi.h b/libdvbci/dvbci_mmi.h index 25501c2..38ed6d2 100644 --- a/libdvbci/dvbci_mmi.h +++ b/libdvbci/dvbci_mmi.h @@ -5,20 +5,21 @@ class eDVBCIMMISession: public eDVBCISession { - enum { - stateDisplayReply=statePrivate, stateFakeOK, stateIdle - }; + enum + { + stateDisplayReply = statePrivate, stateFakeOK, stateIdle + }; - int receivedAPDU(const unsigned char *tag, const void *data, int len); - int doAction(); - eDVBCISlot *slot; -public: - eDVBCIMMISession(eDVBCISlot *tslot); - ~eDVBCIMMISession(); - int stopMMI(); - int answerText(int answer); - int answerEnq(char *answer, int len); - int cancelEnq(); + int receivedAPDU(const unsigned char *tag, const void *data, int len); + int doAction(); + eDVBCISlot *slot; + public: + eDVBCIMMISession(eDVBCISlot *tslot); + ~eDVBCIMMISession(); + int stopMMI(); + int answerText(int answer); + int answerEnq(char *answer, int len); + int cancelEnq(); }; #endif diff --git a/libdvbci/dvbci_resmgr.cpp b/libdvbci/dvbci_resmgr.cpp index 65ce0ea..3af04a7 100644 --- a/libdvbci/dvbci_resmgr.cpp +++ b/libdvbci/dvbci_resmgr.cpp @@ -9,7 +9,7 @@ int eDVBCIResourceManagerSession::receivedAPDU(const unsigned char *tag, const v if (len) { for (int i = 0; i < len; i++) - printf("%02x ", ((const unsigned char*)data)[i]); + printf("%02x ", ((const unsigned char *)data)[i]); printf("\n"); } if ((tag[0] == 0x9f) && (tag[1] == 0x80)) @@ -27,7 +27,7 @@ int eDVBCIResourceManagerSession::receivedAPDU(const unsigned char *tag, const v printf("nothing"); else for (int i = 0; i < len; i++) - printf("%02x ", ((const unsigned char*)data)[i]); + printf("%02x ", ((const unsigned char *)data)[i]); printf("\n"); if (state == stateFirstProfileEnquiry) @@ -76,16 +76,16 @@ int eDVBCIResourceManagerSession::doAction() { const unsigned char data[][4] = { - {0x00, 0x01, 0x00, 0x41}, // resource - {0x00, 0x02, 0x00, 0x41}, // application V1 - {0x00, 0x02, 0x00, 0x43}, // application V3 - {0x00, 0x03, 0x00, 0x41}, // conditional access - {0x00, 0x20, 0x00, 0x41}, // host control (dummy) - {0x00, 0x40, 0x00, 0x41}, // mmi - {0x00, 0x24, 0x00, 0x41}, // date-time - {0x00, 0x8c, 0x10, 0x01}, // content control - {0x00, 0x8e, 0x10, 0x01} // cam upgrade (dummy) -// {0x00, 0x10, 0x00, 0x41} // auth. + {0x00, 0x01, 0x00, 0x41}, // resource + {0x00, 0x02, 0x00, 0x41}, // application V1 + {0x00, 0x02, 0x00, 0x43}, // application V3 + {0x00, 0x03, 0x00, 0x41}, // conditional access + {0x00, 0x20, 0x00, 0x41}, // host control (dummy) + {0x00, 0x40, 0x00, 0x41}, // mmi + {0x00, 0x24, 0x00, 0x41}, // date-time + {0x00, 0x8c, 0x10, 0x01}, // content control + {0x00, 0x8e, 0x10, 0x01} // cam upgrade (dummy) +// {0x00, 0x10, 0x00, 0x41} // auth. }; sendAPDU(tag, data, sizeof(data)); } @@ -93,14 +93,14 @@ int eDVBCIResourceManagerSession::doAction() { const unsigned char data[][4] = { - {0x00, 0x01, 0x00, 0x41}, // resource - {0x00, 0x02, 0x00, 0x41}, // application V1 - {0x00, 0x02, 0x00, 0x43}, // application V3 - {0x00, 0x03, 0x00, 0x41}, // conditional access -// {0x00, 0x20, 0x00, 0x41}, // host control - {0x00, 0x40, 0x00, 0x41}, // mmi - {0x00, 0x24, 0x00, 0x41} // date-time -// {0x00, 0x10, 0x00, 0x41} // auth. + {0x00, 0x01, 0x00, 0x41}, // resource + {0x00, 0x02, 0x00, 0x41}, // application V1 + {0x00, 0x02, 0x00, 0x43}, // application V3 + {0x00, 0x03, 0x00, 0x41}, // conditional access +// {0x00, 0x20, 0x00, 0x41}, // host control + {0x00, 0x40, 0x00, 0x41}, // mmi + {0x00, 0x24, 0x00, 0x41} // date-time +// {0x00, 0x10, 0x00, 0x41} // auth. }; sendAPDU(tag, data, sizeof(data)); } diff --git a/libdvbci/dvbci_resmgr.h b/libdvbci/dvbci_resmgr.h index 85f4589..2f9a881 100644 --- a/libdvbci/dvbci_resmgr.h +++ b/libdvbci/dvbci_resmgr.h @@ -5,15 +5,16 @@ class eDVBCIResourceManagerSession: public eDVBCISession { - enum { - stateFirstProfileEnquiry=statePrivate, - stateProfileChange, - stateProfileEnquiry, - stateFinal - }; - int receivedAPDU(const unsigned char *tag, const void *data, int len); - int doAction(); -public: + enum + { + stateFirstProfileEnquiry = statePrivate, + stateProfileChange, + stateProfileEnquiry, + stateFinal + }; + int receivedAPDU(const unsigned char *tag, const void *data, int len); + int doAction(); + public: }; diff --git a/libdvbci/dvbci_session.cpp b/libdvbci/dvbci_session.cpp index f60020d..bcf7560 100644 --- a/libdvbci/dvbci_session.cpp +++ b/libdvbci/dvbci_session.cpp @@ -12,7 +12,7 @@ #include "dvbci_mmi.h" #include "dvbci_ccmgr.h" -eDVBCISession* eDVBCISession::sessions[SLMS]; +eDVBCISession *eDVBCISession::sessions[SLMS]; eDVBCIHostControlSession::eDVBCIHostControlSession(eDVBCISlot *tslot) { @@ -23,11 +23,11 @@ eDVBCIHostControlSession::~eDVBCIHostControlSession() { } -int eDVBCIHostControlSession::receivedAPDU(const unsigned char *tag,const void *data, int len) +int eDVBCIHostControlSession::receivedAPDU(const unsigned char *tag, const void *data, int len) { printf("CI HC SESSION(%d)/TAG %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); - for (int i=0; iCheckCerts()) - { + if (cCA::GetInstance()->CheckCerts()) + { case 0x008c1001: printf("[CI SESS] CC MANAGER\n"); sessions[session_nb - 1] = new eDVBCIContentControlManagerSession(slot); break; - } // fall through + } // fall through case 0x00200041: sessions[session_nb - 1] = new eDVBCIHostControlSession(slot); printf("[CI SESS] Host Control\n"); @@ -222,7 +222,7 @@ eDVBCISession* eDVBCISession::createSession(eDVBCISlot *slot, const unsigned cha // session=new eDVBCIAuthSession; printf("[CI SESS] AuthSession\n"); // break; - // fall through + // fall through case 0x008e1001: default: printf("[CI SESS] unknown resource type %02x %02x %02x %02x\n", resource_identifier[0], resource_identifier[1], resource_identifier[2], resource_identifier[3]); @@ -284,18 +284,18 @@ int eDVBCISession::pollAll() void eDVBCISession::receiveData(eDVBCISlot *slot, const unsigned char *ptr, size_t len) { - if ((ptr[0] == 0x90 || ptr[0] == 0x95) && (ptr[3] == 0 )) + if ((ptr[0] == 0x90 || ptr[0] == 0x95) && (ptr[3] == 0)) { printf("[CI SESS] ****Mist: %02x %02x %02x %02x\n", ptr[0], ptr[1], ptr[2], ptr[3]); } - const unsigned char *pkt = (const unsigned char*)ptr; + const unsigned char *pkt = (const unsigned char *)ptr; unsigned char tag = *pkt++; int llen, hlen; - printf("[CI SESS] receiveData slot: %p > ",slot); + printf("[CI SESS] receiveData slot: %p > ", slot); #if 0 - for(unsigned int i = 0; i < len; i++) + for (unsigned int i = 0; i < len; i++) printf("%02x ", ptr[i]); #endif printf("\n"); @@ -303,9 +303,9 @@ void eDVBCISession::receiveData(eDVBCISlot *slot, const unsigned char *ptr, size llen = parseLengthField(pkt, hlen); pkt += llen; - eDVBCISession* session = NULL; + eDVBCISession *session = NULL; - if(tag == 0x91) + if (tag == 0x91) { unsigned char status; @@ -357,7 +357,7 @@ void eDVBCISession::receiveData(eDVBCISlot *slot, const unsigned char *ptr, size hlen += llen + 1; // lengthfield and tag - pkt = ((const unsigned char*)ptr) + hlen; + pkt = ((const unsigned char *)ptr) + hlen; len -= hlen; if (session) diff --git a/libdvbci/dvbci_session.h b/libdvbci/dvbci_session.h index 1367891..37580dd 100644 --- a/libdvbci/dvbci_session.h +++ b/libdvbci/dvbci_session.h @@ -11,53 +11,68 @@ class eDVBCISession { - static eDVBCISession* sessions[SLMS]; - static eDVBCISession* createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status); - static void sendSPDU(eDVBCISlot *slot, unsigned char tag,const void *data, int len, unsigned short session_nb, const void *apdu = 0, int alen = 0); - static void sendOpenSessionResponse(eDVBCISlot *slot,unsigned char session_status, const unsigned char *resource_identifier, unsigned short session_nb); - void recvCreateSessionResponse(const unsigned char *data); - void recvCloseSessionRequest(const unsigned char *data); -protected: - int state; - int status; - int action; - eDVBCISlot *slot; - unsigned short session_nb; - virtual int receivedAPDU(const unsigned char *tag, const void *data, int len) = 0; - void sendAPDU(const unsigned char *tag, const void *data=0,int len=0); - virtual int doAction() = 0; - void handleClose(); -public: - virtual ~eDVBCISession(); + static eDVBCISession *sessions[SLMS]; + static eDVBCISession *createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status); + static void sendSPDU(eDVBCISlot *slot, unsigned char tag, const void *data, int len, unsigned short session_nb, const void *apdu = 0, int alen = 0); + static void sendOpenSessionResponse(eDVBCISlot *slot, unsigned char session_status, const unsigned char *resource_identifier, unsigned short session_nb); + void recvCreateSessionResponse(const unsigned char *data); + void recvCloseSessionRequest(const unsigned char *data); + protected: + int state; + int status; + int action; + eDVBCISlot *slot; + unsigned short session_nb; + virtual int receivedAPDU(const unsigned char *tag, const void *data, int len) = 0; + void sendAPDU(const unsigned char *tag, const void *data = 0, int len = 0); + virtual int doAction() = 0; + void handleClose(); + public: + virtual ~eDVBCISession(); - static void deleteSessions(const eDVBCISlot *slot); - void sendSPDU(unsigned char tag, const void *data, int len, const void *apdu = 0, int alen = 0); + static void deleteSessions(const eDVBCISlot *slot); + void sendSPDU(unsigned char tag, const void *data, int len, const void *apdu = 0, int alen = 0); - int poll() { if (action) { action=doAction(); return 1; } return 0; } - enum { stateInCreation, stateBusy, stateInDeletion, stateStarted, statePrivate}; + int poll() + { + if (action) + { + action = doAction(); + return 1; + } + return 0; + } + enum { stateInCreation, stateBusy, stateInDeletion, stateStarted, statePrivate}; - static int parseLengthField(const unsigned char *pkt, int &len); - static int buildLengthField(unsigned char *pkt, int len); + static int parseLengthField(const unsigned char *pkt, int &len); + static int buildLengthField(unsigned char *pkt, int len); - static void receiveData(eDVBCISlot *slot, const unsigned char *ptr, size_t len); + static void receiveData(eDVBCISlot *slot, const unsigned char *ptr, size_t len); - int getState() { return state; } - int getStatus() { return status; } + int getState() + { + return state; + } + int getStatus() + { + return status; + } - static int pollAll(); + static int pollAll(); }; class eDVBCIHostControlSession: public eDVBCISession { - enum { - stateFinal=statePrivate - }; - eDVBCISlot *slot; - int receivedAPDU(const unsigned char *tag,const void *data, int len); - int doAction(); -public: - eDVBCIHostControlSession(eDVBCISlot *tslot); - ~eDVBCIHostControlSession(); + enum + { + stateFinal = statePrivate + }; + eDVBCISlot *slot; + int receivedAPDU(const unsigned char *tag, const void *data, int len); + int doAction(); + public: + eDVBCIHostControlSession(eDVBCISlot *tslot); + ~eDVBCIHostControlSession(); }; diff --git a/libdvbci/misc.cpp b/libdvbci/misc.cpp index b09b889..3ff2ab2 100644 --- a/libdvbci/misc.cpp +++ b/libdvbci/misc.cpp @@ -16,12 +16,14 @@ int get_random(unsigned char *dest, int len) const char *urnd = "/dev/urandom"; fd = open(urnd, O_RDONLY); - if (fd <= 0) { + if (fd <= 0) + { printf("cannot open %s\n", urnd); return -1; } - if (read(fd, dest, len) != len) { + if (read(fd, dest, len) != len) + { printf("cannot read from %s\n", urnd); close(fd); return -2; @@ -37,11 +39,13 @@ int parseLengthField(const unsigned char *pkt, int *len) int i; *len = 0; - if (!(*pkt & 0x80)) { + if (!(*pkt & 0x80)) + { *len = *pkt; return 1; } - for (i = 0; i < (pkt[0] & 0x7F); ++i) { + for (i = 0; i < (pkt[0] & 0x7F); ++i) + { *len <<= 8; *len |= pkt[i + 1]; } @@ -53,7 +57,8 @@ int add_padding(uint8_t *dest, unsigned int len, unsigned int blocklen) uint8_t padding = 0x80; int count = 0; - while (len & (blocklen - 1)) { + while (len & (blocklen - 1)) + { *dest++ = padding; ++len; ++count; @@ -84,7 +89,7 @@ void str2bin(uint8_t *dst, char *data, int len) int i; for (i = 0; i < len; i += 2) - *dst++ = (get_bin_from_nibble(data[i]) << 4) | get_bin_from_nibble(data[i + 1]); + * dst++ = (get_bin_from_nibble(data[i]) << 4) | get_bin_from_nibble(data[i + 1]); } uint32_t UINT32(const unsigned char *in, unsigned int len) @@ -92,7 +97,8 @@ uint32_t UINT32(const unsigned char *in, unsigned int len) uint32_t val = 0; unsigned int i; - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) + { val <<= 8; val |= *in++; } diff --git a/libeplayer3-sh4/include/input.h b/libeplayer3-sh4/include/input.h index c842f21..648ebc1 100644 --- a/libeplayer3-sh4/include/input.h +++ b/libeplayer3-sh4/include/input.h @@ -51,9 +51,9 @@ class Track; class Input { - friend class Player; - friend class WriterPCM; // needs calcPts() - friend int interrupt_cb(void *arg); + friend class Player; + friend class WriterPCM; // needs calcPts() + friend int interrupt_cb(void *arg); private: OpenThreads::Mutex mutex; @@ -75,7 +75,7 @@ class Input CodecList codecs[EPLAYER_MAX_CODECS]; #endif uint64_t readCount; - int64_t calcPts(AVStream * stream, int64_t pts); + int64_t calcPts(AVStream *stream, int64_t pts); public: Input(); diff --git a/libeplayer3-sh4/include/manager.h b/libeplayer3-sh4/include/manager.h index 364595b..ca542e7 100644 --- a/libeplayer3-sh4/include/manager.h +++ b/libeplayer3-sh4/include/manager.h @@ -62,16 +62,16 @@ struct Program class Manager { - friend class Player; + friend class Player; private: Player *player; OpenThreads::Mutex mutex; - std::map videoTracks, audioTracks, subtitleTracks, teletextTracks; - std::map Programs; - void addTrack(std::map &tracks, Track &track); - Track *getTrack(std::map &tracks, int pid); - std::vector getTracks(std::map &tracks); + std::map videoTracks, audioTracks, subtitleTracks, teletextTracks; + std::map Programs; + void addTrack(std::map &tracks, Track &track); + Track *getTrack(std::map &tracks, int pid); + std::vector getTracks(std::map &tracks); public: void addVideoTrack(Track &track); void addAudioTrack(Track &track); diff --git a/libeplayer3-sh4/include/misc.h b/libeplayer3-sh4/include/misc.h index 34b2eb2..31513d5 100644 --- a/libeplayer3-sh4/include/misc.h +++ b/libeplayer3-sh4/include/misc.h @@ -5,16 +5,16 @@ #include -#define INVALID_PTS_VALUE 0x200000000ll +#define INVALID_PTS_VALUE 0x200000000ll struct BitPacker_t { - uint8_t *Ptr; /* write pointer */ - unsigned int BitBuffer; /* bitreader shifter */ - int Remaining; /* number of remaining in the shifter */ + uint8_t *Ptr; /* write pointer */ + unsigned int BitBuffer; /* bitreader shifter */ + int Remaining; /* number of remaining in the shifter */ }; -void PutBits(BitPacker_t * ld, unsigned int code, unsigned int length); -void FlushBits(BitPacker_t * ld); +void PutBits(BitPacker_t *ld, unsigned int code, unsigned int length); +void FlushBits(BitPacker_t *ld); #endif diff --git a/libeplayer3-sh4/include/output.h b/libeplayer3-sh4/include/output.h index b154427..9d33d3c 100644 --- a/libeplayer3-sh4/include/output.h +++ b/libeplayer3-sh4/include/output.h @@ -44,7 +44,7 @@ class Player; class Output { - friend class Player; + friend class Player; private: int videofd; diff --git a/libeplayer3-sh4/include/pes.h b/libeplayer3-sh4/include/pes.h index c9c63a5..5932eaa 100644 --- a/libeplayer3-sh4/include/pes.h +++ b/libeplayer3-sh4/include/pes.h @@ -3,30 +3,30 @@ #include -#define PES_MAX_HEADER_SIZE 64 -#define PES_PRIVATE_DATA_FLAG 0x80 -#define PES_PRIVATE_DATA_LENGTH 8 -#define PES_LENGTH_BYTE_0 5 -#define PES_LENGTH_BYTE_1 4 -#define PES_FLAGS_BYTE 7 -#define PES_EXTENSION_DATA_PRESENT 0x01 -#define PES_HEADER_DATA_LENGTH_BYTE 8 -#define PES_START_CODE_RESERVED_4 0xfd -#define PES_VERSION_FAKE_START_CODE 0x31 +#define PES_MAX_HEADER_SIZE 64 +#define PES_PRIVATE_DATA_FLAG 0x80 +#define PES_PRIVATE_DATA_LENGTH 8 +#define PES_LENGTH_BYTE_0 5 +#define PES_LENGTH_BYTE_1 4 +#define PES_FLAGS_BYTE 7 +#define PES_EXTENSION_DATA_PRESENT 0x01 +#define PES_HEADER_DATA_LENGTH_BYTE 8 +#define PES_START_CODE_RESERVED_4 0xfd +#define PES_VERSION_FAKE_START_CODE 0x31 -#define MAX_PES_PACKET_SIZE 65535 +#define MAX_PES_PACKET_SIZE 65535 /* start codes */ -#define PCM_PES_START_CODE 0xbd -#define PRIVATE_STREAM_1_PES_START_CODE 0xbd -#define H263_VIDEO_PES_START_CODE 0xfe -#define H264_VIDEO_PES_START_CODE 0xe2 -#define MPEG_VIDEO_PES_START_CODE 0xe0 -#define MPEG_AUDIO_PES_START_CODE 0xc0 -#define VC1_VIDEO_PES_START_CODE 0xfd -#define AAC_AUDIO_PES_START_CODE 0xcf +#define PCM_PES_START_CODE 0xbd +#define PRIVATE_STREAM_1_PES_START_CODE 0xbd +#define H263_VIDEO_PES_START_CODE 0xfe +#define H264_VIDEO_PES_START_CODE 0xe2 +#define MPEG_VIDEO_PES_START_CODE 0xe0 +#define MPEG_AUDIO_PES_START_CODE 0xc0 +#define VC1_VIDEO_PES_START_CODE 0xfd +#define AAC_AUDIO_PES_START_CODE 0xcf int InsertPesHeader(uint8_t *data, int size, uint8_t stream_id, int64_t pts, int pic_start_code); int InsertVideoPrivateDataHeader(uint8_t *data, int payload_size); diff --git a/libeplayer3-sh4/include/player.h b/libeplayer3-sh4/include/player.h index b675adc..56aaa0b 100644 --- a/libeplayer3-sh4/include/player.h +++ b/libeplayer3-sh4/include/player.h @@ -51,13 +51,14 @@ struct Chapter int64_t end; }; -class Player { - friend class Input; - friend class Output; - friend class Manager; - friend class cPlayback; - friend class WriterPCM; - friend int interrupt_cb(void *arg); +class Player +{ + friend class Input; + friend class Output; + friend class Manager; + friend class cPlayback; + friend class WriterPCM; + friend int interrupt_cb(void *arg); private: Input input; @@ -81,10 +82,10 @@ class Player { uint64_t readCount; std::string url; - bool noprobe; /* hack: only minimal probing in av_find_stream_info */ + bool noprobe; /* hack: only minimal probing in av_find_stream_info */ void SetChapters(std::vector &Chapters); - static void* playthread(void*); + static void *playthread(void *); public: bool SwitchAudio(int pid); bool SwitchVideo(int pid); @@ -115,8 +116,14 @@ class Player { void RequestAbort(); bool GetChapters(std::vector &positions, std::vector &titles); - AVFormatContext *GetAVFormatContext() { return input.GetAVFormatContext(); } - void ReleaseAVFormatContext() { input.ReleaseAVFormatContext(); } + AVFormatContext *GetAVFormatContext() + { + return input.GetAVFormatContext(); + } + void ReleaseAVFormatContext() + { + input.ReleaseAVFormatContext(); + } bool GetPrograms(std::vector &keys, std::vector &values); bool SelectProgram(int key); diff --git a/libeplayer3-sh4/include/writer.h b/libeplayer3-sh4/include/writer.h index 8f13d94..37ade93 100644 --- a/libeplayer3-sh4/include/writer.h +++ b/libeplayer3-sh4/include/writer.h @@ -39,21 +39,21 @@ extern "C" { /* wrapper */ #if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(57,25,100) -static AVCodecParameters __attribute__ ((unused)) *get_codecpar(AVStream *stream) +static AVCodecParameters __attribute__((unused)) *get_codecpar(AVStream *stream) { return stream->codecpar; } #else -static AVCodecContext __attribute__ ((unused)) *get_codecpar(AVStream *stream) +static AVCodecContext __attribute__((unused)) *get_codecpar(AVStream *stream) { return stream->codec; } #endif #if (LIBAVCODEC_VERSION_MAJOR > 55) -#define av_free_packet av_packet_unref +#define av_free_packet av_packet_unref #else -#define av_packet_unref av_free_packet +#define av_packet_unref av_free_packet #endif /* end wrapper */ @@ -71,7 +71,11 @@ class Writer static audio_encoding_t GetAudioEncoding(enum AVCodecID id); static Writer *GetWriter(enum AVCodecID id, enum AVMediaType codec_type, int track_type); - virtual void Init(int _fd, AVStream * /*stream*/, Player *_player ) { fd = _fd; player = _player; } + virtual void Init(int _fd, AVStream * /*stream*/, Player *_player) + { + fd = _fd; + player = _player; + } virtual bool Write(AVPacket *packet, int64_t pts); }; #endif diff --git a/libeplayer3-sh4/input.cpp b/libeplayer3-sh4/input.cpp index 167b451..7de69bd 100644 --- a/libeplayer3-sh4/input.cpp +++ b/libeplayer3-sh4/input.cpp @@ -34,14 +34,14 @@ static const char *FILENAME = "eplayer/input.cpp"; -#define averror(_err,_fun) ({ \ - if (_err < 0) { \ - char _error[512]; \ - av_strerror(_err, _error, sizeof(_error)); \ - fprintf(stderr, "%s %d: %s: %d (%s)\n", FILENAME, __LINE__, #_fun, _err, _error); \ - } \ - _err; \ -}) +#define averror(_err,_fun) ({ \ + if (_err < 0) { \ + char _error[512]; \ + av_strerror(_err, _error, sizeof(_error)); \ + fprintf(stderr, "%s %d: %s: %d (%s)\n", FILENAME, __LINE__, #_fun, _err, _error); \ + } \ + _err; \ + }) Input::Input() { @@ -55,7 +55,7 @@ Input::Input() seek_avts_rel = 0; abortPlayback = false; #if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(57,25,100) - for (int n = 0;n < EPLAYER_MAX_CODECS;n++) + for (int n = 0; n < EPLAYER_MAX_CODECS; n++) codecs[n].codec = NULL; #endif } @@ -64,7 +64,7 @@ Input::~Input() { } -int64_t Input::calcPts(AVStream * stream, int64_t pts) +int64_t Input::calcPts(AVStream *stream, int64_t pts) { if (pts == AV_NOPTS_VALUE) return INVALID_PTS_VALUE; @@ -89,17 +89,20 @@ extern void teletext_write(int pid, uint8_t *data, int size); static std::string lastlog_message; static unsigned int lastlog_repeats; -static void log_callback(void *ptr __attribute__ ((unused)), int lvl __attribute__ ((unused)), const char *format, va_list ap) +static void log_callback(void *ptr __attribute__((unused)), int lvl __attribute__((unused)), const char *format, va_list ap) { char m[1024]; - if (sizeof(m) - 1 > (unsigned int) vsnprintf(m, sizeof(m), format, ap)) { - if (lastlog_message.compare(m) || lastlog_repeats > 999) { + if (sizeof(m) - 1 > (unsigned int) vsnprintf(m, sizeof(m), format, ap)) + { + if (lastlog_message.compare(m) || lastlog_repeats > 999) + { if (lastlog_repeats) fprintf(stderr, "last message repeated %u times\n", lastlog_repeats); lastlog_message = m; lastlog_repeats = 0; fprintf(stderr, "%s", m); - } else + } + else lastlog_repeats++; } } @@ -115,21 +118,25 @@ static void logprintf(const char *format, ...) AVCodecContext *Input::GetCodecContext(unsigned int index) { #if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(57,25,100) - if (codecs[index].codec) { + if (codecs[index].codec) + { return codecs[index].codec; } AVCodec *codec = avcodec_find_decoder(avfc->streams[index]->codecpar->codec_id); codecs[index].codec = avcodec_alloc_context3(codec); - if (!codecs[index].codec) { + if (!codecs[index].codec) + { fprintf(stderr, "context3 alloc for stream %d failed\n", (int)index); return NULL; } - if (avcodec_parameters_to_context(codecs[index].codec, avfc->streams[index]->codecpar) < 0) { + if (avcodec_parameters_to_context(codecs[index].codec, avfc->streams[index]->codecpar) < 0) + { fprintf(stderr, "copy parameters to codec context for stream %d failed\n", (int)index); avcodec_free_context(&codecs[index].codec); return NULL; } - if (!codec) { + if (!codec) + { fprintf(stderr, "decoder for codec_id:(0x%X) stream:(%d) not found\n", avfc->streams[index]->codecpar->codec_id, (int)index);; return codecs[index].codec; } @@ -138,7 +145,8 @@ AVCodecContext *Input::GetCodecContext(unsigned int index) fprintf(stderr, "decoder for codec_id:(0x%X) stream:(%d) found\n", avfc->streams[index]->codecpar->codec_id, (int)index);; } int err = avcodec_open2(codecs[index].codec, codec, NULL); - if (averror(err, avcodec_open2)) { + if (averror(err, avcodec_open2)) + { fprintf(stderr, "open codec context for stream:(%d) failed}n", (int)index); avcodec_free_context(&codecs[index].codec); return NULL; @@ -161,10 +169,12 @@ bool Input::Play() // Oddly, this seems to be necessary for network streaming only ... bool audioSeen = !audioTrack || !player->isHttp; - while (player->isPlaying && !player->abortRequested) { + while (player->isPlaying && !player->abortRequested) + { //IF MOVIE IS PAUSED, WAIT - if (player->isPaused) { + if (player->isPaused) + { fprintf(stderr, "paused\n"); usleep(100000); continue; @@ -173,44 +183,61 @@ bool Input::Play() int seek_target_flag = 0; int64_t seek_target = INT64_MIN; // in AV_TIME_BASE units - if (seek_avts_rel) { - if (avfc->iformat->flags & AVFMT_TS_DISCONT) { - if (avfc->bit_rate) { + if (seek_avts_rel) + { + if (avfc->iformat->flags & AVFMT_TS_DISCONT) + { + if (avfc->bit_rate) + { seek_target_flag = AVSEEK_FLAG_BYTE; seek_target = avio_tell(avfc->pb) + av_rescale(seek_avts_rel, avfc->bit_rate, 8 * AV_TIME_BASE); } - } else { + } + else + { int64_t pts; - if(player->output.GetPts(pts)) + if (player->output.GetPts(pts)) seek_target = av_rescale(pts, AV_TIME_BASE, 90000ll) + seek_avts_rel; } seek_avts_rel = 0; - } else if (seek_avts_abs != INT64_MIN) { - if (avfc->iformat->flags & AVFMT_TS_DISCONT) { - if (avfc->bit_rate) { + } + else if (seek_avts_abs != INT64_MIN) + { + if (avfc->iformat->flags & AVFMT_TS_DISCONT) + { + if (avfc->bit_rate) + { seek_target_flag = AVSEEK_FLAG_BYTE; seek_target = av_rescale(seek_avts_abs, avfc->bit_rate, 8 * AV_TIME_BASE); } - } else { + } + else + { seek_target = seek_avts_abs; } seek_avts_abs = INT64_MIN; - } else if (player->isBackWard && av_gettime_relative() >= showtime) { + } + else if (player->isBackWard && av_gettime_relative() >= showtime) + { player->output.ClearVideo(); - if (bof) { + if (bof) + { showtime = av_gettime_relative(); usleep(100000); continue; } seek_avts_rel = player->Speed * AV_TIME_BASE; - showtime = av_gettime_relative() + 300000; //jump back every 300ms + showtime = av_gettime_relative() + 300000; //jump back every 300ms continue; - } else { + } + else + { bof = false; } - if (seek_target > INT64_MIN) { + if (seek_target > INT64_MIN) + { int res; if (seek_target < 0) seek_target = 0; @@ -223,7 +250,8 @@ bool Input::Play() restart_audio_resampling = true; // clear streams - for (unsigned int i = 0; i < avfc->nb_streams; i++) { + for (unsigned int i = 0; i < avfc->nb_streams; i++) + { AVCodecContext *avcctx = GetCodecContext(i); if (avcctx && avcctx->codec) avcodec_flush_buffers(avcctx); @@ -236,13 +264,15 @@ bool Input::Play() av_init_packet(&packet); int err = av_read_frame(avfc, &packet); - if (err == AVERROR(EAGAIN)) { + if (err == AVERROR(EAGAIN)) + { av_packet_unref(&packet); continue; } - if (averror(err, av_read_frame)) { // EOF? + if (averror(err, av_read_frame)) // EOF? + { av_packet_unref(&packet); - break; // while + break; // while } player->readCount += packet.size; @@ -254,24 +284,32 @@ bool Input::Play() Track *_subtitleTrack = subtitleTrack; Track *_teletextTrack = teletextTrack; - if (_videoTrack && (_videoTrack->stream == stream)) { + if (_videoTrack && (_videoTrack->stream == stream)) + { int64_t pts = calcPts(stream, packet.pts); if (audioSeen && !player->output.Write(stream, &packet, pts)) logprintf("writing data to video device failed\n"); - } else if (_audioTrack && (_audioTrack->stream == stream)) { - if (restart_audio_resampling) { + } + else if (_audioTrack && (_audioTrack->stream == stream)) + { + if (restart_audio_resampling) + { restart_audio_resampling = false; player->output.Write(stream, NULL, 0); } - if (!player->isBackWard) { + if (!player->isBackWard) + { int64_t pts = calcPts(stream, packet.pts); - //if (!player->output.Write(stream, &packet, _videoTrack ? pts : 0)) // DBO: why pts only at video tracks ? + //if (!player->output.Write(stream, &packet, _videoTrack ? pts : 0)) // DBO: why pts only at video tracks ? if (!player->output.Write(stream, &packet, pts)) logprintf("writing data to audio device failed\n"); } audioSeen = true; - } else if (_subtitleTrack && (_subtitleTrack->stream == stream)) { - if (avcctx->codec) { + } + else if (_subtitleTrack && (_subtitleTrack->stream == stream)) + { + if (avcctx->codec) + { AVSubtitle sub; memset(&sub, 0, sizeof(sub)); int got_sub_ptr = 0; @@ -279,13 +317,16 @@ bool Input::Play() err = avcodec_decode_subtitle2(avcctx, &sub, &got_sub_ptr, &packet); averror(err, avcodec_decode_subtitle2); - if (got_sub_ptr && sub.num_rects > 0) { - switch (sub.rects[0]->type) { + if (got_sub_ptr && sub.num_rects > 0) + { + switch (sub.rects[0]->type) + { case SUBTITLE_TEXT: // FIXME? case SUBTITLE_ASS: dvbsub_ass_write(avcctx, &sub, _subtitleTrack->pid); break; - case SUBTITLE_BITMAP: { + case SUBTITLE_BITMAP: + { int64_t pts = calcPts(stream, packet.pts); dvbsub_write(&sub, pts); // avsubtitle_free() will be called by handler @@ -296,7 +337,9 @@ bool Input::Play() } } } - } else if (_teletextTrack && (_teletextTrack->stream == stream)) { + } + else if (_teletextTrack && (_teletextTrack->stream == stream)) + { if (packet.data && packet.size > 1) teletext_write(_teletextTrack->pid, packet.data + 1, packet.size - 1); } @@ -329,7 +372,8 @@ bool Input::Play() #if LIBAVCODEC_VERSION_MAJOR < 58 static int lock_callback(void **mutex, enum AVLockOp op) { - switch (op) { + switch (op) + { case AV_LOCK_CREATE: *mutex = (void *) new OpenThreads::Mutex; return !*mutex; @@ -363,13 +407,15 @@ bool Input::ReadSubtitle(const char *filename, const char *format, int pid) AVFormatContext *subavfc = avformat_alloc_context(); int err = avformat_open_input(&subavfc, subfile, av_find_input_format(format), 0); - if (averror(err, avformat_open_input)) { + if (averror(err, avformat_open_input)) + { avformat_free_context(subavfc); return false; } avformat_find_stream_info(subavfc, NULL); - if (subavfc->nb_streams != 1) { + if (subavfc->nb_streams != 1) + { avformat_free_context(subavfc); return false; } @@ -380,7 +426,8 @@ bool Input::ReadSubtitle(const char *filename, const char *format, int pid) c = subavfc->streams[0]->codec; #else c = avcodec_alloc_context3(codec); - if (avcodec_parameters_to_context(c, subavfc->streams[0]->codecpar) < 0) { + if (avcodec_parameters_to_context(c, subavfc->streams[0]->codecpar) < 0) + { avcodec_free_context(&c); avformat_close_input(&subavfc); avformat_free_context(subavfc); @@ -388,13 +435,15 @@ bool Input::ReadSubtitle(const char *filename, const char *format, int pid) } #endif codec = avcodec_find_decoder(c->codec_id); - if (!codec) { + if (!codec) + { avformat_free_context(subavfc); return false; } err = avcodec_open2(c, codec, NULL); - if (averror(err, avcodec_open2)) { + if (averror(err, avcodec_open2)) + { avformat_free_context(subavfc); return false; } @@ -402,7 +451,8 @@ bool Input::ReadSubtitle(const char *filename, const char *format, int pid) AVPacket packet; av_init_packet(&packet); - while (av_read_frame(subavfc, &packet) > -1) { + while (av_read_frame(subavfc, &packet) > -1) + { AVSubtitle sub; memset(&sub, 0, sizeof(sub)); int got_sub = 0; @@ -426,7 +476,8 @@ bool Input::ReadSubtitle(const char *filename, const char *format, int pid) return true; } -bool Input::ReadSubtitles(const char *filename) { +bool Input::ReadSubtitles(const char *filename) +{ if (strncmp(filename, "file://", 7)) return false; filename += 7; @@ -454,7 +505,8 @@ bool Input::Init(const char *filename, std::string headers) av_log_set_level(AV_LOG_PANIC); #endif - if (!filename) { + if (!filename) + { fprintf(stderr, "filename NULL\n"); return false; } @@ -501,14 +553,16 @@ again: av_log_set_level(AV_LOG_INFO); #endif av_dict_free(&options); - if (averror(err, avformat_open_input)) { + if (averror(err, avformat_open_input)) + { avformat_free_context(avfc); return false; } avfc->iformat->flags |= AVFMT_SEEK_TO_PTS; avfc->flags = AVFMT_FLAG_GENPTS; - if (player->noprobe) { + if (player->noprobe) + { #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(55, 43, 100) || \ LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(57, 25, 0) avfc->max_analyze_duration = 1; @@ -520,7 +574,8 @@ again: #if 0 if (!player->isHttp) { - for (unsigned int i = 0; i < avfc->nb_streams; i++) { + for (unsigned int i = 0; i < avfc->nb_streams; i++) + { if (avfc->streams[i]->codec->codec_id == AV_CODEC_ID_AAC) find_info = false; } @@ -530,9 +585,11 @@ again: err = avformat_find_stream_info(avfc, NULL); #if 0 - if (averror(err, avformat_find_stream_info)) { + if (averror(err, avformat_find_stream_info)) + { avformat_close_input(&avfc); - if (player->noprobe) { + if (player->noprobe) + { player->noprobe = false; goto again; } @@ -542,7 +599,8 @@ again: bool res = UpdateTracks(); - if (!videoTrack && !audioTrack) { + if (!videoTrack && !audioTrack) + { avformat_close_input(&avfc); return false; } @@ -563,9 +621,10 @@ bool Input::UpdateTracks() return true; std::vector chapters; - for (unsigned int i = 0; i < avfc->nb_chapters; i++) { + for (unsigned int i = 0; i < avfc->nb_chapters; i++) + { AVChapter *ch = avfc->chapters[i]; - AVDictionaryEntry* title = av_dict_get(ch->metadata, "title", NULL, 0); + AVDictionaryEntry *title = av_dict_get(ch->metadata, "title", NULL, 0); Chapter chapter; chapter.title = title ? title->value : ""; chapter.start = av_rescale(ch->time_base.num * AV_TIME_BASE, ch->start, ch->time_base.den); @@ -579,7 +638,8 @@ bool Input::UpdateTracks() av_dump_format(avfc, 0, player->url.c_str(), 0); bool use_index_as_pid = false; - for (unsigned int n = 0; n < avfc->nb_streams; n++) { + for (unsigned int n = 0; n < avfc->nb_streams; n++) + { AVStream *stream = avfc->streams[n]; AVCodecContext *avcctx = GetCodecContext(n); @@ -590,7 +650,8 @@ bool Input::UpdateTracks() track.title = lang ? lang->value : ""; if (!use_index_as_pid) - switch (avcctx->codec_type) { + switch (avcctx->codec_type) + { case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_AUDIO: case AVMEDIA_TYPE_SUBTITLE: @@ -600,17 +661,19 @@ bool Input::UpdateTracks() break; } - track.pid = use_index_as_pid ? n + 1: stream->id; + track.pid = use_index_as_pid ? n + 1 : stream->id; track.ac3flags = 0; - switch (avcctx->codec_type) { + switch (avcctx->codec_type) + { case AVMEDIA_TYPE_VIDEO: player->manager.addVideoTrack(track); if (!videoTrack) videoTrack = player->manager.getVideoTrack(track.pid); break; case AVMEDIA_TYPE_AUDIO: - switch(avcctx->codec_id) { + switch (avcctx->codec_id) + { case AV_CODEC_ID_MP2: track.ac3flags = 1; break; @@ -623,12 +686,14 @@ bool Input::UpdateTracks() case AV_CODEC_ID_DTS: track.ac3flags = 4; break; - case AV_CODEC_ID_AAC: { + case AV_CODEC_ID_AAC: + { unsigned int extradata_size = avcctx->extradata_size; unsigned int object_type = 2; - if(extradata_size >= 2) + if (extradata_size >= 2) object_type = avcctx->extradata[0] >> 3; - if (extradata_size <= 1 || object_type == 1 || object_type == 5) { + if (extradata_size <= 1 || object_type == 1 || object_type == 5) + { fprintf(stderr, "use resampling for AAC\n"); track.ac3flags = 6; } @@ -654,24 +719,30 @@ bool Input::UpdateTracks() audioTrack = player->manager.getAudioTrack(track.pid); break; case AVMEDIA_TYPE_SUBTITLE: - if (avcctx->codec_id == AV_CODEC_ID_DVB_TELETEXT) { + if (avcctx->codec_id == AV_CODEC_ID_DVB_TELETEXT) + { std::string l = lang ? lang->value : ""; uint8_t *data = avcctx->extradata; int size = avcctx->extradata_size; if (size > 0 && 2 * size - 1 == (int) l.length()) - for (int i = 0; i < size; i += 2) { + for (int i = 0; i < size; i += 2) + { track.title = l.substr(i * 2, 3); track.type = data[i] >> 3; track.mag = data[i] & 7; track.page = data[i + 1]; player->manager.addTeletextTrack(track); } - } else { - if (!avcctx->codec) { + } + else + { + if (!avcctx->codec) + { avcctx->codec = avcodec_find_decoder(avcctx->codec_id); if (!avcctx->codec) fprintf(stderr, "avcodec_find_decoder failed for subtitle track %d\n", n); - else { + else + { int err = avcodec_open2(avcctx, avcctx->codec, NULL); if (averror(err, avcodec_open2)) avcctx->codec = NULL; @@ -687,9 +758,11 @@ bool Input::UpdateTracks() } } - for (unsigned int n = 0; n < avfc->nb_programs; n++) { + for (unsigned int n = 0; n < avfc->nb_programs; n++) + { AVProgram *p = avfc->programs[n]; - if (p->nb_stream_indexes) { + if (p->nb_stream_indexes) + { AVDictionaryEntry *name = av_dict_get(p->metadata, "name", NULL, 0); Program program; program.title = name ? name->value : ""; @@ -712,9 +785,11 @@ bool Input::Stop() av_log(NULL, AV_LOG_QUIET, "%s", ""); - if (avfc) { + if (avfc) + { OpenThreads::ScopedLock lock(mutex); - for (unsigned int i = 0; i < avfc->nb_streams; i++) { + for (unsigned int i = 0; i < avfc->nb_streams; i++) + { #if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(57,25,100) if (codecs[i].codec) avcodec_free_context(&codecs[i].codec); @@ -756,7 +831,8 @@ bool Input::Seek(int64_t avts, bool absolute) bool Input::GetDuration(int64_t &duration) { - if (avfc) { + if (avfc) + { duration = avfc->duration; return true; } @@ -796,38 +872,45 @@ bool Input::GetMetadata(std::vector &keys, std::vector keys.clear(); values.clear(); - if (avfc) { + if (avfc) + { AVDictionaryEntry *tag = NULL; if (avfc->metadata) - while ((tag = av_dict_get(avfc->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { + while ((tag = av_dict_get(avfc->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) + { keys.push_back(tag->key); values.push_back(tag->value); } if (videoTrack) - while ((tag = av_dict_get(videoTrack->stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { + while ((tag = av_dict_get(videoTrack->stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) + { keys.push_back(tag->key); values.push_back(tag->value); } if (audioTrack) - while ((tag = av_dict_get(audioTrack->stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { + while ((tag = av_dict_get(audioTrack->stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) + { keys.push_back(tag->key); values.push_back(tag->value); } // find the first attached picture, if available - for(unsigned int i = 0; i < avfc->nb_streams; i++) { - if (avfc->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) { - AVPacket *pkt = &avfc->streams[i]->attached_pic; - FILE *cover_art = fopen("/tmp/.id3coverart", "wb"); - if (cover_art) { - fwrite(pkt->data, pkt->size, 1, cover_art); - fclose(cover_art); - } - av_packet_unref(pkt); - break; + for (unsigned int i = 0; i < avfc->nb_streams; i++) + { + if (avfc->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) + { + AVPacket *pkt = &avfc->streams[i]->attached_pic; + FILE *cover_art = fopen("/tmp/.id3coverart", "wb"); + if (cover_art) + { + fwrite(pkt->data, pkt->size, 1, cover_art); + fclose(cover_art); + } + av_packet_unref(pkt); + break; } } } diff --git a/libeplayer3-sh4/manager.cpp b/libeplayer3-sh4/manager.cpp index da39024..80b2a9d 100644 --- a/libeplayer3-sh4/manager.cpp +++ b/libeplayer3-sh4/manager.cpp @@ -23,15 +23,17 @@ #include "manager.h" #include "player.h" -void Manager::addTrack(std::map &tracks, Track &track) +void Manager::addTrack(std::map &tracks, Track &track) { OpenThreads::ScopedLock m_lock(mutex); - std::map::iterator it = tracks.find(track.pid); - if (it == tracks.end()) { + std::map::iterator it = tracks.find(track.pid); + if (it == tracks.end()) + { Track *t = new Track; *t = track; tracks[track.pid] = t; - } else + } + else *it->second = track; } @@ -55,12 +57,12 @@ void Manager::addTeletextTrack(Track &track) addTrack(teletextTracks, track); } -std::vector Manager::getTracks(std::map &tracks) +std::vector Manager::getTracks(std::map &tracks) { player->input.UpdateTracks(); std::vector res; OpenThreads::ScopedLock m_lock(mutex); - for(std::map::iterator it = tracks.begin(); it != tracks.end(); ++it) + for (std::map::iterator it = tracks.begin(); it != tracks.end(); ++it) if (!it->second->inactive && !it->second->hidden) res.push_back(*it->second); return res; @@ -86,10 +88,10 @@ std::vector Manager::getTeletextTracks() return getTracks(teletextTracks); } -Track *Manager::getTrack(std::map &tracks, int pid) +Track *Manager::getTrack(std::map &tracks, int pid) { OpenThreads::ScopedLock m_lock(mutex); - std::map::iterator it = tracks.find(pid); + std::map::iterator it = tracks.find(pid); if (it != tracks.end() && !it->second->inactive) return it->second; return NULL; @@ -118,16 +120,16 @@ bool Manager::initTrackUpdate() { OpenThreads::ScopedLock m_lock(mutex); - for (std::map::iterator it = audioTracks.begin(); it != audioTracks.end(); ++it) + for (std::map::iterator it = audioTracks.begin(); it != audioTracks.end(); ++it) it->second->inactive = !it->second->is_static; - for (std::map::iterator it = videoTracks.begin(); it != videoTracks.end(); ++it) + for (std::map::iterator it = videoTracks.begin(); it != videoTracks.end(); ++it) it->second->inactive = !it->second->is_static; - for (std::map::iterator it = subtitleTracks.begin(); it != subtitleTracks.end(); ++it) + for (std::map::iterator it = subtitleTracks.begin(); it != subtitleTracks.end(); ++it) it->second->inactive = !it->second->is_static; - for (std::map::iterator it = teletextTracks.begin(); it != teletextTracks.end(); ++it) + for (std::map::iterator it = teletextTracks.begin(); it != teletextTracks.end(); ++it) it->second->inactive = !it->second->is_static; return true; @@ -142,7 +144,7 @@ std::vector Manager::getPrograms(void) { OpenThreads::ScopedLock m_lock(mutex); std::vector res; - for (std::map::iterator it = Programs.begin(); it != Programs.end(); ++it) + for (std::map::iterator it = Programs.begin(); it != Programs.end(); ++it) res.push_back(it->second); return res; } @@ -150,81 +152,95 @@ std::vector Manager::getPrograms(void) bool Manager::selectProgram(const int id) { OpenThreads::ScopedLock m_lock(mutex); - std::map::iterator i = Programs.find(id); - if (i != Programs.end()) { + std::map::iterator i = Programs.find(id); + if (i != Programs.end()) + { // mark all tracks as hidden - for (std::map::iterator it = audioTracks.begin(); it != audioTracks.end(); ++it) + for (std::map::iterator it = audioTracks.begin(); it != audioTracks.end(); ++it) it->second->hidden = true; - for (std::map::iterator it = videoTracks.begin(); it != videoTracks.end(); ++it) + for (std::map::iterator it = videoTracks.begin(); it != videoTracks.end(); ++it) it->second->hidden = true; - for (std::map::iterator it = subtitleTracks.begin(); it != subtitleTracks.end(); ++it) + for (std::map::iterator it = subtitleTracks.begin(); it != subtitleTracks.end(); ++it) it->second->hidden = true; - for (std::map::iterator it = teletextTracks.begin(); it != teletextTracks.end(); ++it) + for (std::map::iterator it = teletextTracks.begin(); it != teletextTracks.end(); ++it) it->second->hidden = true; // unhide tracks that are part of the selected program - for (unsigned int j = 0; j < i->second.streams.size(); j++) { + for (unsigned int j = 0; j < i->second.streams.size(); j++) + { AVStream *stream = i->second.streams[j]; bool h = true; - for (std::map::iterator it = audioTracks.begin(); h && (it != audioTracks.end()); ++it) + for (std::map::iterator it = audioTracks.begin(); h && (it != audioTracks.end()); ++it) if (stream == it->second->stream) h = it->second->hidden = false; if (!h) continue; - for (std::map::iterator it = videoTracks.begin(); h && (it != videoTracks.end()); ++it) + for (std::map::iterator it = videoTracks.begin(); h && (it != videoTracks.end()); ++it) if (stream == it->second->stream) h = it->second->hidden = false; if (!h) continue; - for (std::map::iterator it = subtitleTracks.begin(); h && (it != subtitleTracks.end()); ++it) + for (std::map::iterator it = subtitleTracks.begin(); h && (it != subtitleTracks.end()); ++it) if (stream == it->second->stream) h = it->second->hidden = false; if (!h) continue; - for (std::map::iterator it = teletextTracks.begin(); h && (it != teletextTracks.end()); ++it) + for (std::map::iterator it = teletextTracks.begin(); h && (it != teletextTracks.end()); ++it) if (stream == it->second->stream) h = it->second->hidden = false; } // tell ffmpeg what we're interested in - for (std::map::iterator it = audioTracks.begin(); it != audioTracks.end(); ++it) - if (it->second->hidden || it->second->inactive) { + for (std::map::iterator it = audioTracks.begin(); it != audioTracks.end(); ++it) + if (it->second->hidden || it->second->inactive) + { it->second->stream->discard = AVDISCARD_ALL; - } else { + } + else + { it->second->stream->discard = AVDISCARD_NONE; player->input.SwitchAudio(it->second); } - for (std::map::iterator it = videoTracks.begin(); it != videoTracks.end(); ++it) - if (it->second->hidden || it->second->inactive) { + for (std::map::iterator it = videoTracks.begin(); it != videoTracks.end(); ++it) + if (it->second->hidden || it->second->inactive) + { it->second->stream->discard = AVDISCARD_ALL; - } else { + } + else + { it->second->stream->discard = AVDISCARD_NONE; player->input.SwitchVideo(it->second); } - for (std::map::iterator it = subtitleTracks.begin(); it != subtitleTracks.end(); ++it) - if (it->second->hidden || it->second->inactive) { + for (std::map::iterator it = subtitleTracks.begin(); it != subtitleTracks.end(); ++it) + if (it->second->hidden || it->second->inactive) + { it->second->stream->discard = AVDISCARD_ALL; - } else { + } + else + { it->second->stream->discard = AVDISCARD_NONE; player->input.SwitchSubtitle(it->second); } - for (std::map::iterator it = teletextTracks.begin(); it != teletextTracks.end(); ++it) - if (it->second->hidden || it->second->inactive) { + for (std::map::iterator it = teletextTracks.begin(); it != teletextTracks.end(); ++it) + if (it->second->hidden || it->second->inactive) + { it->second->stream->discard = AVDISCARD_ALL; - } else { + } + else + { it->second->stream->discard = AVDISCARD_NONE; player->input.SwitchTeletext(it->second); } @@ -238,19 +254,19 @@ void Manager::clearTracks() { OpenThreads::ScopedLock m_lock(mutex); - for (std::map::iterator it = audioTracks.begin(); it != audioTracks.end(); ++it) + for (std::map::iterator it = audioTracks.begin(); it != audioTracks.end(); ++it) delete it->second; audioTracks.clear(); - for (std::map::iterator it = videoTracks.begin(); it != videoTracks.end(); ++it) + for (std::map::iterator it = videoTracks.begin(); it != videoTracks.end(); ++it) delete it->second; videoTracks.clear(); - for (std::map::iterator it = subtitleTracks.begin(); it != subtitleTracks.end(); ++it) + for (std::map::iterator it = subtitleTracks.begin(); it != subtitleTracks.end(); ++it) delete it->second; subtitleTracks.clear(); - for (std::map::iterator it = teletextTracks.begin(); it != teletextTracks.end(); ++it) + for (std::map::iterator it = teletextTracks.begin(); it != teletextTracks.end(); ++it) delete it->second; teletextTracks.clear(); diff --git a/libeplayer3-sh4/output.cpp b/libeplayer3-sh4/output.cpp index 1d53864..fa214c7 100644 --- a/libeplayer3-sh4/output.cpp +++ b/libeplayer3-sh4/output.cpp @@ -44,12 +44,12 @@ static const char *FILENAME = "eplayer/output.cpp"; -#define dioctl(fd,req,arg) ({ \ - int _r = ioctl(fd,req,arg); \ - if (_r) \ - fprintf(stderr, "%s %d: ioctl '%s' failed: %d (%s)\n", FILENAME, __LINE__, #req, errno, strerror(errno)); \ - _r; \ -}) +#define dioctl(fd,req,arg) ({ \ + int _r = ioctl(fd,req,arg); \ + if (_r) \ + fprintf(stderr, "%s %d: ioctl '%s' failed: %d (%s)\n", FILENAME, __LINE__, #req, errno, strerror(errno)); \ + _r; \ + }) #define VIDEODEV "/dev/dvb/adapter0/video0" #define AUDIODEV "/dev/dvb/adapter0/audio0" @@ -70,7 +70,7 @@ bool Output::Open() { OpenThreads::ScopedLock v_lock(videoMutex); OpenThreads::ScopedLock a_lock(audioMutex); - + if (videofd < 0) videofd = open(VIDEODEV, O_RDWR); @@ -85,7 +85,8 @@ bool Output::Open() if (audiofd < 0) audiofd = open(AUDIODEV, O_RDWR); - if (audiofd < 0) { + if (audiofd < 0) + { close(videofd); videofd = -1; return false; @@ -105,11 +106,13 @@ bool Output::Close() OpenThreads::ScopedLock v_lock(videoMutex); OpenThreads::ScopedLock a_lock(audioMutex); - if (videofd > -1) { + if (videofd > -1) + { close(videofd); videofd = -1; } - if (audiofd > -1) { + if (audiofd > -1) + { close(audiofd); audiofd = -1; } @@ -127,22 +130,24 @@ bool Output::Play() OpenThreads::ScopedLock v_lock(videoMutex); OpenThreads::ScopedLock a_lock(audioMutex); - if (videoTrack && videoTrack->stream && videofd > -1 && get_codecpar(videoTrack->stream)) { + if (videoTrack && videoTrack->stream && videofd > -1 && get_codecpar(videoTrack->stream)) + { videoWriter = Writer::GetWriter(get_codecpar(videoTrack->stream)->codec_id, get_codecpar(videoTrack->stream)->codec_type, videoTrack->ac3flags); videoWriter->Init(videofd, videoTrack->stream, player); if (dioctl(videofd, VIDEO_SET_ENCODING, videoWriter->GetVideoEncoding(get_codecpar(videoTrack->stream)->codec_id)) - || dioctl(videofd, VIDEO_PLAY, NULL)) + || dioctl(videofd, VIDEO_PLAY, NULL)) ret = false; } - if (audioTrack && audioTrack->stream && audiofd > -1 && get_codecpar(audioTrack->stream)) { + if (audioTrack && audioTrack->stream && audiofd > -1 && get_codecpar(audioTrack->stream)) + { audioWriter = Writer::GetWriter(get_codecpar(audioTrack->stream)->codec_id, get_codecpar(audioTrack->stream)->codec_type, audioTrack->ac3flags); audioWriter->Init(audiofd, audioTrack->stream, player); audio_encoding_t audioEncoding = AUDIO_ENCODING_LPCMA; if (audioTrack->ac3flags != 6) audioEncoding = audioWriter->GetAudioEncoding(get_codecpar(audioTrack->stream)->codec_id); if (dioctl(audiofd, AUDIO_SET_ENCODING, audioEncoding) - || dioctl(audiofd, AUDIO_PLAY, NULL)) + || dioctl(audiofd, AUDIO_PLAY, NULL)) ret = false; } return ret; @@ -155,7 +160,8 @@ bool Output::Stop() OpenThreads::ScopedLock v_lock(videoMutex); OpenThreads::ScopedLock a_lock(audioMutex); - if (videofd > -1) { + if (videofd > -1) + { ioctl(videofd, VIDEO_CLEAR_BUFFER, NULL); /* set back to normal speed (end trickmodes) */ dioctl(videofd, VIDEO_SET_SPEED, DVB_SPEED_NORMAL_PLAY); @@ -163,7 +169,8 @@ bool Output::Stop() ret = false; } - if (audiofd > -1) { + if (audiofd > -1) + { ioctl(audiofd, AUDIO_CLEAR_BUFFER, NULL); /* set back to normal speed (end trickmodes) */ dioctl(audiofd, AUDIO_SET_SPEED, DVB_SPEED_NORMAL_PLAY); @@ -181,12 +188,14 @@ bool Output::Pause() OpenThreads::ScopedLock v_lock(videoMutex); OpenThreads::ScopedLock a_lock(audioMutex); - if (videofd > -1) { + if (videofd > -1) + { if (dioctl(videofd, VIDEO_FREEZE, NULL)) ret = false; } - if (audiofd > -1) { + if (audiofd > -1) + { if (dioctl(audiofd, AUDIO_PAUSE, NULL)) ret = false; } @@ -228,7 +237,8 @@ bool Output::Flush() if (videofd > -1 && ioctl(videofd, VIDEO_FLUSH, NULL)) ret = false; - if (audiofd > -1 && audioWriter) { + if (audiofd > -1 && audioWriter) + { // flush audio decoder AVPacket packet; packet.data = NULL; @@ -283,7 +293,7 @@ bool Output::GetPts(int64_t &pts) { pts = 0; return ((videofd > -1 && !ioctl(videofd, VIDEO_GET_PTS, (void *) &pts)) || - (audiofd > -1 && !ioctl(audiofd, AUDIO_GET_PTS, (void *) &pts))); + (audiofd > -1 && !ioctl(audiofd, AUDIO_GET_PTS, (void *) &pts))); } bool Output::GetFrameCount(int64_t &framecount) @@ -291,7 +301,8 @@ bool Output::GetFrameCount(int64_t &framecount) dvb_play_info_t playInfo; if ((videofd > -1 && !dioctl(videofd, VIDEO_GET_PLAY_INFO, (void *) &playInfo)) || - (audiofd > -1 && !dioctl(audiofd, AUDIO_GET_PLAY_INFO, (void *) &playInfo))) { + (audiofd > -1 && !dioctl(audiofd, AUDIO_GET_PLAY_INFO, (void *) &playInfo))) + { framecount = playInfo.frame_count; return true; } @@ -303,20 +314,23 @@ bool Output::SwitchAudio(Track *track) OpenThreads::ScopedLock a_lock(audioMutex); if (audioTrack && track->stream == audioTrack->stream) return true; - if (audiofd > -1) { + if (audiofd > -1) + { dioctl(audiofd, AUDIO_STOP, NULL); ioctl(audiofd, AUDIO_CLEAR_BUFFER, NULL); } audioTrack = track; - if (track->stream) { + if (track->stream) + { if (!get_codecpar(audioTrack->stream)) return false; - audioWriter = Writer::GetWriter(get_codecpar(audioTrack->stream)->codec_id, get_codecpar(audioTrack->stream)->codec_type, audioTrack->ac3flags); - audioWriter->Init(audiofd, audioTrack->stream, player); - if (audiofd > -1) { + audioWriter = Writer::GetWriter(get_codecpar(audioTrack->stream)->codec_id, get_codecpar(audioTrack->stream)->codec_type, audioTrack->ac3flags); + audioWriter->Init(audiofd, audioTrack->stream, player); + if (audiofd > -1) + { audio_encoding_t audioEncoding = AUDIO_ENCODING_LPCMA; - if (audioTrack->ac3flags != 6) - audioEncoding = Writer::GetAudioEncoding(get_codecpar(audioTrack->stream)->codec_id); + if (audioTrack->ac3flags != 6) + audioEncoding = Writer::GetAudioEncoding(get_codecpar(audioTrack->stream)->codec_id); dioctl(audiofd, AUDIO_SET_ENCODING, audioEncoding); dioctl(audiofd, AUDIO_PLAY, NULL); } @@ -329,17 +343,20 @@ bool Output::SwitchVideo(Track *track) OpenThreads::ScopedLock v_lock(videoMutex); if (videoTrack && track->stream == videoTrack->stream) return true; - if (videofd > -1) { + if (videofd > -1) + { dioctl(videofd, VIDEO_STOP, NULL); ioctl(videofd, VIDEO_CLEAR_BUFFER, NULL); } videoTrack = track; - if (track->stream) { + if (track->stream) + { if (!get_codecpar(videoTrack->stream)) return false; videoWriter = Writer::GetWriter(get_codecpar(videoTrack->stream)->codec_id, get_codecpar(videoTrack->stream)->codec_type, videoTrack->type); videoWriter->Init(videofd, videoTrack->stream, player); - if (videofd > -1) { + if (videofd > -1) + { dioctl(videofd, VIDEO_SET_ENCODING, Writer::GetVideoEncoding(get_codecpar(videoTrack->stream)->codec_id)); dioctl(videofd, VIDEO_PLAY, NULL); } @@ -349,12 +366,15 @@ bool Output::SwitchVideo(Track *track) bool Output::Write(AVStream *stream, AVPacket *packet, int64_t pts) { - switch (get_codecpar(stream)->codec_type) { - case AVMEDIA_TYPE_VIDEO: { + switch (get_codecpar(stream)->codec_type) + { + case AVMEDIA_TYPE_VIDEO: + { OpenThreads::ScopedLock v_lock(videoMutex); return videofd > -1 && videoWriter && videoWriter->Write(packet, pts); } - case AVMEDIA_TYPE_AUDIO: { + case AVMEDIA_TYPE_AUDIO: + { OpenThreads::ScopedLock a_lock(audioMutex); return audiofd > -1 && audioWriter && audioWriter->Write(packet, pts); } diff --git a/libeplayer3-sh4/player.cpp b/libeplayer3-sh4/player.cpp index 9444afb..ee3d32e 100644 --- a/libeplayer3-sh4/player.cpp +++ b/libeplayer3-sh4/player.cpp @@ -32,8 +32,8 @@ static const char *FILENAME = "eplayer/player.cpp"; -#define cMaxSpeed_ff 128 /* fixme: revise */ -#define cMaxSpeed_fr -320 /* fixme: revise */ +#define cMaxSpeed_ff 128 /* fixme: revise */ +#define cMaxSpeed_fr -320 /* fixme: revise */ Player::Player() { @@ -75,16 +75,23 @@ bool Player::Open(const char *Url, bool _noprobe, std::string headers) manager.clearTracks(); - if (!strncmp("mms://", Url, 6)) { + if (!strncmp("mms://", Url, 6)) + { url = "mmst"; url += Url + 3; isHttp = true; - } else if (strstr(Url, "://")) { + } + else if (strstr(Url, "://")) + { url = Url; isHttp = strncmp("file://", Url, 7); - } else if (!strncmp(Url, "bluray:/", 8)) { + } + else if (!strncmp(Url, "bluray:/", 8)) + { url = Url; - } else { + } + else + { fprintf(stderr, "%s %s %d: Unknown stream (%s)\n", FILENAME, __func__, __LINE__, Url); return false; } @@ -109,37 +116,46 @@ bool Player::Play() { bool ret = true; - if (!isPlaying) { + if (!isPlaying) + { output.AVSync(true); ret = output.Play(); - if (ret) { + if (ret) + { isPlaying = true; isPaused = false; isForwarding = false; - if (isBackWard) { + if (isBackWard) + { isBackWard = false; output.Mute(false); } isSlowMotion = false; Speed = 1; - if (!hasThreadStarted) { + if (!hasThreadStarted) + { int err = pthread_create(&playThread, NULL, playthread, this); - if (err) { + if (err) + { fprintf(stderr, "%s %s %d: pthread_create: %d (%s)\n", FILENAME, __func__, __LINE__, err, strerror(err)); ret = false; isPlaying = false; - } else { + } + else + { pthread_detach(playThread); } } } - } else { - fprintf(stderr,"playback already running\n"); + } + else + { + fprintf(stderr, "playback already running\n"); ret = false; } return ret; @@ -149,7 +165,8 @@ bool Player::Pause() { bool ret = true; - if (isPlaying && !isPaused) { + if (isPlaying && !isPaused) + { if (isSlowMotion) output.Clear(); @@ -159,14 +176,17 @@ bool Player::Pause() isPaused = true; //isPlaying = 1; isForwarding = false; - if (isBackWard) { + if (isBackWard) + { isBackWard = false; output.Mute(false); } isSlowMotion = false; Speed = 1; - } else { - fprintf(stderr,"playback not playing or already in pause mode\n"); + } + else + { + fprintf(stderr, "playback not playing or already in pause mode\n"); ret = false; } return ret; @@ -176,7 +196,8 @@ bool Player::Continue() { int ret = true; - if (isPlaying && (isPaused || isForwarding || isBackWard || isSlowMotion)) { + if (isPlaying && (isPaused || isForwarding || isBackWard || isSlowMotion)) + { if (isSlowMotion) output.Clear(); @@ -186,14 +207,17 @@ bool Player::Continue() isPaused = false; //isPlaying = 1; isForwarding = false; - if (isBackWard) { + if (isBackWard) + { isBackWard = false; output.Mute(false); } isSlowMotion = false; Speed = 1; - } else { - fprintf(stderr,"continue not possible\n"); + } + else + { + fprintf(stderr, "continue not possible\n"); ret = false; } @@ -204,11 +228,13 @@ bool Player::Stop() { bool ret = true; - if (isPlaying) { + if (isPlaying) + { isPaused = false; isPlaying = false; isForwarding = false; - if (isBackWard) { + if (isBackWard) + { isBackWard = false; output.Mute(false); } @@ -218,8 +244,10 @@ bool Player::Stop() output.Stop(); input.Stop(); - } else { - fprintf(stderr,"stop not possible\n"); + } + else + { + fprintf(stderr, "stop not possible\n"); ret = false; } @@ -234,9 +262,11 @@ bool Player::FastForward(int speed) int ret = true; /* Audio only forwarding not supported */ - if (input.videoTrack && !isHttp && !isBackWard && (!isPaused || isPlaying)) { + if (input.videoTrack && !isHttp && !isBackWard && (!isPaused || isPlaying)) + { - if ((speed <= 0) || (speed > cMaxSpeed_ff)) { + if ((speed <= 0) || (speed > cMaxSpeed_ff)) + { fprintf(stderr, "speed %d out of range (1 - %d) \n", speed, cMaxSpeed_ff); return false; } @@ -244,8 +274,10 @@ bool Player::FastForward(int speed) isForwarding = 1; Speed = speed; output.FastForward(speed); - } else { - fprintf(stderr,"fast forward not possible\n"); + } + else + { + fprintf(stderr, "fast forward not possible\n"); ret = false; } @@ -257,32 +289,40 @@ bool Player::FastBackward(int speed) bool ret = true; /* Audio only reverse play not supported */ - if (input.videoTrack && !isForwarding && (!isPaused || isPlaying)) { + if (input.videoTrack && !isForwarding && (!isPaused || isPlaying)) + { - if ((speed > 0) || (speed < cMaxSpeed_fr)) { + if ((speed > 0) || (speed < cMaxSpeed_fr)) + { fprintf(stderr, "speed %d out of range (0 - %d) \n", speed, cMaxSpeed_fr); return false; } - if (speed == 0) { + if (speed == 0) + { isBackWard = false; - Speed = 0; /* reverse end */ - } else { + Speed = 0; /* reverse end */ + } + else + { Speed = speed; isBackWard = true; } output.Clear(); #if 0 - if (output->Command(player, OUTPUT_REVERSE, NULL) < 0) { - fprintf(stderr,"OUTPUT_REVERSE failed\n"); + if (output->Command(player, OUTPUT_REVERSE, NULL) < 0) + { + fprintf(stderr, "OUTPUT_REVERSE failed\n"); isBackWard = false; Speed = 1; ret = false; } #endif - } else { - fprintf(stderr,"fast backward not possible\n"); + } + else + { + fprintf(stderr, "fast backward not possible\n"); ret = false; } @@ -294,11 +334,13 @@ bool Player::FastBackward(int speed) bool Player::SlowMotion(int repeats) { - if (input.videoTrack && !isHttp && isPlaying) { + if (input.videoTrack && !isHttp && isPlaying) + { if (isPaused) Continue(); - switch (repeats) { + switch (repeats) + { case 2: case 4: case 8: @@ -318,7 +360,7 @@ bool Player::SlowMotion(int repeats) bool Player::Seek(int64_t pos, bool absolute) { if (GetVideoPid()) - /* Don't Clear if no video track */ + /* Don't Clear if no video track */ output.Clear(); return input.Seek(pos, absolute); } @@ -375,8 +417,9 @@ bool Player::GetChapters(std::vector &positions, std::vector & titles.clear(); input.UpdateTracks(); OpenThreads::ScopedLock m_lock(chapterMutex); - for (std::vector::iterator it = chapters.begin(); it != chapters.end(); ++it) { - positions.push_back(it->start/1000); + for (std::vector::iterator it = chapters.begin(); it != chapters.end(); ++it) + { + positions.push_back(it->start / 1000); titles.push_back(it->title); } return true; @@ -427,7 +470,8 @@ bool Player::GetPrograms(std::vector &keys, std::vector::iterator it = p.begin(); it != p.end(); ++it) { + for (std::vector::iterator it = p.begin(); it != p.end(); ++it) + { std::stringstream s; s << it->id; keys.push_back(s.str()); diff --git a/libeplayer3-sh4/writer/aac.cpp b/libeplayer3-sh4/writer/aac.cpp index a92fd98..c827561 100644 --- a/libeplayer3-sh4/writer/aac.cpp +++ b/libeplayer3-sh4/writer/aac.cpp @@ -41,7 +41,8 @@ static inline void Hexdump(unsigned char *Data, int length) { int k; - for (k = 0; k < length; k++) { + for (k = 0; k < length; k++) + { printf("%02x ", Data[k]); if (((k + 1) & 31) == 0) printf("\n"); @@ -84,7 +85,7 @@ static inline int aac_get_sample_rate_index(uint32_t sample_rate) } #if 0 -static unsigned char DefaultAACHeader[] = {0xff,0xf1,0x50,0x80,0x00,0x1f,0xfc}; +static unsigned char DefaultAACHeader[] = {0xff, 0xf1, 0x50, 0x80, 0x00, 0x1f, 0xfc}; #endif class WriterAAC : public Writer @@ -109,7 +110,7 @@ void WriterAAC::Init(int _fd, AVStream *_stream, Player *_player) printf("stream->codec->extradata_size %d\n", stream->codec->extradata_size); Hexdump(stream->codec->extradata, stream->codec->extradata_size); #endif - unsigned int object_type = 2; // LC + unsigned int object_type = 2; // LC unsigned int sample_index = aac_get_sample_rate_index(stream->codec->sample_rate); unsigned int chan_config = stream->codec->channels; if (stream->codec->extradata_size >= 2) @@ -123,7 +124,7 @@ void WriterAAC::Init(int _fd, AVStream *_stream, Player *_player) printf("aac sample_index %d\n", sample_index); printf("aac chan_config %d\n", chan_config); #endif - object_type -= 1; // Cause of ADTS + object_type -= 1; // Cause of ADTS aacbuflen = AAC_HEADER_LENGTH; aacbuf[0] = 0xFF; aacbuf[1] = 0xF1; @@ -147,7 +148,7 @@ bool WriterAAC::Write(AVPacket *packet, int64_t pts) uint8_t PesHeader[PES_MAX_HEADER_SIZE]; uint8_t ExtraData[AAC_HEADER_LENGTH]; - for (int pos = 0; pos < packet->size + AAC_HEADER_LENGTH; ) + for (int pos = 0; pos < packet->size + AAC_HEADER_LENGTH;) { int PacketLength = std::min(packet->size - pos + AAC_HEADER_LENGTH, MAX_PES_PACKET_SIZE); @@ -182,4 +183,4 @@ WriterAAC::WriterAAC() Register(this, AV_CODEC_ID_AAC, AUDIO_ENCODING_AAC); } -static WriterAAC writer_aac __attribute__ ((init_priority (300))); +static WriterAAC writer_aac __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/ac3.cpp b/libeplayer3-sh4/writer/ac3.cpp index d1a32ba..31c2cb9 100644 --- a/libeplayer3-sh4/writer/ac3.cpp +++ b/libeplayer3-sh4/writer/ac3.cpp @@ -46,7 +46,8 @@ bool WriterAC3::Write(AVPacket *packet, int64_t pts) uint8_t PesHeader[PES_MAX_HEADER_SIZE]; - for (int pos = 0; pos < packet->size; ) { + for (int pos = 0; pos < packet->size;) + { int PacketLength = std::min(packet->size - pos, MAX_PES_PACKET_SIZE); struct iovec iov[2]; iov[0].iov_base = PesHeader; @@ -69,4 +70,4 @@ WriterAC3::WriterAC3() Register(this, AV_CODEC_ID_EAC3, AUDIO_ENCODING_AC3); } -static WriterAC3 writer_ac3 __attribute__ ((init_priority (300))); +static WriterAC3 writer_ac3 __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/divx.cpp b/libeplayer3-sh4/writer/divx.cpp index f3a2bbd..afe49e7 100644 --- a/libeplayer3-sh4/writer/divx.cpp +++ b/libeplayer3-sh4/writer/divx.cpp @@ -58,7 +58,7 @@ bool WriterDIVX::Write(AVPacket *packet, int64_t pts) return false; uint8_t PesHeader[PES_MAX_HEADER_SIZE]; - uint8_t FakeHeaders[64] = { 0 }; // 64bytes should be enough to make the fake headers + uint8_t FakeHeaders[64] = { 0 }; // 64bytes should be enough to make the fake headers unsigned int FakeHeaderLength; uint8_t Version = 5; unsigned int FakeStartCode = (Version << 8) | PES_VERSION_FAKE_START_CODE; @@ -72,10 +72,10 @@ bool WriterDIVX::Write(AVPacket *packet, int64_t pts) PutBits(&ld, 0x0, 8); PutBits(&ld, 0x0, 8); */ - PutBits(&ld, 0x1b0, 32); // startcode - PutBits(&ld, 0, 8); // profile = reserved - PutBits(&ld, 0x1b2, 32); // startcode (user data) - PutBits(&ld, 0x53545443, 32); // STTC - an embedded ST timecode from an avi file + PutBits(&ld, 0x1b0, 32); // startcode + PutBits(&ld, 0, 8); // profile = reserved + PutBits(&ld, 0x1b2, 32); // startcode (user data) + PutBits(&ld, 0x53545443, 32); // STTC - an embedded ST timecode from an avi file PutBits(&ld, usecPerFrame, 32); // microseconds per frame FlushBits(&ld); @@ -88,7 +88,8 @@ bool WriterDIVX::Write(AVPacket *packet, int64_t pts) iov[ic].iov_base = FakeHeaders; iov[ic++].iov_len = FakeHeaderLength; - if (initialHeader) { + if (initialHeader) + { iov[ic].iov_base = get_codecpar(stream)->extradata; iov[ic++].iov_len = get_codecpar(stream)->extradata_size; initialHeader = false; @@ -107,4 +108,4 @@ WriterDIVX::WriterDIVX() Register(this, AV_CODEC_ID_MSMPEG4V3, VIDEO_ENCODING_MPEG4P2); } -static WriterDIVX writer_divx __attribute__ ((init_priority (300))); +static WriterDIVX writer_divx __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/dts.cpp b/libeplayer3-sh4/writer/dts.cpp index 11125bb..e824f8d 100644 --- a/libeplayer3-sh4/writer/dts.cpp +++ b/libeplayer3-sh4/writer/dts.cpp @@ -30,8 +30,8 @@ #include "pes.h" #include "writer.h" -#define PES_AUDIO_PRIVATE_HEADER_SIZE 16 // consider maximum private header size. -#define PES_AUDIO_HEADER_SIZE (32 + PES_AUDIO_PRIVATE_HEADER_SIZE) +#define PES_AUDIO_PRIVATE_HEADER_SIZE 16 // consider maximum private header size. +#define PES_AUDIO_HEADER_SIZE (32 + PES_AUDIO_PRIVATE_HEADER_SIZE) class WriterDTS : public Writer { @@ -53,7 +53,8 @@ bool WriterDTS::Write(AVPacket *packet, int64_t pts) memcpy(Data, packet->data, packet->size); /* 16-bit byte swap all data before injecting it */ - for (i = 0; i < packet->size; i += 2) { + for (i = 0; i < packet->size; i += 2) + { uint8_t Tmp = Data[i]; Data[i] = Data[i + 1]; Data[i + 1] = Tmp; @@ -63,7 +64,7 @@ bool WriterDTS::Write(AVPacket *packet, int64_t pts) struct iovec iov[2]; iov[0].iov_base = PesHeader; - iov[0].iov_len = InsertPesHeader(PesHeader, packet->size, MPEG_AUDIO_PES_START_CODE /*PRIVATE_STREAM_1_PES_START_CODE */ , pts, 0); + iov[0].iov_len = InsertPesHeader(PesHeader, packet->size, MPEG_AUDIO_PES_START_CODE /*PRIVATE_STREAM_1_PES_START_CODE */, pts, 0); #ifdef DO_BYTESPWAP iov[1].iov_base = Data; #else @@ -79,4 +80,4 @@ WriterDTS::WriterDTS() Register(this, AV_CODEC_ID_DTS, AUDIO_ENCODING_DTS); } -static WriterDTS writer_dts __attribute__ ((init_priority (300))); +static WriterDTS writer_dts __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/h263.cpp b/libeplayer3-sh4/writer/h263.cpp index 7243e6c..fb09e99 100644 --- a/libeplayer3-sh4/writer/h263.cpp +++ b/libeplayer3-sh4/writer/h263.cpp @@ -71,4 +71,4 @@ WriterH263::WriterH263() Register(this, AV_CODEC_ID_FLV1, VIDEO_ENCODING_FLV1); } -static WriterH263 writer_h263 __attribute__ ((init_priority (300))); +static WriterH263 writer_h263 __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/h264.cpp b/libeplayer3-sh4/writer/h264.cpp index e2c3183..4bdd200 100644 --- a/libeplayer3-sh4/writer/h264.cpp +++ b/libeplayer3-sh4/writer/h264.cpp @@ -30,17 +30,18 @@ #include "pes.h" #include "writer.h" -#define NALU_TYPE_PLAYER2_CONTAINER_PARAMETERS 24 // Reference: player/standards/h264.h -#define CONTAINER_PARAMETERS_VERSION 0x00 +#define NALU_TYPE_PLAYER2_CONTAINER_PARAMETERS 24 // Reference: player/standards/h264.h +#define CONTAINER_PARAMETERS_VERSION 0x00 -typedef struct avcC_s { - uint8_t Version; // configurationVersion - uint8_t Profile; // AVCProfileIndication - uint8_t Compatibility; // profile_compatibility - uint8_t Level; // AVCLevelIndication - uint8_t NalLengthMinusOne; // held in bottom two bits - uint8_t NumParamSets; // held in bottom 5 bits - uint8_t Params[1]; // {length,params}{length,params}...sequence then picture +typedef struct avcC_s +{ + uint8_t Version; // configurationVersion + uint8_t Profile; // AVCProfileIndication + uint8_t Compatibility; // profile_compatibility + uint8_t Level; // AVCLevelIndication + uint8_t NalLengthMinusOne; // held in bottom two bits + uint8_t NumParamSets; // held in bottom 5 bits + uint8_t Params[1]; // {length,params}{length,params}...sequence then picture } avcC_t; class WriterH264 : public Writer @@ -74,14 +75,16 @@ bool WriterH264::Write(AVPacket *packet, int64_t pts) uint8_t *d = packet->data; // byte-stream format - if ((packet->size > 3) && ( (d[0] == 0x00 && d[1] == 0x00 && d[2] == 0x00 && d[3] == 0x01) // first NAL unit - || (d[0] == 0xff && d[1] == 0xff && d[2] == 0xff && d[3] == 0xff) // FIXME, needed??? - )) { + if ((packet->size > 3) && ((d[0] == 0x00 && d[1] == 0x00 && d[2] == 0x00 && d[3] == 0x01) // first NAL unit + || (d[0] == 0xff && d[1] == 0xff && d[2] == 0xff && d[3] == 0xff) // FIXME, needed??? + )) + { unsigned int FakeStartCode = /* (call->Version << 8) | */ PES_VERSION_FAKE_START_CODE; int ic = 0; iov[ic++].iov_base = PesHeader; unsigned int len = 0; - if (initialHeader) { + if (initialHeader) + { initialHeader = false; iov[ic].iov_base = get_codecpar(stream)->extradata; iov[ic++].iov_len = get_codecpar(stream)->extradata_size; @@ -103,10 +106,12 @@ bool WriterH264::Write(AVPacket *packet, int64_t pts) } // convert NAL units without sync byte sequence to byte-stream format - if (initialHeader) { + if (initialHeader) + { avcC_t *avcCHeader = (avcC_t *) get_codecpar(stream)->extradata; - if (!avcCHeader) { + if (!avcCHeader) + { fprintf(stderr, "stream->codec->extradata == NULL\n"); return false; } @@ -122,35 +127,35 @@ bool WriterH264::Write(AVPacket *packet, int64_t pts) uint8_t Header[20]; unsigned int len = 0; - Header[len++] = 0x00; // Start code, 00 00 00 01 for first NAL unit + Header[len++] = 0x00; // Start code, 00 00 00 01 for first NAL unit Header[len++] = 0x00; Header[len++] = 0x00; Header[len++] = 0x01; Header[len++] = NALU_TYPE_PLAYER2_CONTAINER_PARAMETERS; // NAL unit header // Container message version - changes when/if we vary the format of the message Header[len++] = CONTAINER_PARAMETERS_VERSION; - Header[len++] = 0xff; // marker bits + Header[len++] = 0xff; // marker bits - #if 0 +#if 0 if (FrameRate == 0xffffffff) FrameRate = (TimeScale > 1000) ? 1001 : 1; - #endif +#endif - Header[len++] = (TimeScale >> 24) & 0xff; // Output the timescale + Header[len++] = (TimeScale >> 24) & 0xff; // Output the timescale Header[len++] = (TimeScale >> 16) & 0xff; - Header[len++] = 0xff; // marker bits + Header[len++] = 0xff; // marker bits Header[len++] = (TimeScale >> 8) & 0xff; - Header[len++] = (TimeScale ) & 0xff; - Header[len++] = 0xff; // marker bits + Header[len++] = (TimeScale) & 0xff; + Header[len++] = 0xff; // marker bits - Header[len++] = (FrameRate >> 24) & 0xff; // Output frame period (should be: time delta) + Header[len++] = (FrameRate >> 24) & 0xff; // Output frame period (should be: time delta) Header[len++] = (FrameRate >> 16) & 0xff; - Header[len++] = 0xff; // marker bits + Header[len++] = 0xff; // marker bits Header[len++] = (FrameRate >> 8) & 0xff; - Header[len++] = (FrameRate ) & 0xff; - Header[len++] = 0xff; // marker bits + Header[len++] = (FrameRate) & 0xff; + Header[len++] = 0xff; // marker bits - Header[len++] = 0x80; // Rsbp trailing bits + Header[len++] = 0x80; // Rsbp trailing bits int ic = 0; iov[ic].iov_base = PesHeader; @@ -169,7 +174,8 @@ bool WriterH264::Write(AVPacket *packet, int64_t pts) // sequence parameter set unsigned int ParamSets = avcCHeader->NumParamSets & 0x1f; - for (unsigned int i = 0; i < ParamSets; i++) { + for (unsigned int i = 0; i < ParamSets; i++) + { unsigned int PsLength = (avcCHeader->Params[ParamOffset] << 8) | avcCHeader->Params[ParamOffset + 1]; iov[ic].iov_base = (uint8_t *) "\0\0\0\1"; @@ -184,7 +190,8 @@ bool WriterH264::Write(AVPacket *packet, int64_t pts) // picture parameter set ParamSets = avcCHeader->Params[ParamOffset++]; - for (unsigned int i = 0; i < ParamSets; i++) { + for (unsigned int i = 0; i < ParamSets; i++) + { unsigned int PsLength = (avcCHeader->Params[ParamOffset] << 8) | avcCHeader->Params[ParamOffset + 1]; iov[ic].iov_base = (uint8_t *) "\0\0\0\1"; @@ -205,9 +212,11 @@ bool WriterH264::Write(AVPacket *packet, int64_t pts) } uint8_t *de = d + packet->size; - do { + do + { unsigned int len = 0; - switch (NalLengthBytes) { + switch (NalLengthBytes) + { case 4: len = *d; d++; @@ -225,8 +234,9 @@ bool WriterH264::Write(AVPacket *packet, int64_t pts) d++; } - if (d + len > de) { - fprintf(stderr, "NAL length past end of buffer - size %u frame offset %d left %d\n", len, (int) (d - packet->data), (int) (de - d)); + if (d + len > de) + { + fprintf(stderr, "NAL length past end of buffer - size %u frame offset %d left %d\n", len, (int)(d - packet->data), (int)(de - d)); break; } @@ -245,7 +255,8 @@ bool WriterH264::Write(AVPacket *packet, int64_t pts) d += len; pts = INVALID_PTS_VALUE; - } while (d < de); + } + while (d < de); return true; } @@ -255,4 +266,4 @@ WriterH264::WriterH264() Register(this, AV_CODEC_ID_H264, VIDEO_ENCODING_H264); } -static WriterH264 writerh264 __attribute__ ((init_priority (300))); +static WriterH264 writerh264 __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/misc.cpp b/libeplayer3-sh4/writer/misc.cpp index c63e659..ff58a0f 100644 --- a/libeplayer3-sh4/writer/misc.cpp +++ b/libeplayer3-sh4/writer/misc.cpp @@ -28,7 +28,7 @@ #include "misc.h" -void PutBits(BitPacker_t * ld, unsigned int code, unsigned int length) +void PutBits(BitPacker_t *ld, unsigned int code, unsigned int length) { unsigned int bit_buf; unsigned int bit_left; @@ -39,20 +39,23 @@ void PutBits(BitPacker_t * ld, unsigned int code, unsigned int length) #ifdef DEBUG_PUTBITS if (ld->debug) dprintf("code = %d, length = %d, bit_buf = 0x%x, bit_left = %d\n", - code, length, bit_buf, bit_left); + code, length, bit_buf, bit_left); #endif - if (length < bit_left) { + if (length < bit_left) + { /* fits into current buffer */ bit_buf = (bit_buf << length) | code; bit_left -= length; - } else { + } + else + { /* doesn't fit */ bit_buf <<= bit_left; bit_buf |= code >> (length - bit_left); - ld->Ptr[0] = (uint8_t) (bit_buf >> 24); - ld->Ptr[1] = (uint8_t) (bit_buf >> 16); - ld->Ptr[2] = (uint8_t) (bit_buf >> 8); + ld->Ptr[0] = (uint8_t)(bit_buf >> 24); + ld->Ptr[1] = (uint8_t)(bit_buf >> 16); + ld->Ptr[2] = (uint8_t)(bit_buf >> 8); ld->Ptr[3] = (uint8_t) bit_buf; ld->Ptr += 4; length -= bit_left; @@ -71,10 +74,11 @@ void PutBits(BitPacker_t * ld, unsigned int code, unsigned int length) ld->Remaining = bit_left; } -void FlushBits(BitPacker_t * ld) +void FlushBits(BitPacker_t *ld) { ld->BitBuffer <<= ld->Remaining; - while (ld->Remaining < 32) { + while (ld->Remaining < 32) + { #ifdef DEBUG_PUTBITS if (ld->debug) dprintf("flushing 0x%2.2x\n", ld->BitBuffer >> 24); diff --git a/libeplayer3-sh4/writer/mp3.cpp b/libeplayer3-sh4/writer/mp3.cpp index c71af94..ca62620 100644 --- a/libeplayer3-sh4/writer/mp3.cpp +++ b/libeplayer3-sh4/writer/mp3.cpp @@ -46,7 +46,8 @@ bool WriterMP3::Write(AVPacket *packet, int64_t pts) uint8_t PesHeader[PES_MAX_HEADER_SIZE]; - for (int pos = 0; pos < packet->size; ) { + for (int pos = 0; pos < packet->size;) + { int PacketLength = std::min(packet->size - pos, MAX_PES_PACKET_SIZE); struct iovec iov[2]; iov[0].iov_base = PesHeader; @@ -71,4 +72,4 @@ WriterMP3::WriterMP3() Register(this, AV_CODEC_ID_FLAC, AUDIO_ENCODING_LPCM); } -static WriterMP3 writer_mp3 __attribute__ ((init_priority (300))); +static WriterMP3 writer_mp3 __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/mpeg2.cpp b/libeplayer3-sh4/writer/mpeg2.cpp index f7cbb8f..ba13ff3 100644 --- a/libeplayer3-sh4/writer/mpeg2.cpp +++ b/libeplayer3-sh4/writer/mpeg2.cpp @@ -46,7 +46,8 @@ bool WriterMPEG2::Write(AVPacket *packet, int64_t pts) uint8_t PesHeader[PES_MAX_HEADER_SIZE]; - for (int pos = 0; pos < packet->size; ) { + for (int pos = 0; pos < packet->size;) + { int PacketLength = std::min(packet->size - pos, MAX_PES_PACKET_SIZE); struct iovec iov[2]; iov[0].iov_base = PesHeader; @@ -68,4 +69,4 @@ WriterMPEG2::WriterMPEG2() Register(this, AV_CODEC_ID_MPEG2TS, VIDEO_ENCODING_AUTO); } -static WriterMPEG2 writer_mpeg2 __attribute__ ((init_priority (300))); +static WriterMPEG2 writer_mpeg2 __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/pcm.cpp b/libeplayer3-sh4/writer/pcm.cpp index 4d1a305..c0ee6bf 100644 --- a/libeplayer3-sh4/writer/pcm.cpp +++ b/libeplayer3-sh4/writer/pcm.cpp @@ -43,18 +43,19 @@ extern "C" { } // reference: search for TypeLpcmDVDAudio in player/frame_parser/frame_parser_audio_lpcm.cpp -static const uint8_t clpcm_prv[14] = { - 0xA0, //sub_stream_id - 0, 0, //resvd and UPC_EAN_ISRC stuff, unused - 0x0A, //private header length - 0, 9, //first_access_unit_pointer - 0x00, //emph,rsvd,stereo,downmix - 0x0F, //quantisation word length 1,2 - 0x0F, //audio sampling freqency 1,2 - 0, //resvd, multi channel type - 0, //bit shift on channel GR2, assignment - 0x80, //dynamic range control - 0, 0 //resvd for copyright management +static const uint8_t clpcm_prv[14] = +{ + 0xA0, //sub_stream_id + 0, 0, //resvd and UPC_EAN_ISRC stuff, unused + 0x0A, //private header length + 0, 9, //first_access_unit_pointer + 0x00, //emph,rsvd,stereo,downmix + 0x0F, //quantisation word length 1,2 + 0x0F, //audio sampling freqency 1,2 + 0, //resvd, multi channel type + 0, //bit shift on channel GR2, assignment + 0x80, //dynamic range control + 0, 0 //resvd for copyright management }; class WriterPCM : public Writer @@ -98,7 +99,8 @@ bool WriterPCM::prepareClipPlay() memcpy(lpcm_prv, clpcm_prv, sizeof(lpcm_prv)); // figure out size of subframe and set up sample rate - switch (uSampleRate) { + switch (uSampleRate) + { case 48000: SubFrameLen = 40; break; @@ -136,7 +138,8 @@ bool WriterPCM::prepareClipPlay() //set number of channels lpcm_prv[10] = uNoOfChannels - 1; - switch (uBitsPerSample) { + switch (uBitsPerSample) + { case 24: lpcm_prv[7] |= 0x20; case 16: @@ -154,7 +157,8 @@ bool WriterPCM::writePCM(int64_t Pts, uint8_t *data, unsigned int size) bool res = true; uint8_t PesHeader[PES_MAX_HEADER_SIZE]; - if (initialHeader) { + if (initialHeader) + { initialHeader = false; prepareClipPlay(); ioctl(fd, AUDIO_CLEAR_BUFFER, NULL); @@ -162,7 +166,8 @@ bool WriterPCM::writePCM(int64_t Pts, uint8_t *data, unsigned int size) size += breakBufferFillSize; - while (size >= SubFrameLen) { + while (size >= SubFrameLen) + { if (breakBufferFillSize) memcpy(injectBuffer, breakBuffer, breakBufferFillSize); memcpy(injectBuffer + breakBufferFillSize, data, SubFrameLen - breakBufferFillSize); @@ -171,17 +176,22 @@ bool WriterPCM::writePCM(int64_t Pts, uint8_t *data, unsigned int size) breakBufferFillSize = 0; //write the PCM data - if (uBitsPerSample == 16) { - for (unsigned int n = 0; n < SubFrameLen; n += 2) { + if (uBitsPerSample == 16) + { + for (unsigned int n = 0; n < SubFrameLen; n += 2) + { uint8_t tmp = injectBuffer[n]; injectBuffer[n] = injectBuffer[n + 1]; injectBuffer[n + 1] = tmp; } - } else { + } + else + { // 0 1 2 3 4 5 6 7 8 9 10 11 // A1c A1b A1a B1c B1b B1a A2c A2b A2a B2c B2b B2a // to A1a A1b B1a B1b A2a A2b B2a B2b A1c B1c A2c B2c - for (unsigned int n = 0; n < SubFrameLen; n += 12) { + for (unsigned int n = 0; n < SubFrameLen; n += 12) + { uint8_t t, *p = injectBuffer + n; t = p[0]; p[0] = p[2]; @@ -207,12 +217,14 @@ bool WriterPCM::writePCM(int64_t Pts, uint8_t *data, unsigned int size) iov[2].iov_len = SubFrameLen; iov[0].iov_len = InsertPesHeader(PesHeader, iov[1].iov_len + iov[2].iov_len, PCM_PES_START_CODE, Pts, 0); int len = writev(fd, iov, 3); - if (len < 0) { + if (len < 0) + { res = false; break; } } - if (size && res) { + if (size && res) + { breakBufferFillSize = size; memcpy(breakBuffer, data, size); } @@ -231,58 +243,67 @@ void WriterPCM::Init(int _fd, AVStream *_stream, Player *_player) bool WriterPCM::Write(AVPacket *packet, int64_t pts) { - if (!packet) { + if (!packet) + { restart_audio_resampling = true; return true; } AVCodecContext *c = player->input.GetCodecContext((unsigned int)stream->index); - if (restart_audio_resampling) { + if (restart_audio_resampling) + { restart_audio_resampling = false; initialHeader = true; - if (swr) { + if (swr) + { swr_free(&swr); swr = NULL; } - if (decoded_frame) { + if (decoded_frame) + { av_frame_free(&decoded_frame); decoded_frame = NULL; } #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(57,25,101) AVCodec *codec = avcodec_find_decoder(c->codec_id); - if (!codec) { + if (!codec) + { fprintf(stderr, "%s %d: avcodec_find_decoder(%llx)\n", __func__, __LINE__, (unsigned long long) c->codec_id); return false; } avcodec_close(c); - if (avcodec_open2(c, codec, NULL)) { + if (avcodec_open2(c, codec, NULL)) + { fprintf(stderr, "%s %d: avcodec_open2 failed\n", __func__, __LINE__); return false; } #endif } - if (!swr) { + if (!swr) + { int in_rate = c->sample_rate; // rates in descending order int rates[] = {192000, 176400, 96000, 88200, 48000, 44100, 0}; int i = 0; // find the next equal or smallest rate while (rates[i] && in_rate < rates[i]) - i++; + i++; out_sample_rate = rates[i] ? rates[i] : 44100; out_channels = c->channels; - if (c->channel_layout == 0) { + if (c->channel_layout == 0) + { // FIXME -- need to guess, looks pretty much like a bug in the FFMPEG WMA decoder c->channel_layout = AV_CH_LAYOUT_STEREO; } out_channel_layout = c->channel_layout; // player2 won't play mono - if (out_channel_layout == AV_CH_LAYOUT_MONO) { + if (out_channel_layout == AV_CH_LAYOUT_MONO) + { out_channel_layout = AV_CH_LAYOUT_STEREO; out_channels = 2; } @@ -292,7 +313,8 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts) uBitsPerSample = 16; swr = swr_alloc(); - if (!swr) { + if (!swr) + { fprintf(stderr, "%s %d: swr_alloc failed\n", __func__, __LINE__); return false; } @@ -304,31 +326,37 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts) av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); int e = swr_init(swr); - if (e < 0) { + if (e < 0) + { fprintf(stderr, "swr_init: %d (icl=%d ocl=%d isr=%d osr=%d isf=%d osf=%d)\n", - -e, (int) c->channel_layout, - (int) out_channel_layout, c->sample_rate, out_sample_rate, c->sample_fmt, AV_SAMPLE_FMT_S16); + -e, (int) c->channel_layout, + (int) out_channel_layout, c->sample_rate, out_sample_rate, c->sample_fmt, AV_SAMPLE_FMT_S16); restart_audio_resampling = true; return false; } } unsigned int packet_size = packet->size; - while (packet_size > 0 || (!packet_size && !packet->data)) { + while (packet_size > 0 || (!packet_size && !packet->data)) + { - if (!decoded_frame) { - if (!(decoded_frame = av_frame_alloc())) { + if (!decoded_frame) + { + if (!(decoded_frame = av_frame_alloc())) + { fprintf(stderr, "out of memory\n"); exit(1); } - } else + } + else av_frame_unref(decoded_frame); #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) int got_frame = 0; int len = avcodec_decode_audio4(c, decoded_frame, &got_frame, packet); - if (len < 0) { + if (len < 0) + { restart_audio_resampling = true; break; } @@ -336,35 +364,43 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts) if (packet->data) packet_size -= len; - if (!got_frame) { + if (!got_frame) + { if (!packet->data || !packet_size) break; continue; } #else - int ret = avcodec_send_packet(c, packet); - if (ret < 0) { - if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { - restart_audio_resampling = true; - break; - } + int ret = avcodec_send_packet(c, packet); + if (ret < 0) + { + if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) + { + restart_audio_resampling = true; + break; } - if (ret >= 0) { - packet_size = 0; + } + if (ret >= 0) + { + packet_size = 0; + } + ret = avcodec_receive_frame(c, decoded_frame); + if (ret < 0) + { + if (ret == AVERROR_EOF) + { + restart_audio_resampling = true; + break; } - ret = avcodec_receive_frame(c, decoded_frame); - if (ret < 0) { - if (ret == AVERROR_EOF) { - restart_audio_resampling = true; - break; - } - if (ret != AVERROR(EAGAIN)) { - break; - } - else { - continue; - } + if (ret != AVERROR(EAGAIN)) + { + break; } + else + { + continue; + } + } #endif #if (LIBAVUTIL_VERSION_MAJOR < 54) @@ -375,11 +411,13 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts) int in_samples = decoded_frame->nb_samples; int out_samples = av_rescale_rnd(swr_get_delay(swr, c->sample_rate) + in_samples, out_sample_rate, c->sample_rate, AV_ROUND_UP); - if (out_samples > out_samples_max) { + if (out_samples > out_samples_max) + { if (output) av_freep(&output); int e = av_samples_alloc(&output, NULL, out_channels, out_samples, AV_SAMPLE_FMT_S16, 1); - if (e < 0) { + if (e < 0) + { fprintf(stderr, "av_samples_alloc: %d\n", -e); break; } @@ -388,7 +426,8 @@ bool WriterPCM::Write(AVPacket *packet, int64_t pts) out_samples = swr_convert(swr, &output, out_samples, (const uint8_t **) &decoded_frame->data[0], in_samples); - if (!writePCM(pts, output, out_samples * sizeof(short) * out_channels)) { + if (!writePCM(pts, output, out_samples * sizeof(short) * out_channels)) + { restart_audio_resampling = true; break; } @@ -409,4 +448,4 @@ WriterPCM::WriterPCM() Register(this, AV_CODEC_ID_INJECTPCM, AUDIO_ENCODING_LPCMA); } -static WriterPCM writer_pcm __attribute__ ((init_priority (300))); +static WriterPCM writer_pcm __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/pes.cpp b/libeplayer3-sh4/writer/pes.cpp index c8b9bc2..933500b 100644 --- a/libeplayer3-sh4/writer/pes.cpp +++ b/libeplayer3-sh4/writer/pes.cpp @@ -53,44 +53,45 @@ int InsertPesHeader(uint8_t *data, int size, uint8_t stream_id, int64_t pts, int { BitPacker_t ld2 = { data, 0, 32 }; - /* if (size > MAX_PES_PACKET_SIZE) - size = 0; // unbounded */ + /* if (size > MAX_PES_PACKET_SIZE) + size = 0; // unbounded */ PutBits(&ld2, 0x0, 8); PutBits(&ld2, 0x0, 8); - PutBits(&ld2, 0x1, 8); // Start Code - PutBits(&ld2, stream_id, 8); // Stream_id = Audio Stream + PutBits(&ld2, 0x1, 8); // Start Code + PutBits(&ld2, stream_id, 8); // Stream_id = Audio Stream //4 - PutBits(&ld2, size + 3 + (pts != INVALID_PTS_VALUE ? 5 : 0) + (pic_start_code ? (5) : 0), 16); // PES_packet_length + PutBits(&ld2, size + 3 + (pts != INVALID_PTS_VALUE ? 5 : 0) + (pic_start_code ? (5) : 0), 16); // PES_packet_length //6 = 4+2 - PutBits(&ld2, 0x2, 2); // 10 - PutBits(&ld2, 0x0, 2); // PES_Scrambling_control - PutBits(&ld2, 0x0, 1); // PES_Priority - PutBits(&ld2, 0x0, 1); // data_alignment_indicator - PutBits(&ld2, 0x0, 1); // Copyright - PutBits(&ld2, 0x0, 1); // Original or Copy + PutBits(&ld2, 0x2, 2); // 10 + PutBits(&ld2, 0x0, 2); // PES_Scrambling_control + PutBits(&ld2, 0x0, 1); // PES_Priority + PutBits(&ld2, 0x0, 1); // data_alignment_indicator + PutBits(&ld2, 0x0, 1); // Copyright + PutBits(&ld2, 0x0, 1); // Original or Copy //7 = 6+1 if (pts != INVALID_PTS_VALUE) PutBits(&ld2, 0x2, 2); else - PutBits(&ld2, 0x0, 2); // PTS_DTS flag + PutBits(&ld2, 0x0, 2); // PTS_DTS flag - PutBits(&ld2, 0x0, 1); // ESCR_flag - PutBits(&ld2, 0x0, 1); // ES_rate_flag - PutBits(&ld2, 0x0, 1); // DSM_trick_mode_flag - PutBits(&ld2, 0x0, 1); // additional_copy_ingo_flag - PutBits(&ld2, 0x0, 1); // PES_CRC_flag - PutBits(&ld2, 0x0, 1); // PES_extension_flag + PutBits(&ld2, 0x0, 1); // ESCR_flag + PutBits(&ld2, 0x0, 1); // ES_rate_flag + PutBits(&ld2, 0x0, 1); // DSM_trick_mode_flag + PutBits(&ld2, 0x0, 1); // additional_copy_ingo_flag + PutBits(&ld2, 0x0, 1); // PES_CRC_flag + PutBits(&ld2, 0x0, 1); // PES_extension_flag //8 = 7+1 if (pts != INVALID_PTS_VALUE) PutBits(&ld2, 0x5, 8); else - PutBits(&ld2, 0x0, 8); // PES_header_data_length + PutBits(&ld2, 0x0, 8); // PES_header_data_length //9 = 8+1 - if (pts != INVALID_PTS_VALUE) { + if (pts != INVALID_PTS_VALUE) + { PutBits(&ld2, 0x2, 4); PutBits(&ld2, (pts >> 30) & 0x7, 3); PutBits(&ld2, 0x1, 1); @@ -101,12 +102,13 @@ int InsertPesHeader(uint8_t *data, int size, uint8_t stream_id, int64_t pts, int } //14 = 9+5 - if (pic_start_code) { + if (pic_start_code) + { PutBits(&ld2, 0x0, 8); PutBits(&ld2, 0x0, 8); - PutBits(&ld2, 0x1, 8); // Start Code - PutBits(&ld2, pic_start_code & 0xff, 8); // 00, for picture start - PutBits(&ld2, (pic_start_code >> 8) & 0xff, 8); // For any extra information (like in mpeg4p2, the pic_start_code) + PutBits(&ld2, 0x1, 8); // Start Code + PutBits(&ld2, pic_start_code & 0xff, 8); // 00, for picture start + PutBits(&ld2, (pic_start_code >> 8) & 0xff, 8); // For any extra information (like in mpeg4p2, the pic_start_code) //14 + 5 = 19 } diff --git a/libeplayer3-sh4/writer/vc1.cpp b/libeplayer3-sh4/writer/vc1.cpp index 7d7a0bb..48a84d7 100644 --- a/libeplayer3-sh4/writer/vc1.cpp +++ b/libeplayer3-sh4/writer/vc1.cpp @@ -32,16 +32,16 @@ #include "pes.h" #include "writer.h" -#define WMV3_PRIVATE_DATA_LENGTH 4 +#define WMV3_PRIVATE_DATA_LENGTH 4 -#define METADATA_STRUCT_A_START 12 -#define METADATA_STRUCT_B_START 24 -#define METADATA_STRUCT_B_FRAMERATE_START 32 -#define METADATA_STRUCT_C_START 8 +#define METADATA_STRUCT_A_START 12 +#define METADATA_STRUCT_B_START 24 +#define METADATA_STRUCT_B_FRAMERATE_START 32 +#define METADATA_STRUCT_C_START 8 -#define VC1_SEQUENCE_LAYER_METADATA_START_CODE 0x80 -#define VC1_FRAME_START_CODE 0x0d +#define VC1_SEQUENCE_LAYER_METADATA_START_CODE 0x80 +#define VC1_FRAME_START_CODE 0x0d class WriterVC1 : public Writer { @@ -68,22 +68,24 @@ bool WriterVC1::Write(AVPacket *packet, int64_t pts) if (!packet || !packet->data) return false; - if (initialHeader) { + if (initialHeader) + { initialHeader = false; FrameHeaderSeen = false; const uint8_t SequenceLayerStartCode[] = - { 0x00, 0x00, 0x01, VC1_SEQUENCE_LAYER_METADATA_START_CODE }; + { 0x00, 0x00, 0x01, VC1_SEQUENCE_LAYER_METADATA_START_CODE }; - const uint8_t Metadata[] = { + const uint8_t Metadata[] = + { 0x00, 0x00, 0x00, 0xc5, 0x04, 0x00, 0x00, 0x00, - 0xc0, 0x00, 0x00, 0x00, /* Struct C set for for advanced profile */ - 0x00, 0x00, 0x00, 0x00, /* Struct A */ + 0xc0, 0x00, 0x00, 0x00, /* Struct C set for for advanced profile */ + 0x00, 0x00, 0x00, 0x00, /* Struct A */ 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, - 0x60, 0x00, 0x00, 0x00, /* Struct B */ + 0x60, 0x00, 0x00, 0x00, /* Struct B */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -116,7 +118,7 @@ bool WriterVC1::Write(AVPacket *packet, int64_t pts) *PesPtr++ = (get_codecpar(stream)->width >> 16) & 0xff; *PesPtr++ = get_codecpar(stream)->width >> 24; - PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */ + PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */ *PesPtr++ = (usecPerFrame >> 0) & 0xff; *PesPtr++ = (usecPerFrame >> 8) & 0xff; @@ -141,21 +143,25 @@ bool WriterVC1::Write(AVPacket *packet, int64_t pts) initialHeader = false; } - if (packet->size > 0) { + if (packet->size > 0) + { int Position = 0; bool insertSampleHeader = true; - while (Position < packet->size) { + while (Position < packet->size) + { int PacketLength = std::min(packet->size - Position, MAX_PES_PACKET_SIZE); uint8_t PesHeader[PES_MAX_HEADER_SIZE]; int HeaderLength = InsertPesHeader(PesHeader, PacketLength, VC1_VIDEO_PES_START_CODE, pts, 0); - if (insertSampleHeader) { + if (insertSampleHeader) + { const uint8_t Vc1FrameStartCode[] = { 0, 0, 1, VC1_FRAME_START_CODE }; if (!FrameHeaderSeen && (packet->size > 3) && (memcmp(packet->data, Vc1FrameStartCode, 4) == 0)) FrameHeaderSeen = true; - if (!FrameHeaderSeen) { + if (!FrameHeaderSeen) + { memcpy(&PesHeader[HeaderLength], Vc1FrameStartCode, sizeof(Vc1FrameStartCode)); HeaderLength += sizeof(Vc1FrameStartCode); } @@ -185,4 +191,4 @@ WriterVC1::WriterVC1() Register(this, AV_CODEC_ID_VC1, VIDEO_ENCODING_VC1); } -static WriterVC1 writer_vc1 __attribute__ ((init_priority (300))); +static WriterVC1 writer_vc1 __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/wmv.cpp b/libeplayer3-sh4/writer/wmv.cpp index f74a998..76ec19f 100644 --- a/libeplayer3-sh4/writer/wmv.cpp +++ b/libeplayer3-sh4/writer/wmv.cpp @@ -33,21 +33,22 @@ #include -#define WMV3_PRIVATE_DATA_LENGTH 4 +#define WMV3_PRIVATE_DATA_LENGTH 4 -static const uint8_t Metadata[] = { +static const uint8_t Metadata[] = +{ 0x00, 0x00, 0x00, 0xc5, 0x04, 0x00, 0x00, 0x00, -#define METADATA_STRUCT_C_START 8 - 0xc0, 0x00, 0x00, 0x00, /* Struct C set for for advanced profile */ -#define METADATA_STRUCT_A_START 12 - 0x00, 0x00, 0x00, 0x00, /* Struct A */ +#define METADATA_STRUCT_C_START 8 + 0xc0, 0x00, 0x00, 0x00, /* Struct C set for for advanced profile */ +#define METADATA_STRUCT_A_START 12 + 0x00, 0x00, 0x00, 0x00, /* Struct A */ 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, -#define METADATA_STRUCT_B_START 24 - 0x60, 0x00, 0x00, 0x00, /* Struct B */ +#define METADATA_STRUCT_B_START 24 + 0x60, 0x00, 0x00, 0x00, /* Struct B */ 0x00, 0x00, 0x00, 0x00, -#define METADATA_STRUCT_B_FRAMERATE_START 32 +#define METADATA_STRUCT_B_FRAMERATE_START 32 0x00, 0x00, 0x00, 0x00 }; @@ -75,7 +76,8 @@ bool WriterWMV::Write(AVPacket *packet, int64_t pts) if (!packet || !packet->data) return false; - if (initialHeader) { + if (initialHeader) + { #define PES_MIN_HEADER_SIZE 9 uint8_t PesPacket[PES_MIN_HEADER_SIZE + 128]; uint8_t *PesPtr; @@ -103,7 +105,7 @@ bool WriterWMV::Write(AVPacket *packet, int64_t pts) *PesPtr++ = (get_codecpar(stream)->width >> 16) & 0xff; *PesPtr++ = get_codecpar(stream)->width >> 24; - PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */ + PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */ *PesPtr++ = (usecPerFrame >> 0) & 0xff; *PesPtr++ = (usecPerFrame >> 8) & 0xff; @@ -120,18 +122,21 @@ bool WriterWMV::Write(AVPacket *packet, int64_t pts) initialHeader = false; } - if (packet->size > 0 && packet->data) { + if (packet->size > 0 && packet->data) + { int Position = 0; bool insertSampleHeader = true; - while (Position < packet->size) { + while (Position < packet->size) + { int PacketLength = std::min(packet->size - Position, MAX_PES_PACKET_SIZE); uint8_t PesHeader[PES_MAX_HEADER_SIZE] = { 0 }; int HeaderLength = InsertPesHeader(PesHeader, PacketLength, VC1_VIDEO_PES_START_CODE, pts, 0); - if (insertSampleHeader) { + if (insertSampleHeader) + { unsigned int PesLength; unsigned int PrivateHeaderLength; @@ -168,4 +173,4 @@ WriterWMV::WriterWMV() Register(this, AV_CODEC_ID_WMV3, VIDEO_ENCODING_WMV); } -static WriterWMV writer_wmv __attribute__ ((init_priority (300))); +static WriterWMV writer_wmv __attribute__((init_priority(300))); diff --git a/libeplayer3-sh4/writer/writer.cpp b/libeplayer3-sh4/writer/writer.cpp index daadecd..050672a 100644 --- a/libeplayer3-sh4/writer/writer.cpp +++ b/libeplayer3-sh4/writer/writer.cpp @@ -43,9 +43,9 @@ #include "wmv.cpp" //#include "aac.cpp" -static std::mapwriters __attribute__ ((init_priority (200))); -static std::mapvencoding __attribute__ ((init_priority (200))); -static std::mapaencoding __attribute__ ((init_priority (200))); +static std::mapwriters __attribute__((init_priority(200))); +static std::mapvencoding __attribute__((init_priority(200))); +static std::mapaencoding __attribute__((init_priority(200))); void Writer::Register(Writer *w, enum AVCodecID id, video_encoding_t encoding) { @@ -64,17 +64,19 @@ bool Writer::Write(AVPacket * /* packet */, int64_t /* pts */) return false; } -static Writer writer __attribute__ ((init_priority (300))); +static Writer writer __attribute__((init_priority(300))); Writer *Writer::GetWriter(enum AVCodecID id, enum AVMediaType codec_type, int track_type) { fprintf(stderr, "GETWRITER %d %d %d", id, codec_type, track_type); - if (track_type != 6) { // hack for ACC resampling - std::map::iterator it = writers.find(id); + if (track_type != 6) // hack for ACC resampling + { + std::map::iterator it = writers.find(id); if (it != writers.end()) return it->second; } - switch (codec_type) { + switch (codec_type) + { case AVMEDIA_TYPE_AUDIO: if (id == AV_CODEC_ID_INJECTPCM) // should not happen break; @@ -91,7 +93,7 @@ Writer *Writer::GetWriter(enum AVCodecID id, enum AVMediaType codec_type, int tr video_encoding_t Writer::GetVideoEncoding(enum AVCodecID id) { - std::map::iterator it = vencoding.find(id); + std::map::iterator it = vencoding.find(id); if (it != vencoding.end()) return it->second; return VIDEO_ENCODING_AUTO; @@ -99,7 +101,7 @@ video_encoding_t Writer::GetVideoEncoding(enum AVCodecID id) audio_encoding_t Writer::GetAudioEncoding(enum AVCodecID id) { - std::map::iterator it = aencoding.find(id); + std::map::iterator it = aencoding.find(id); if (it != aencoding.end()) return it->second; return AUDIO_ENCODING_LPCMA; diff --git a/libeplayer3/container/buff_ffmpeg.c b/libeplayer3/container/buff_ffmpeg.c index 8229380..7fbb23e 100644 --- a/libeplayer3/container/buff_ffmpeg.c +++ b/libeplayer3/container/buff_ffmpeg.c @@ -107,7 +107,7 @@ static void update_finish_timeout() * this is the reason for additional validation when we what to close immediately */ if (!progressive_playback && 0 == ret && currPts >= maxInjectedPts && - ((currPts - maxInjectedPts) / 90000) < 2) + ((currPts - maxInjectedPts) / 90000) < 2) { /* close immediately */ @@ -271,7 +271,7 @@ static void ffmpeg_filler(Context_t *context, int32_t id, int32_t *inpause, int3 } while ((flag == 0 && avContextTab[0] != NULL && avContextTab[0]->pb != NULL && rwdiff > FILLBUFDIFF) || - (flag == 1 && hasfillerThreadStarted[id] == 1 && avContextTab[0] != NULL && avContextTab[0]->pb != NULL && rwdiff > FILLBUFDIFF)) + (flag == 1 && hasfillerThreadStarted[id] == 1 && avContextTab[0] != NULL && avContextTab[0]->pb != NULL && rwdiff > FILLBUFDIFF)) { if (0 == PlaybackDieNow(0)) { diff --git a/libeplayer3/container/container_ffmpeg.c b/libeplayer3/container/container_ffmpeg.c index 98004b8..aef811c 100644 --- a/libeplayer3/container/container_ffmpeg.c +++ b/libeplayer3/container/container_ffmpeg.c @@ -223,7 +223,7 @@ static int32_t flv2mpeg4_converter = 0; /* MISC Functions */ /* ***************************** */ -static void __attribute__ ((unused)) ffmpeg_silen_callback(void *avcl __attribute__((unused)), int level __attribute__((unused)), const char *fmt __attribute__((unused)), va_list vl __attribute__((unused))) +static void __attribute__((unused)) ffmpeg_silen_callback(void *avcl __attribute__((unused)), int level __attribute__((unused)), const char *fmt __attribute__((unused)), va_list vl __attribute__((unused))) { return; } @@ -1124,7 +1124,7 @@ static void FFMPEGThread(Context_t *context) if (e < 0) { ffmpeg_err("swr_init: %d (icl=%d ocl=%d isr=%d osr=%d isf=%d osf=%d\n", - -e, (int32_t)c->channel_layout, (int32_t)out_channel_layout, c->sample_rate, out_sample_rate, c->sample_fmt, AV_SAMPLE_FMT_S16); + -e, (int32_t)c->channel_layout, (int32_t)out_channel_layout, c->sample_rate, out_sample_rate, c->sample_fmt, AV_SAMPLE_FMT_S16); swr_free(&swr); swr = NULL; } @@ -1140,11 +1140,11 @@ static void FFMPEGThread(Context_t *context) continue; } int64_t next_in_pts = av_rescale(wrapped_frame_get_best_effort_timestamp(decoded_frame), - ((AVStream *) audioTrack->stream)->time_base.num * (int64_t)out_sample_rate * c->sample_rate, - ((AVStream *) audioTrack->stream)->time_base.den); + ((AVStream *) audioTrack->stream)->time_base.num * (int64_t)out_sample_rate * c->sample_rate, + ((AVStream *) audioTrack->stream)->time_base.den); int64_t next_out_pts = av_rescale(swr_next_pts(swr, next_in_pts), - ((AVStream *) audioTrack->stream)->time_base.den, - ((AVStream *) audioTrack->stream)->time_base.num * (int64_t)out_sample_rate * c->sample_rate); + ((AVStream *) audioTrack->stream)->time_base.den, + ((AVStream *) audioTrack->stream)->time_base.num * (int64_t)out_sample_rate * c->sample_rate); currentAudioPts = audioTrack->pts = pts = calcPts(cAVIdx, audioTrack->stream, next_out_pts); out_samples = swr_convert(swr, &output[0], out_samples, (const uint8_t **) &decoded_frame->data[0], in_samples); @@ -1269,7 +1269,7 @@ static void FFMPEGThread(Context_t *context) /* if(ffmpegStatus == AVERROR(EAGAIN)) { - continue; + continue; } */ ffmpegStatus = 0; @@ -1354,7 +1354,7 @@ static void FFMPEGThread(Context_t *context) do_seek_target_seconds = 0; PlaybackDieNow(1); - if(context && context->playback) + if (context && context->playback) { container_ffmpeg_stop(context); } @@ -1533,7 +1533,7 @@ int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, uin int32_t err = 0; AVInputFormat *fmt = NULL; avContextTab[AVIdx] = avformat_alloc_context(); - if(avContextTab[AVIdx] != NULL) + if (avContextTab[AVIdx] != NULL) { avContextTab[AVIdx]->interrupt_callback.callback = interrupt_cb; avContextTab[AVIdx]->interrupt_callback.opaque = context->playback; @@ -1555,7 +1555,7 @@ int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, uin avio_ctx = container_ffmpeg_get_avio_context(custom_io_tab[AVIdx], 4096); if (avio_ctx) { - if(avContextTab[AVIdx]) + if (avContextTab[AVIdx]) { avContextTab[AVIdx]->pb = avio_ctx; use_custom_io[AVIdx] = 1; @@ -1774,7 +1774,7 @@ int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, uin { int len = strlen(baseUri) + 2 + 1; filename = malloc(len); - snprintf(filename,len,"ff%s",baseUri); + snprintf(filename, len, "ff%s", baseUri); free(baseUri); // memory leak, only once, so does not matter } @@ -1786,7 +1786,7 @@ int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, uin } } else if (0 == strncmp(filename, "http://", 7) || - 0 == strncmp(filename, "https://", 8)) + 0 == strncmp(filename, "https://", 8)) { av_dict_set(&avio_opts, "timeout", "20000000", 0); //20sec av_dict_set(&avio_opts, "reconnect", "1", 0); @@ -1827,7 +1827,7 @@ int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, uin return cERR_CONTAINER_FFMPEG_OPEN; } } - if(avContextTab[AVIdx] != NULL) + if (avContextTab[AVIdx] != NULL) { avContextTab[AVIdx]->iformat->flags |= AVFMT_SEEK_TO_PTS; avContextTab[AVIdx]->flags = AVFMT_FLAG_GENPTS; @@ -1879,7 +1879,7 @@ int32_t container_ffmpeg_init_av_context(Context_t *context, char *filename, uin } else if (progressive_playback) { - if(avContextTab[AVIdx] != NULL) + if (avContextTab[AVIdx] != NULL) avContextTab[AVIdx]->pb->read_packet = ffmpeg_read_wrapper; } } @@ -1938,7 +1938,7 @@ int32_t container_ffmpeg_init(Context_t *context, PlayFiles_t *playFilesNames) context->playback->abortRequested = 0; int32_t res = container_ffmpeg_init_av_context(context, playFilesNames->szFirstFile, playFilesNames->iFirstFileSize, \ - playFilesNames->szFirstMoovAtomFile, playFilesNames->iFirstMoovAtomOffset, 0); + playFilesNames->szFirstMoovAtomFile, playFilesNames->iFirstMoovAtomOffset, 0); if (0 != res) { @@ -1948,7 +1948,7 @@ int32_t container_ffmpeg_init(Context_t *context, PlayFiles_t *playFilesNames) if (playFilesNames->szSecondFile && playFilesNames->szSecondFile[0] != '\0') { res = container_ffmpeg_init_av_context(context, playFilesNames->szSecondFile, playFilesNames->iSecondFileSize, \ - playFilesNames->szSecondMoovAtomFile, playFilesNames->iSecondMoovAtomOffset, 1); + playFilesNames->szSecondMoovAtomFile, playFilesNames->iSecondMoovAtomOffset, 1); } if (0 != res) @@ -2071,7 +2071,7 @@ int32_t container_ffmpeg_update_tracks(Context_t *context, char *filename, int32 if (title) snprintf(str, sizeof(str), "%s (%d - %d)", title->value, chstart, chend); else - snprintf(str, sizeof(str), "%d (%d - %d)", i+1, chstart, chend); + snprintf(str, sizeof(str), "%d (%d - %d)", i + 1, chstart, chend); chstart = (double) 1000 * ch->start * av_q2d(ch->time_base); track.Name = str; track.Encoding = "chapter"; @@ -2119,9 +2119,9 @@ int32_t container_ffmpeg_update_tracks(Context_t *context, char *filename, int32 } encoding = Codec2Encoding((int32_t)get_codecpar(stream)->codec_id, (int32_t)get_codecpar(stream)->codec_type, \ - (uint8_t *)get_codecpar(stream)->extradata, \ - (int)get_codecpar(stream)->extradata_size, \ - (int)get_codecpar(stream)->profile, &version); + (uint8_t *)get_codecpar(stream)->extradata, \ + (int)get_codecpar(stream)->extradata_size, \ + (int)get_codecpar(stream)->profile, &version); if (encoding != NULL && !strncmp(encoding, "A_IPCM", 6) && insert_pcm_as_lpcm) { @@ -2408,9 +2408,9 @@ int32_t container_ffmpeg_update_tracks(Context_t *context, char *filename, int32 } else if (get_codecpar(stream)->codec_id == AV_CODEC_ID_WMAV1 || - get_codecpar(stream)->codec_id == AV_CODEC_ID_WMAV2 || - get_codecpar(stream)->codec_id == AV_CODEC_ID_WMAPRO || - get_codecpar(stream)->codec_id == AV_CODEC_ID_WMALOSSLESS) //if (get_codecpar(stream)->extradata_size > 0) + get_codecpar(stream)->codec_id == AV_CODEC_ID_WMAV2 || + get_codecpar(stream)->codec_id == AV_CODEC_ID_WMAPRO || + get_codecpar(stream)->codec_id == AV_CODEC_ID_WMALOSSLESS) //if (get_codecpar(stream)->extradata_size > 0) { ffmpeg_printf(10, "Create WMA ExtraData\n"); uint16_t channels = get_codecpar(stream)->channels; @@ -2560,7 +2560,8 @@ int32_t container_ffmpeg_update_tracks(Context_t *context, char *filename, int32 ffmpeg_printf(1, "cAVIdx[%d]: MANAGER_ADD track AUDIO\n", cAVIdx); if (context->manager->audio->Command(context, MANAGER_ADD, &track) < 0) { - if(track.aacbuf){ + if (track.aacbuf) + { free(track.aacbuf); track.aacbuf = NULL; } @@ -2785,7 +2786,7 @@ static int32_t container_ffmpeg_stop(Context_t *context) fclose(io->pFile); if (io->pMoovFile) fclose(io->pMoovFile); - if(custom_io_tab[i] != NULL) + if (custom_io_tab[i] != NULL) { free(custom_io_tab[i]); custom_io_tab[i] = NULL; @@ -3289,12 +3290,15 @@ static int container_ffmpeg_get_metadata(Context_t *context, char ***p) // find the first attached picture, if available unlink("/tmp/.id3coverart"); - for(unsigned int i = 0; i < avContextTab[0]->nb_streams; i++) { - if (avContextTab[0]->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) { + for (unsigned int i = 0; i < avContextTab[0]->nb_streams; i++) + { + if (avContextTab[0]->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) + { AVPacket *pkt = NULL; pkt = av_packet_clone(&avContextTab[0]->streams[i]->attached_pic); FILE *cover_art = fopen("/tmp/.id3coverart", "wb"); - if (cover_art) { + if (cover_art) + { fwrite(pkt->data, pkt->size, 1, cover_art); fclose(cover_art); } diff --git a/libeplayer3/external/ffmpeg/get_bits.h b/libeplayer3/external/ffmpeg/get_bits.h index e40e201..61b476b 100644 --- a/libeplayer3/external/ffmpeg/get_bits.h +++ b/libeplayer3/external/ffmpeg/get_bits.h @@ -97,8 +97,8 @@ typedef struct GetBitContext #endif #define OPEN_READER_NOSIZE(name, gb) \ - unsigned int name ## _index = (gb)->index; \ - unsigned int av_unused name ## _cache + unsigned int name ## _index = (gb)->index; \ + unsigned int av_unused name ## _cache #define OPEN_READER(name, gb) OPEN_READER_NOSIZE(name, gb) @@ -110,18 +110,18 @@ typedef struct GetBitContext # ifdef LONG_BITSTREAM_READER # define UPDATE_CACHE_LE(name, gb) name ## _cache = \ - AV_RL64((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) + AV_RL64((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) # define UPDATE_CACHE_BE(name, gb) name ## _cache = \ - AV_RB64((gb)->buffer + (name ## _index >> 3)) >> (32 - (name ## _index & 7)) + AV_RB64((gb)->buffer + (name ## _index >> 3)) >> (32 - (name ## _index & 7)) #else # define UPDATE_CACHE_LE(name, gb) name ## _cache = \ - AV_RL32((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) + AV_RL32((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) # define UPDATE_CACHE_BE(name, gb) name ## _cache = \ - AV_RB32((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7) + AV_RB32((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7) #endif @@ -146,10 +146,10 @@ typedef struct GetBitContext #define BITS_LEFT(name, gb) ((int)((gb)->size_in_bits - name ## _index)) #define SKIP_BITS(name, gb, num) \ - do { \ - SKIP_CACHE(name, gb, num); \ - SKIP_COUNTER(name, gb, num); \ - } while (0) + do { \ + SKIP_CACHE(name, gb, num); \ + SKIP_COUNTER(name, gb, num); \ + } while (0) #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) @@ -389,7 +389,7 @@ static inline int check_marker(void *logctx __attribute__((unused)), GetBitConte * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow. */ static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer, - int bit_size) + int bit_size) { int buffer_size; int ret = 0; @@ -421,7 +421,7 @@ static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer, * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow. */ static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer, - int byte_size) + int byte_size) { if (byte_size > INT_MAX / 8 || byte_size < 0) byte_size = -1; @@ -442,73 +442,73 @@ static inline const uint8_t *align_get_bits(GetBitContext *s) * is undefined. */ #define GET_VLC(code, name, gb, table, bits, max_depth) \ - do { \ - int n, nb_bits; \ - unsigned int index; \ - \ - index = SHOW_UBITS(name, gb, bits); \ - code = table[index][0]; \ - n = table[index][1]; \ - \ - if (max_depth > 1 && n < 0) { \ - LAST_SKIP_BITS(name, gb, bits); \ - UPDATE_CACHE(name, gb); \ - \ - nb_bits = -n; \ - \ - index = SHOW_UBITS(name, gb, nb_bits) + code; \ - code = table[index][0]; \ - n = table[index][1]; \ - if (max_depth > 2 && n < 0) { \ - LAST_SKIP_BITS(name, gb, nb_bits); \ - UPDATE_CACHE(name, gb); \ - \ - nb_bits = -n; \ - \ - index = SHOW_UBITS(name, gb, nb_bits) + code; \ - code = table[index][0]; \ - n = table[index][1]; \ - } \ - } \ - SKIP_BITS(name, gb, n); \ - } while (0) + do { \ + int n, nb_bits; \ + unsigned int index; \ + \ + index = SHOW_UBITS(name, gb, bits); \ + code = table[index][0]; \ + n = table[index][1]; \ + \ + if (max_depth > 1 && n < 0) { \ + LAST_SKIP_BITS(name, gb, bits); \ + UPDATE_CACHE(name, gb); \ + \ + nb_bits = -n; \ + \ + index = SHOW_UBITS(name, gb, nb_bits) + code; \ + code = table[index][0]; \ + n = table[index][1]; \ + if (max_depth > 2 && n < 0) { \ + LAST_SKIP_BITS(name, gb, nb_bits); \ + UPDATE_CACHE(name, gb); \ + \ + nb_bits = -n; \ + \ + index = SHOW_UBITS(name, gb, nb_bits) + code; \ + code = table[index][0]; \ + n = table[index][1]; \ + } \ + } \ + SKIP_BITS(name, gb, n); \ + } while (0) #define GET_RL_VLC(level, run, name, gb, table, bits, \ - max_depth, need_update) \ - do { \ - int n, nb_bits; \ - unsigned int index; \ - \ - index = SHOW_UBITS(name, gb, bits); \ - level = table[index].level; \ - n = table[index].len; \ - \ - if (max_depth > 1 && n < 0) { \ - SKIP_BITS(name, gb, bits); \ - if (need_update) { \ - UPDATE_CACHE(name, gb); \ - } \ - \ - nb_bits = -n; \ - \ - index = SHOW_UBITS(name, gb, nb_bits) + level; \ - level = table[index].level; \ - n = table[index].len; \ - if (max_depth > 2 && n < 0) { \ - LAST_SKIP_BITS(name, gb, nb_bits); \ - if (need_update) { \ - UPDATE_CACHE(name, gb); \ - } \ - nb_bits = -n; \ - \ - index = SHOW_UBITS(name, gb, nb_bits) + level; \ - level = table[index].level; \ - n = table[index].len; \ - } \ - } \ - run = table[index].run; \ - SKIP_BITS(name, gb, n); \ - } while (0) + max_depth, need_update) \ +do { \ + int n, nb_bits; \ + unsigned int index; \ + \ + index = SHOW_UBITS(name, gb, bits); \ + level = table[index].level; \ + n = table[index].len; \ + \ + if (max_depth > 1 && n < 0) { \ + SKIP_BITS(name, gb, bits); \ + if (need_update) { \ + UPDATE_CACHE(name, gb); \ + } \ + \ + nb_bits = -n; \ + \ + index = SHOW_UBITS(name, gb, nb_bits) + level; \ + level = table[index].level; \ + n = table[index].len; \ + if (max_depth > 2 && n < 0) { \ + LAST_SKIP_BITS(name, gb, nb_bits); \ + if (need_update) { \ + UPDATE_CACHE(name, gb); \ + } \ + nb_bits = -n; \ + \ + index = SHOW_UBITS(name, gb, nb_bits) + level; \ + level = table[index].level; \ + n = table[index].len; \ + } \ + } \ + run = table[index].run; \ + SKIP_BITS(name, gb, n); \ +} while (0) static inline int decode012(GetBitContext *gb) diff --git a/libeplayer3/external/ffmpeg/mpeg4audio.h b/libeplayer3/external/ffmpeg/mpeg4audio.h index 941df06..cc617df 100644 --- a/libeplayer3/external/ffmpeg/mpeg4audio.h +++ b/libeplayer3/external/ffmpeg/mpeg4audio.h @@ -54,7 +54,7 @@ extern const uint8_t ff_mpeg4audio_channels[8]; * @return On error -1 is returned, on success AudioSpecificConfig bit index in extradata. */ int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, - int bit_size, int sync_extension); + int bit_size, int sync_extension); enum AudioObjectType { diff --git a/libeplayer3/external/ffmpeg/put_bits.h b/libeplayer3/external/ffmpeg/put_bits.h index 40cc722..2265de4 100644 --- a/libeplayer3/external/ffmpeg/put_bits.h +++ b/libeplayer3/external/ffmpeg/put_bits.h @@ -47,7 +47,7 @@ typedef struct PutBitContext * @param buffer_size the size in bytes of buffer */ static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, - int buffer_size) + int buffer_size) { if (buffer_size < 0) { @@ -71,7 +71,7 @@ static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, * must be larger than the previous size */ static inline void rebase_put_bits(PutBitContext *s, uint8_t *buffer, - int buffer_size) + int buffer_size) { av_assert0(8 * buffer_size > s->size_in_bits); @@ -138,7 +138,7 @@ void avpriv_align_put_bits(PutBitContext *s); * @param terminate_string 0-terminates the written string if value is 1 */ void avpriv_put_string(PutBitContext *pb, const char *string, - int terminate_string); + int terminate_string); /** * Copy the content of src to the bitstream. diff --git a/libeplayer3/external/ffmpeg/src/mpeg4audio.c b/libeplayer3/external/ffmpeg/src/mpeg4audio.c index 934dc18..4ba0257 100644 --- a/libeplayer3/external/ffmpeg/src/mpeg4audio.c +++ b/libeplayer3/external/ffmpeg/src/mpeg4audio.c @@ -80,7 +80,7 @@ static inline int get_sample_rate(GetBitContext *gb, int *index) } int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, - int bit_size, int sync_extension) + int bit_size, int sync_extension) { GetBitContext gb; int specific_config_bitindex, ret; @@ -100,8 +100,8 @@ int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, c->sbr = -1; c->ps = -1; if (c->object_type == AOT_SBR || (c->object_type == AOT_PS && - // check for W6132 Annex YYYY draft MP3onMP4 - !(show_bits(&gb, 3) & 0x03 && !(show_bits(&gb, 9) & 0x3F)))) + // check for W6132 Annex YYYY draft MP3onMP4 + !(show_bits(&gb, 3) & 0x03 && !(show_bits(&gb, 9) & 0x3F)))) { if (c->object_type == AOT_PS) c->ps = 1; @@ -165,8 +165,8 @@ int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, } static av_always_inline unsigned int copy_bits(PutBitContext *pb, - GetBitContext *gb, - int bits) + GetBitContext *gb, + int bits) { unsigned int el = get_bits(gb, bits); put_bits(pb, bits, el); diff --git a/libeplayer3/external/flv2mpeg4/src/flv2mpeg4.c b/libeplayer3/external/flv2mpeg4/src/flv2mpeg4.c index 36049dd..d35d4ab 100644 --- a/libeplayer3/external/flv2mpeg4/src/flv2mpeg4.c +++ b/libeplayer3/external/flv2mpeg4/src/flv2mpeg4.c @@ -139,10 +139,10 @@ static int write_pad_not_coded_frames(flv2mpeg4_CTX *pub_ctx, CONVCTX *c, BW *bw // write frame if (pub_ctx->write_packet_cb(pub_ctx->usr_data, - 0, - 0,//c->frame, - bw->buf, - bw->pos) < 0) + 0, + 0,//c->frame, + bw->buf, + bw->pos) < 0) { return -1; } @@ -203,10 +203,10 @@ static int write_m4v_picture_frame(flv2mpeg4_CTX *pub_ctx, CONVCTX *c, BR *br, B // write frame if (pub_ctx->write_packet_cb(pub_ctx->usr_data, - vop.picture_type == M4V_I_TYPE, - 0,//c->frame, - bw->buf, - bw->pos) < 0) + vop.picture_type == M4V_I_TYPE, + 0,//c->frame, + bw->buf, + bw->pos) < 0) { return -1; } diff --git a/libeplayer3/external/flv2mpeg4/src/m4vencode.c b/libeplayer3/external/flv2mpeg4/src/m4vencode.c index 2315274..234669e 100644 --- a/libeplayer3/external/flv2mpeg4/src/m4vencode.c +++ b/libeplayer3/external/flv2mpeg4/src/m4vencode.c @@ -115,8 +115,8 @@ static inline void encode_escape_3(BW *p, int last, int run, int level) { #if 0 put_bits(p, - 7 + 2 + 1 + 6 + 1 + 12 + 1, //30bit - (3 << 23) + (3 << 21) + (last << 20) + (run << 14) + (1 << 13) + (((level - 64) & 0xfff) << 1) + 1); + 7 + 2 + 1 + 6 + 1 + 12 + 1, //30bit + (3 << 23) + (3 << 21) + (last << 20) + (run << 14) + (1 << 13) + (((level - 64) & 0xfff) << 1) + 1); #else put_bits(p, 7, 3); // escape put_bits(p, 2, 3); // escape3 diff --git a/libeplayer3/include/misc.h b/libeplayer3/include/misc.h index 7bf2ed4..3992804 100644 --- a/libeplayer3/include/misc.h +++ b/libeplayer3/include/misc.h @@ -64,16 +64,16 @@ static inline char *getExtension(char *name) static inline uint32_t ReadUint32(uint8_t *buffer) { uint32_t num = (uint32_t)buffer[0] << 24 | - (uint32_t)buffer[1] << 16 | - (uint32_t)buffer[2] << 8 | - (uint32_t)buffer[3]; + (uint32_t)buffer[1] << 16 | + (uint32_t)buffer[2] << 8 | + (uint32_t)buffer[3]; return num; } static inline uint16_t ReadUInt16(uint8_t *buffer) { uint16_t num = (uint16_t)buffer[0] << 8 | - (uint16_t)buffer[1]; + (uint16_t)buffer[1]; return num; } diff --git a/libeplayer3/include/pes.h b/libeplayer3/include/pes.h index 661ca95..5a6d149 100644 --- a/libeplayer3/include/pes.h +++ b/libeplayer3/include/pes.h @@ -1,8 +1,8 @@ #ifndef pes_123 #define pes_123 -#define PES_HEADER_SIZE 9 ///< size of pes header -#define PES_MAX_HEADER_SIZE (PES_HEADER_SIZE + 256) ///< maximal header size +#define PES_HEADER_SIZE 9 ///< size of pes header +#define PES_MAX_HEADER_SIZE (PES_HEADER_SIZE + 256) ///< maximal header size #define PES_PRIVATE_DATA_FLAG 0x80 #define PES_PRIVATE_DATA_LENGTH 8 #define PES_LENGTH_BYTE_0 5 diff --git a/libeplayer3/include/playback.h b/libeplayer3/include/playback.h index cbb9941..1781651 100644 --- a/libeplayer3/include/playback.h +++ b/libeplayer3/include/playback.h @@ -7,7 +7,8 @@ typedef void(* PlaybackDieNowCallback)(); bool PlaybackDieNowRegisterCallback(PlaybackDieNowCallback callback); -typedef enum { +typedef enum +{ PLAYBACK_OPEN, PLAYBACK_CLOSE, PLAYBACK_PLAY, diff --git a/libeplayer3/main/exteplayer.c b/libeplayer3/main/exteplayer.c index 613e915..196c769 100644 --- a/libeplayer3/main/exteplayer.c +++ b/libeplayer3/main/exteplayer.c @@ -261,16 +261,18 @@ static int HandleTracks(const Manager_t *ptrManager, const PlaybackCmd_t playbac { int i = 0; int Id = -1; - char * pch; + char *pch; char Name[] = " "; fprintf(stderr, "{\"%c_%c\": [", argvBuff[0], argvBuff[1]); for (i = 0; TrackList[i] != NULL; i += 2) { pch = strtok(TrackList[i], " "); - if (pch != NULL) { + if (pch != NULL) + { Id = atoi(pch); pch = strtok(NULL, " "); - if (pch != NULL) { + if (pch != NULL) + { snprintf(Name, sizeof(Name), "%s", pch); } } @@ -278,7 +280,7 @@ static int HandleTracks(const Manager_t *ptrManager, const PlaybackCmd_t playbac { fprintf(stderr, ", "); } - fprintf(stderr, "{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\"}", Id, TrackList[i+1], Name); + fprintf(stderr, "{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\"}", Id, TrackList[i + 1], Name); free(TrackList[i]); free(TrackList[i + 1]); } @@ -305,7 +307,7 @@ static int HandleTracks(const Manager_t *ptrManager, const PlaybackCmd_t playbac else // video { fprintf(stderr, "{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\",\"w\":%d,\"h\":%d,\"f\":%u,\"p\":%d,\"an\":%d,\"ad\":%d}}\n", \ - argvBuff[0], argvBuff[1], track->Id, track->Encoding, track->Name, track->width, track->height, track->frame_rate, track->progressive, track->aspect_ratio_num, track->aspect_ratio_den); + argvBuff[0], argvBuff[1], track->Id, track->Encoding, track->Name, track->width, track->height, track->frame_rate, track->progressive, track->aspect_ratio_num, track->aspect_ratio_den); } free(track->Encoding); free(track->Name); @@ -343,7 +345,7 @@ static int HandleTracks(const Manager_t *ptrManager, const PlaybackCmd_t playbac if (NULL != TrackList) { int i = 0; - char * pch; + char *pch; for (i = 0; TrackList[i] != NULL; i += 2) { if (idx == i) @@ -433,7 +435,7 @@ static int HandleTracks(const Manager_t *ptrManager, const PlaybackCmd_t playbac else // video { fprintf(stderr, "{\"%c_%c\":{\"id\":%d,\"e\":\"%s\",\"n\":\"%s\",\"w\":%d,\"h\":%d,\"f\":%u,\"p\":%d,\"an\":%d,\"ad\":%d}}\n", \ - argvBuff[0], argvBuff[1], track->Id, track->Encoding, track->Name, track->width, track->height, track->frame_rate, track->progressive, track->aspect_ratio_num, track->aspect_ratio_den); + argvBuff[0], argvBuff[1], track->Id, track->Encoding, track->Name, track->width, track->height, track->frame_rate, track->progressive, track->aspect_ratio_num, track->aspect_ratio_den); } free(track->Encoding); free(track->Name); @@ -671,7 +673,7 @@ static int ParseParams(int argc, char *argv[], PlayFiles_t *playbackFiles, int * strcpy(playbackFiles->szFirstFile, "file://"); } strcat(playbackFiles->szFirstFile, argv[optind]); - playbackFiles->szFirstFile[IPTV_MAX_FILE_PATH-1] = '\0'; + playbackFiles->szFirstFile[IPTV_MAX_FILE_PATH - 1] = '\0'; map_inter_file_path(playbackFiles->szFirstFile); printf("file: [%s]\n", playbackFiles->szFirstFile); ++optind; @@ -1032,7 +1034,7 @@ int main(int argc, char *argv[]) if (g_player->container && g_player->container->selectedContainer) { - commandRetVal = g_player->container->selectedContainer->Command((Context_t*)g_player->container, CONTAINER_LAST_PTS, &lastPts); + commandRetVal = g_player->container->selectedContainer->Command((Context_t *)g_player->container, CONTAINER_LAST_PTS, &lastPts); } if (0 == commandRetVal && lastPts != INVALID_PTS_VALUE) @@ -1052,10 +1054,10 @@ int main(int argc, char *argv[]) if (ptrP) { fprintf(stderr, "{\"PLAYBACK_INFO\":{ \"isPlaying\":%s, \"isPaused\":%s, \"isForwarding\":%s, \"isSeeking\":%s, \"isCreationPhase\":%s,", \ - DUMP_BOOL(ptrP->isPlaying), DUMP_BOOL(ptrP->isPaused), DUMP_BOOL(ptrP->isForwarding), DUMP_BOOL(ptrP->isSeeking), DUMP_BOOL(ptrP->isCreationPhase)); + DUMP_BOOL(ptrP->isPlaying), DUMP_BOOL(ptrP->isPaused), DUMP_BOOL(ptrP->isForwarding), DUMP_BOOL(ptrP->isSeeking), DUMP_BOOL(ptrP->isCreationPhase)); fprintf(stderr, "\"BackWard\":%d, \"SlowMotion\":%d, \"Speed\":%d, \"AVSync\":%d,", ptrP->BackWard, ptrP->SlowMotion, ptrP->Speed, ptrP->AVSync); fprintf(stderr, " \"isVideo\":%s, \"isAudio\":%s, \"isSubtitle\":%s, \"isDvbSubtitle\":%s, \"isTeletext\":%s, \"mayWriteToFramebuffer\":%s, \"abortRequested\":%s }}\n", \ - DUMP_BOOL(ptrP->isVideo), DUMP_BOOL(ptrP->isAudio), DUMP_BOOL(0), DUMP_BOOL(0), DUMP_BOOL(0), DUMP_BOOL(0), DUMP_BOOL(ptrP->abortRequested)); + DUMP_BOOL(ptrP->isVideo), DUMP_BOOL(ptrP->isAudio), DUMP_BOOL(0), DUMP_BOOL(0), DUMP_BOOL(0), DUMP_BOOL(0), DUMP_BOOL(ptrP->abortRequested)); } break; diff --git a/libeplayer3/manager/audio.c b/libeplayer3/manager/audio.c index 419da78..5867982 100644 --- a/libeplayer3/manager/audio.c +++ b/libeplayer3/manager/audio.c @@ -85,7 +85,8 @@ static int ManagerAdd(Context_t *context, Track_t track) if (Tracks[i].Id == track.Id) { Tracks[i].pending = 0; - if(track.aacbuf){ + if (track.aacbuf) + { free(track.aacbuf); track.aacbuf = NULL; } @@ -303,7 +304,7 @@ static int Command(Context_t *context, ManagerCmd_t command, void *argument) } case MANAGER_GETENCODING: { - if ((TrackCount > 0) && (CurrentTrack >= 0) && (Tracks[CurrentTrack].Encoding != NULL )) + if ((TrackCount > 0) && (CurrentTrack >= 0) && (Tracks[CurrentTrack].Encoding != NULL)) { *((char **)argument) = (char *)strdup(Tracks[CurrentTrack].Encoding); } @@ -315,7 +316,7 @@ static int Command(Context_t *context, ManagerCmd_t command, void *argument) } case MANAGER_GETNAME: { - if ((TrackCount > 0) && (CurrentTrack >= 0) && (Tracks[CurrentTrack].Name != NULL )) + if ((TrackCount > 0) && (CurrentTrack >= 0) && (Tracks[CurrentTrack].Name != NULL)) { *((char **)argument) = (char *)strdup(Tracks[CurrentTrack].Name); } diff --git a/libeplayer3/manager/chapter.c b/libeplayer3/manager/chapter.c index 4a6fc11..4fb1bdb 100644 --- a/libeplayer3/manager/chapter.c +++ b/libeplayer3/manager/chapter.c @@ -39,7 +39,7 @@ static short debug_level = 0; #define chapter_mgr_printf(level, x...) do { \ -if (debug_level >= level) printf(x); } while (0) + if (debug_level >= level) printf(x); } while (0) #else #define chapter_mgr_printf(level, x...) #endif @@ -152,7 +152,7 @@ static char **ManagerList(Context_t *context __attribute__((unused))) } chapter_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, - __FUNCTION__, tracklist, j, TrackCount); + __FUNCTION__, tracklist, j, TrackCount); return tracklist; } diff --git a/libeplayer3/manager/video.c b/libeplayer3/manager/video.c index b6ebcff..d60c311 100644 --- a/libeplayer3/manager/video.c +++ b/libeplayer3/manager/video.c @@ -251,7 +251,7 @@ static int Command(Context_t *context, ManagerCmd_t command, void *argument) } case MANAGER_GETENCODING: { - if ((TrackCount > 0) && (CurrentTrack >= 0) && (Tracks[CurrentTrack].Encoding != NULL )) + if ((TrackCount > 0) && (CurrentTrack >= 0) && (Tracks[CurrentTrack].Encoding != NULL)) { *((char **)argument) = (char *)strdup(Tracks[CurrentTrack].Encoding); } @@ -263,7 +263,7 @@ static int Command(Context_t *context, ManagerCmd_t command, void *argument) } case MANAGER_GETNAME: { - if ((TrackCount > 0) && (CurrentTrack >= 0) && (Tracks[CurrentTrack].Name != NULL )) + if ((TrackCount > 0) && (CurrentTrack >= 0) && (Tracks[CurrentTrack].Name != NULL)) { *((char **)argument) = (char *)strdup(Tracks[CurrentTrack].Name); } diff --git a/libeplayer3/output/linuxdvb_fake.c b/libeplayer3/output/linuxdvb_fake.c index cb4070c..88312d5 100644 --- a/libeplayer3/output/linuxdvb_fake.c +++ b/libeplayer3/output/linuxdvb_fake.c @@ -231,7 +231,7 @@ static int Write(Context_t *context, void *_out) audio = !strcmp("audio", out->type); linuxdvb_printf(20, "DataLength=%u PrivateLength=%u Pts=%"PRIu64" FrameRate=%d\n", - out->len, out->extralen, out->pts, out->frameRate); + out->len, out->extralen, out->pts, out->frameRate); linuxdvb_printf(20, "v%d a%d\n", video, audio); if (video) diff --git a/libeplayer3/output/linuxdvb_mipsel.c b/libeplayer3/output/linuxdvb_mipsel.c index 62af8d5..d8db1a8 100644 --- a/libeplayer3/output/linuxdvb_mipsel.c +++ b/libeplayer3/output/linuxdvb_mipsel.c @@ -821,7 +821,7 @@ static int Write(Context_t *context, void *_out) audio = !strcmp("audio", out->type); linuxdvb_printf(20, "DataLength=%u PrivateLength=%u Pts=%" PRIu64 " FrameRate=%d\n", - out->len, out->extralen, out->pts, out->frameRate); + out->len, out->extralen, out->pts, out->frameRate); linuxdvb_printf(20, "v%d a%d\n", video, audio); if (video) diff --git a/libeplayer3/output/linuxdvb_sh4.c b/libeplayer3/output/linuxdvb_sh4.c index dedc77f..42194ad 100644 --- a/libeplayer3/output/linuxdvb_sh4.c +++ b/libeplayer3/output/linuxdvb_sh4.c @@ -963,7 +963,7 @@ static int Write(void *_context, void *_out) audio = !strcmp("audio", out->type); linuxdvb_printf(20, "DataLength=%u PrivateLength=%u Pts=%llu FrameRate=%f\n", - out->len, out->extralen, out->pts, out->frameRate); + out->len, out->extralen, out->pts, out->frameRate); linuxdvb_printf(20, "v%d a%d\n", video, audio); if (video) diff --git a/libeplayer3/output/writer/common/misc.c b/libeplayer3/output/writer/common/misc.c index bb4d42a..696934b 100644 --- a/libeplayer3/output/writer/common/misc.c +++ b/libeplayer3/output/writer/common/misc.c @@ -138,7 +138,7 @@ stb_type_t GetSTBType() type = STB_DREAMBOX; } else if (access("/proc/stb/info/vumodel", F_OK) != -1 && - access("/proc/stb/info/boxtype", F_OK) == -1) + access("/proc/stb/info/boxtype", F_OK) == -1) { // some STB like Octagon SF4008 has also /proc/stb/info/vumodel // but VU PLUS does not have /proc/stb/info/boxtype diff --git a/libeplayer3/output/writer/mipsel/aac.c b/libeplayer3/output/writer/mipsel/aac.c index c808927..655a3b9 100644 --- a/libeplayer3/output/writer/mipsel/aac.c +++ b/libeplayer3/output/writer/mipsel/aac.c @@ -169,7 +169,7 @@ static int _writeData(WriterAVCallData_t *call, int type) else // check LOAS header { if (!(call->len > 2 && call->data[0] == 0x56 && (call->data[1] >> 4) == 0xe && - ((uint32_t)(AV_RB16(call->data + 1) & 0x1FFF) + 3) == call->len)) + ((uint32_t)(AV_RB16(call->data + 1) & 0x1FFF) + 3) == call->len)) { aac_err("parsing Data with wrong latm header. ignoring...\n"); return 0; @@ -213,7 +213,7 @@ static int writeDataADTS(WriterAVCallData_t *call) } if ((call->private_data && 0 == strncmp("ADTS", (const char *)call->private_data, call->private_size)) || - HasADTSHeader(call->data, call->len)) + HasADTSHeader(call->data, call->len)) { //printf("%hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n", call->data[0], call->data[1], call->data[2], call->data[3], call->data[4], call->data[5], call->data[6], call->data[7]); return _writeData(call, 0); diff --git a/libeplayer3/output/writer/mipsel/divx3.c b/libeplayer3/output/writer/mipsel/divx3.c index 40256a0..71206d6 100644 --- a/libeplayer3/output/writer/mipsel/divx3.c +++ b/libeplayer3/output/writer/mipsel/divx3.c @@ -132,11 +132,11 @@ static int writeData(WriterAVCallData_t *call) data += 38; data[0] = B_GET_BITS(width, 11, 4); data[1] = B_SET_BITS("width [3..0]", B_GET_BITS(width, 3, 0), 7, 4) | - B_SET_BITS("'10'", 0x02, 3, 2) | - B_SET_BITS("height [11..10]", B_GET_BITS(height, 11, 10), 1, 0); + B_SET_BITS("'10'", 0x02, 3, 2) | + B_SET_BITS("height [11..10]", B_GET_BITS(height, 11, 10), 1, 0); data[2] = B_GET_BITS(height, 9, 2); data[3] = B_SET_BITS("height [1.0]", B_GET_BITS(height, 1, 0), 7, 6) | - B_SET_BITS("'100000'", 0x20, 5, 0); + B_SET_BITS("'100000'", 0x20, 5, 0); iov[ic].iov_base = brcm_divx311_sequence_header; iov[ic++].iov_len = sizeof(brcm_divx311_sequence_header); diff --git a/libeplayer3/output/writer/mipsel/h264.c b/libeplayer3/output/writer/mipsel/h264.c index 1b01c5c..bcf91a5 100644 --- a/libeplayer3/output/writer/mipsel/h264.c +++ b/libeplayer3/output/writer/mipsel/h264.c @@ -335,8 +335,8 @@ static int writeData(WriterAVCallData_t *call) /* AnnexA */ if (!avc3 && ((1 < call->private_size && 0 == call->private_data[0]) || - ((call->len > 3) && ((call->data[0] == 0x00 && call->data[1] == 0x00 && call->data[2] == 0x00 && call->data[3] == 0x01) || - (call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff))))) + ((call->len > 3) && ((call->data[0] == 0x00 && call->data[1] == 0x00 && call->data[2] == 0x00 && call->data[3] == 0x01) || + (call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff))))) { uint32_t i = 0; uint8_t InsertPrivData = !sps_pps_in_stream; diff --git a/libeplayer3/output/writer/mipsel/pcm.c b/libeplayer3/output/writer/mipsel/pcm.c index 30caa13..d3cfb6f 100644 --- a/libeplayer3/output/writer/mipsel/pcm.c +++ b/libeplayer3/output/writer/mipsel/pcm.c @@ -137,7 +137,7 @@ static int writeData(WriterAVCallData_t *call) case AV_CODEC_ID_PCM_S16LE: case AV_CODEC_ID_PCM_U16LE: LE = 1; - // fall through + // fall through case AV_CODEC_ID_PCM_S16BE: case AV_CODEC_ID_PCM_U16BE: width = depth = 16; @@ -145,7 +145,7 @@ static int writeData(WriterAVCallData_t *call) case AV_CODEC_ID_PCM_S24LE: case AV_CODEC_ID_PCM_U24LE: LE = 1; - // fall through + // fall through case AV_CODEC_ID_PCM_S24BE: case AV_CODEC_ID_PCM_U24BE: width = depth = 24; @@ -153,7 +153,7 @@ static int writeData(WriterAVCallData_t *call) case AV_CODEC_ID_PCM_S32LE: case AV_CODEC_ID_PCM_U32LE: LE = 1; - // fall through + // fall through case AV_CODEC_ID_PCM_S32BE: case AV_CODEC_ID_PCM_U32BE: width = depth = 32; diff --git a/libeplayer3/output/writer/mipsel/writer.c b/libeplayer3/output/writer/mipsel/writer.c index f8853a0..a24da31 100644 --- a/libeplayer3/output/writer/mipsel/writer.c +++ b/libeplayer3/output/writer/mipsel/writer.c @@ -144,8 +144,8 @@ ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, void *pDVBMtx __a //if (retval == 0) //{ - // //printf("RETURN FROM SELECT DUE TO TIMEOUT\n"); - // continue; + // //printf("RETURN FROM SELECT DUE TO TIMEOUT\n"); + // continue; //} if (FD_ISSET(pipefd, &rfds)) diff --git a/libeplayer3/output/writer/sh4/aac.c b/libeplayer3/output/writer/sh4/aac.c index 4d36753..6f57379 100644 --- a/libeplayer3/output/writer/sh4/aac.c +++ b/libeplayer3/output/writer/sh4/aac.c @@ -168,7 +168,7 @@ static int _writeData(void *_call, int type) else // check LOAS header { if (!(call->len > 2 && call->data[0] == 0x56 && (call->data[1] >> 4) == 0xe && - (AV_RB16(call->data + 1) & 0x1FFF) + 3 == call->len)) + (AV_RB16(call->data + 1) & 0x1FFF) + 3 == call->len)) { aac_err("parsing Data with wrong latm header. ignoring...\n"); return 0; @@ -214,7 +214,7 @@ static int writeDataADTS(void *_call) } if ((call->private_data && 0 == strncmp("ADTS", call->private_data, call->private_size)) || - HasADTSHeader(call->data, call->len)) + HasADTSHeader(call->data, call->len)) { return _writeData(_call, 0); } diff --git a/libeplayer3/output/writer/sh4/h264.c b/libeplayer3/output/writer/sh4/h264.c index a81b535..5c18d5f 100644 --- a/libeplayer3/output/writer/sh4/h264.c +++ b/libeplayer3/output/writer/sh4/h264.c @@ -237,8 +237,8 @@ static int32_t writeData(void *_call) /* AnnexA */ if (!avc3 && ((1 < call->private_size && 0 == call->private_data[0]) || - (call->len > 3) && ((call->data[0] == 0x00 && call->data[1] == 0x00 && call->data[2] == 0x00 && call->data[3] == 0x01) || - (call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff)))) + (call->len > 3) && ((call->data[0] == 0x00 && call->data[1] == 0x00 && call->data[2] == 0x00 && call->data[3] == 0x01) || + (call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff)))) { uint32_t PacketLength = 0; uint32_t FakeStartCode = /*(call->Version << 8) | */PES_VERSION_FAKE_START_CODE; @@ -440,7 +440,7 @@ static int32_t writeData(void *_call) if (NalStart + NalLength > SampleSize) { h264_printf(20, "nal length past end of buffer - size %u frame offset %u left %u\n", - NalLength, NalStart, SampleSize - NalStart); + NalLength, NalStart, SampleSize - NalStart); NalStart = SampleSize; } diff --git a/libeplayer3/output/writer/sh4/mpeg2.c b/libeplayer3/output/writer/sh4/mpeg2.c index d7fb298..602ce7d 100644 --- a/libeplayer3/output/writer/sh4/mpeg2.c +++ b/libeplayer3/output/writer/sh4/mpeg2.c @@ -106,7 +106,7 @@ static int writeData(void *_call) while (Position < call->len) { int32_t PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ? - (call->len - Position) : MAX_PES_PACKET_SIZE; + (call->len - Position) : MAX_PES_PACKET_SIZE; int32_t Remaining = call->len - Position - PacketLength; diff --git a/libeplayer3/output/writer/sh4/pcm.c b/libeplayer3/output/writer/sh4/pcm.c index 43e1709..201c70f 100644 --- a/libeplayer3/output/writer/sh4/pcm.c +++ b/libeplayer3/output/writer/sh4/pcm.c @@ -97,11 +97,11 @@ static uint32_t breakBufferFillSize = 0; static int32_t prepareClipPlay(int32_t uNoOfChannels, int32_t uSampleRate, int32_t uBitsPerSample, uint8_t bLittleEndian __attribute__((unused))) { printf("rate: %d ch: %d bits: %d (%d bps)\n", - uSampleRate/*Format->dwSamplesPerSec*/, - uNoOfChannels/*Format->wChannels*/, - uBitsPerSample/*Format->wBitsPerSample*/, - (uBitsPerSample/*Format->wBitsPerSample*/ / 8) - ); + uSampleRate/*Format->dwSamplesPerSec*/, + uNoOfChannels/*Format->wChannels*/, + uBitsPerSample/*Format->wBitsPerSample*/, + (uBitsPerSample/*Format->wBitsPerSample*/ / 8) + ); SubFrameLen = 0; SubFramesPerPES = 0; diff --git a/libeplayer3/output/writer/sh4/vc1.c b/libeplayer3/output/writer/sh4/vc1.c index f9fba12..9aa35a0 100644 --- a/libeplayer3/output/writer/sh4/vc1.c +++ b/libeplayer3/output/writer/sh4/vc1.c @@ -197,7 +197,7 @@ static int writeData(void *_call) while (Position < call->len) { int32_t PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ? - (call->len - Position) : MAX_PES_PACKET_SIZE; + (call->len - Position) : MAX_PES_PACKET_SIZE; int32_t Remaining = call->len - Position - PacketLength; diff --git a/libeplayer3/output/writer/sh4/wmv.c b/libeplayer3/output/writer/sh4/wmv.c index 2204195..c72a6c2 100644 --- a/libeplayer3/output/writer/sh4/wmv.c +++ b/libeplayer3/output/writer/sh4/wmv.c @@ -134,7 +134,7 @@ static int writeData(void *_call) wmv_printf(10, "Got Private Size %d\n", call->private_size); memcpy(private_data.privateData, call->private_data, - call->private_size > WMV3_PRIVATE_DATA_LENGTH ? WMV3_PRIVATE_DATA_LENGTH : call->private_size); + call->private_size > WMV3_PRIVATE_DATA_LENGTH ? WMV3_PRIVATE_DATA_LENGTH : call->private_size); private_data.width = call->Width; private_data.height = call->Height; @@ -196,7 +196,7 @@ static int writeData(void *_call) while (Position < call->len) { int PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ? - (call->len - Position) : MAX_PES_PACKET_SIZE; + (call->len - Position) : MAX_PES_PACKET_SIZE; int Remaining = call->len - Position - PacketLength; @@ -214,7 +214,7 @@ static int writeData(void *_call) PrivateHeaderLength = InsertVideoPrivateDataHeader(&PesHeader[HeaderLength], call->len); /* Update PesLength */ PesLength = PesHeader[PES_LENGTH_BYTE_0] + - (PesHeader[PES_LENGTH_BYTE_1] << 8) + PrivateHeaderLength; + (PesHeader[PES_LENGTH_BYTE_1] << 8) + PrivateHeaderLength; PesHeader[PES_LENGTH_BYTE_0] = PesLength & 0xff; PesHeader[PES_LENGTH_BYTE_1] = (PesLength >> 8) & 0xff; PesHeader[PES_HEADER_DATA_LENGTH_BYTE] += PrivateHeaderLength; diff --git a/libeplayer3/output/writer/sh4/writer.c b/libeplayer3/output/writer/sh4/writer.c index f1bd83e..8e383f1 100644 --- a/libeplayer3/output/writer/sh4/writer.c +++ b/libeplayer3/output/writer/sh4/writer.c @@ -44,7 +44,7 @@ static short debug_level = 0; #define writer_printf(level, x...) do { \ -if (debug_level >= level) printf(x); } while (0) + if (debug_level >= level) printf(x); } while (0) #else #define writer_printf(level, x...) #endif diff --git a/libeplayer3/playback/playback.c b/libeplayer3/playback/playback.c index 4512309..edd876f 100644 --- a/libeplayer3/playback/playback.c +++ b/libeplayer3/playback/playback.c @@ -195,7 +195,7 @@ static int PlaybackOpen(Context_t *context, PlayFiles_t *pFiles) // mms is in reality called rtsp, and ffmpeg expects this int len = strlen(uri) + 2; char *tUri = (char *)malloc(strlen(uri) + 2); - snprintf(tUri,len,"rtsp%s",uri+3); + snprintf(tUri, len, "rtsp%s", uri + 3); free(context->playback->uri); context->playback->uri = tUri; } @@ -219,7 +219,7 @@ static int PlaybackOpen(Context_t *context, PlayFiles_t *pFiles) (context->container->selectedContainer->Command(context, CONTAINER_INIT, pFiles) < 0)) { playback_err("CONTAINER_ADD failed\n"); - if(context->playback->uri) + if (context->playback->uri) { free(context->playback->uri); context->playback->uri = NULL; @@ -242,9 +242,9 @@ static int PlaybackClose(Context_t *context) { playback_err("container delete failed\n"); } - if(context->manager->audio) + if (context->manager->audio) context->manager->audio->Command(context, MANAGER_DEL, NULL); - if(context->manager->video) + if (context->manager->video) context->manager->video->Command(context, MANAGER_DEL, NULL); if (context->manager->chapter) context->manager->chapter->Command(context, MANAGER_DEL, NULL); @@ -385,8 +385,8 @@ static int32_t PlaybackContinue(Context_t *context) playback_printf(10, "\n"); if (context->playback->isPlaying && - (context->playback->isPaused || context->playback->isForwarding || - context->playback->BackWard || context->playback->SlowMotion)) + (context->playback->isPaused || context->playback->isForwarding || + context->playback->BackWard || context->playback->SlowMotion)) { if (context->playback->SlowMotion || context->playback->isForwarding || context->playback->BackWard) context->output->Command(context, OUTPUT_CLEAR, NULL); @@ -478,7 +478,7 @@ static int32_t PlaybackTerminate(Context_t *context) } ret = context->container->selectedContainer->Command(context, CONTAINER_STOP, NULL); - if(context && context->playback) + if (context && context->playback) { context->playback->isPaused = 0; context->playback->isPlaying = 0; @@ -487,7 +487,7 @@ static int32_t PlaybackTerminate(Context_t *context) context->playback->SlowMotion = 0; context->playback->Speed = 0; } - if(context && context->output) + if (context && context->output) context->output->Command(context, OUTPUT_STOP, NULL); } else @@ -557,7 +557,7 @@ static int PlaybackFastBackward(Context_t *context, int *speed) /* Audio only reverse play not supported */ if (context->playback->isVideo && !context->playback->isForwarding && - (!context->playback->isPaused || context->playback->isPlaying)) + (!context->playback->isPaused || context->playback->isPlaying)) { if ((*speed > 0) || (*speed < cMaxSpeed_fr)) { diff --git a/libgeneric-pc/audio.cpp b/libgeneric-pc/audio.cpp index e0d98f9..0fd5e9f 100644 --- a/libgeneric-pc/audio.cpp +++ b/libgeneric-pc/audio.cpp @@ -43,7 +43,7 @@ extern "C" { /* my own buf 16k */ #define DMX_BUF_SZ 0x4000 -cAudio * audioDecoder = NULL; +cAudio *audioDecoder = NULL; extern cDemux *audioDemux; static uint8_t *dmxbuf = NULL; static int bufpos; @@ -163,9 +163,9 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int le) adevice = ao_open_live(driver, &sformat, NULL); ao_info *ai = ao_driver_info(driver); hal_info("%s: changed params ch %d srate %d bits %d le %d adevice %p\n", - __func__, ch, srate, bits, le, adevice);; + __func__, ch, srate, bits, le, adevice);; hal_info("libao driver: %d name '%s' short '%s' author '%s'\n", - driver, ai->name, ai->short_name, ai->author); + driver, ai->name, ai->short_name, ai->author); } return 0; }; @@ -173,7 +173,8 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int le) int cAudio::WriteClip(unsigned char *buffer, int size) { hal_debug("cAudio::%s buf 0x%p size %d\n", __func__, buffer, size); - if (!adevice) { + if (!adevice) + { hal_info("%s: adevice not opened?\n", __func__); return 0; } @@ -187,7 +188,8 @@ int cAudio::StopClip() #if 0 /* don't do anything - closing / reopening ao all the time makes for long delays * reinit on-demand (e.g. for changed parameters) instead */ - if (!adevice) { + if (!adevice) + { hal_info("%s: adevice not opened?\n", __func__); return 0; } @@ -200,13 +202,15 @@ int cAudio::StopClip() void cAudio::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode) { type = 0; - layer = 0; /* not used */ + layer = 0; /* not used */ freq = 0; - bitrate = 0; /* not used, but easy to get :-) */ - mode = 0; /* default: stereo */ + bitrate = 0; /* not used, but easy to get :-) */ + mode = 0; /* default: stereo */ printf("cAudio::getAudioInfo c %p\n", c); - if (c) { - switch (c->codec_id) { + if (c) + { + switch (c->codec_id) + { case AV_CODEC_ID_MP2: type = AUDIO_FMT_MPEG; break; @@ -236,40 +240,42 @@ void cAudio::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &m bitrate = c->bit_rate; if (c->channels == 1) mode = 3; /* for AV_CODEC_ID_MP2, only stereo / mono is detected for now */ - if (c->codec_id != AV_CODEC_ID_MP2) { - switch (c->channel_layout) { + if (c->codec_id != AV_CODEC_ID_MP2) + { + switch (c->channel_layout) + { case AV_CH_LAYOUT_MONO: - mode = 1; // "C" + mode = 1; // "C" break; case AV_CH_LAYOUT_STEREO: - mode = 2; // "L/R" + mode = 2; // "L/R" break; case AV_CH_LAYOUT_2_1: case AV_CH_LAYOUT_SURROUND: - mode = 3; // "L/C/R" + mode = 3; // "L/C/R" break; case AV_CH_LAYOUT_2POINT1: - mode = 4; // "L/R/S" + mode = 4; // "L/R/S" break; case AV_CH_LAYOUT_3POINT1: - mode = 5; // "L/C/R/S" + mode = 5; // "L/C/R/S" break; case AV_CH_LAYOUT_2_2: case AV_CH_LAYOUT_QUAD: - mode = 6; // "L/R/SL/SR" + mode = 6; // "L/R/SL/SR" break; case AV_CH_LAYOUT_5POINT0: case AV_CH_LAYOUT_5POINT1: - mode = 7; // "L/C/R/SL/SR" + mode = 7; // "L/C/R/SL/SR" break; default: hal_info("%s: unknown ch_layout 0x%" PRIx64 "\n", - __func__, c->channel_layout); + __func__, c->channel_layout); } } } hal_debug("%s t: %d l: %d f: %d b: %d m: %d codec_id: %x\n", - __func__, type, layer, freq, bitrate, mode, c?c->codec_id:-1); + __func__, type, layer, freq, bitrate, mode, c ? c->codec_id : -1); }; void cAudio::SetSRS(int /*iq_enable*/, int /*nmgr_enable*/, int /*iq_mode*/, int /*iq_level*/) @@ -310,8 +316,10 @@ static int _my_read(void *, uint8_t *buf, int buf_size) int cAudio::my_read(uint8_t *buf, int buf_size) { int tmp = 0; - if (audioDecoder && bufpos < DMX_BUF_SZ - 4096) { - while (bufpos < buf_size && ++tmp < 20) { /* retry max 20 times */ + if (audioDecoder && bufpos < DMX_BUF_SZ - 4096) + { + while (bufpos < buf_size && ++tmp < 20) /* retry max 20 times */ + { int ret = audioDemux->Read(dmxbuf + bufpos, DMX_BUF_SZ - bufpos, 10); if (ret > 0) bufpos += ret; @@ -322,7 +330,8 @@ int cAudio::my_read(uint8_t *buf, int buf_size) if (bufpos == 0) return 0; //hal_info("%s buf_size %d bufpos %d th %d tmp %d\n", __func__, buf_size, bufpos, thread_started, tmp); - if (bufpos > buf_size) { + if (bufpos > buf_size) + { memcpy(buf, dmxbuf, buf_size); memmove(dmxbuf, dmxbuf + buf_size, bufpos - buf_size); bufpos -= buf_size; @@ -367,18 +376,19 @@ void cAudio::run() av_init_packet(&avpkt); inp = av_find_input_format("mpegts"); AVIOContext *pIOCtx = avio_alloc_context(inbuf, INBUF_SIZE, // internal Buffer and its size - 0, // bWriteable (1=true,0=false) - NULL, // user data; will be passed to our callback functions - _my_read, // read callback - NULL, // write callback - NULL); // seek callback + 0, // bWriteable (1=true,0=false) + NULL, // user data; will be passed to our callback functions + _my_read, // read callback + NULL, // write callback + NULL); // seek callback avfc = avformat_alloc_context(); avfc->pb = pIOCtx; avfc->iformat = inp; - avfc->probesize = 188*5; + avfc->probesize = 188 * 5; thread_started = true; - if (avformat_open_input(&avfc, NULL, inp, NULL) < 0) { + if (avformat_open_input(&avfc, NULL, inp, NULL) < 0) + { hal_info("%s: avformat_open_input() failed.\n", __func__); goto out; } @@ -394,31 +404,35 @@ void cAudio::run() hal_info("%s: stream 0 no audio codec? 0x%x\n", __func__, p->codec_type); codec = avcodec_find_decoder(p->codec_id); - if (!codec) { + if (!codec) + { hal_info("%s: Codec for %s not found\n", __func__, avcodec_get_name(p->codec_id)); goto out; } if (c) av_free(c); c = avcodec_alloc_context3(codec); - if (avcodec_open2(c, codec, NULL) < 0) { + if (avcodec_open2(c, codec, NULL) < 0) + { hal_info("%s: avcodec_open2() failed\n", __func__); goto out; } - if(p->sample_rate == 0 || p->channels == 0){ + if (p->sample_rate == 0 || p->channels == 0) + { av_get_sample_fmt_string(tmp, sizeof(tmp), c->sample_fmt); - hal_info("Header missing %s, sample_fmt %d (%s) sample_rate %d channels %d\n",avcodec_get_name(p->codec_id), c->sample_fmt, tmp, p->sample_rate, p->channels); + hal_info("Header missing %s, sample_fmt %d (%s) sample_rate %d channels %d\n", avcodec_get_name(p->codec_id), c->sample_fmt, tmp, p->sample_rate, p->channels); goto out2; } frame = av_frame_alloc(); - if (!frame) { + if (!frame) + { hal_info("%s: av_frame_alloc failed\n", __func__); goto out2; } /* output sample rate, channels, layout could be set here if necessary */ - o_ch = p->channels; /* 2 */ - o_sr = p->sample_rate; /* 48000 */ - o_layout = p->channel_layout; /* AV_CH_LAYOUT_STEREO */ + o_ch = p->channels; /* 2 */ + o_sr = p->sample_rate; /* 48000 */ + o_layout = p->channel_layout; /* AV_CH_LAYOUT_STEREO */ if (sformat.channels != o_ch || sformat.rate != o_sr || sformat.byte_format != AO_FMT_NATIVE || sformat.bits != 16 || adevice == NULL) { @@ -433,10 +447,10 @@ void cAudio::run() adevice = ao_open_live(driver, &sformat, NULL); ai = ao_driver_info(driver); hal_info("%s: changed params ch %d srate %d bits %d adevice %p\n", - __func__, o_ch, o_sr, 16, adevice); - if(ai) + __func__, o_ch, o_sr, 16, adevice); + if (ai) hal_info("libao driver: %d name '%s' short '%s' author '%s'\n", - driver, ai->name, ai->short_name, ai->author); + driver, ai->name, ai->short_name, ai->author); } #if 0 hal_info(" driver options:"); @@ -446,17 +460,19 @@ void cAudio::run() #endif av_get_sample_fmt_string(tmp, sizeof(tmp), c->sample_fmt); hal_info("decoding %s, sample_fmt %d (%s) sample_rate %d channels %d\n", - avcodec_get_name(p->codec_id), c->sample_fmt, tmp, p->sample_rate, p->channels); + avcodec_get_name(p->codec_id), c->sample_fmt, tmp, p->sample_rate, p->channels); swr = swr_alloc_set_opts(swr, - o_layout, AV_SAMPLE_FMT_S16, o_sr, /* output */ - p->channel_layout, c->sample_fmt, p->sample_rate, /* input */ - 0, NULL); - if (! swr) { + o_layout, AV_SAMPLE_FMT_S16, o_sr, /* output */ + p->channel_layout, c->sample_fmt, p->sample_rate, /* input */ + 0, NULL); + if (! swr) + { hal_info("could not alloc resample context\n"); goto out3; } swr_init(swr); - while (thread_started) { + while (thread_started) + { int gotframe = 0; if (av_read_frame(avfc, &avpkt) < 0) break; @@ -464,26 +480,35 @@ void cAudio::run() avcodec_decode_audio4(c, frame, &gotframe, &avpkt); #else av_ret = avcodec_send_packet(c, &avpkt); - if (av_ret != 0 && av_ret != AVERROR(EAGAIN)) { + if (av_ret != 0 && av_ret != AVERROR(EAGAIN)) + { hal_info("%s: avcodec_send_packet %d\n", __func__, av_ret); - }else { + } + else + { av_ret = avcodec_receive_frame(c, frame); - if (av_ret != 0 && av_ret != AVERROR(EAGAIN)) { + if (av_ret != 0 && av_ret != AVERROR(EAGAIN)) + { hal_info("%s: avcodec_send_packet %d\n", __func__, av_ret); - }else { + } + else + { gotframe = 1; } } #endif - if (gotframe && thread_started) { + if (gotframe && thread_started) + { int out_linesize; obuf_sz = av_rescale_rnd(swr_get_delay(swr, p->sample_rate) + frame->nb_samples, o_sr, p->sample_rate, AV_ROUND_UP); - if (obuf_sz > obuf_sz_max) { + if (obuf_sz > obuf_sz_max) + { hal_info("obuf_sz: %d old: %d\n", obuf_sz, obuf_sz_max); av_free(obuf); if (av_samples_alloc(&obuf, &out_linesize, o_ch, - frame->nb_samples, AV_SAMPLE_FMT_S16, 1) < 0) { + frame->nb_samples, AV_SAMPLE_FMT_S16, 1) < 0) + { hal_info("av_samples_alloc failed\n"); av_packet_unref(&avpkt); break; /* while (thread_started) */ @@ -491,13 +516,13 @@ void cAudio::run() obuf_sz_max = obuf_sz; } obuf_sz = swr_convert(swr, &obuf, obuf_sz, - (const uint8_t **)frame->extended_data, frame->nb_samples); + (const uint8_t **)frame->extended_data, frame->nb_samples); #if (LIBAVUTIL_VERSION_MAJOR < 54) curr_pts = av_frame_get_best_effort_timestamp(frame); #else curr_pts = frame->best_effort_timestamp; #endif - hal_debug("%s: pts 0x%" PRIx64 " %3f\n", __func__, curr_pts, curr_pts/90000.0); + hal_debug("%s: pts 0x%" PRIx64 " %3f\n", __func__, curr_pts, curr_pts / 90000.0); int o_buf_sz = av_samples_get_buffer_size(&out_linesize, o_ch, obuf_sz, AV_SAMPLE_FMT_S16, 1); if (o_buf_sz > 0) ao_play(adevice, (char *)obuf, o_buf_sz); @@ -507,13 +532,13 @@ void cAudio::run() // ao_close(adevice); /* can take long :-( */ av_free(obuf); swr_free(&swr); - out3: +out3: av_frame_free(&frame); - out2: +out2: avcodec_close(c); av_free(c); c = NULL; - out: +out: avformat_close_input(&avfc); av_free(pIOCtx->buffer); av_free(pIOCtx); diff --git a/libgeneric-pc/audio_lib.h b/libgeneric-pc/audio_lib.h index 0d0a24e..1712c5d 100644 --- a/libgeneric-pc/audio_lib.h +++ b/libgeneric-pc/audio_lib.h @@ -14,7 +14,8 @@ typedef enum AUDIO_SYNC_AUDIO_MASTER } AUDIO_SYNC_MODE; -typedef enum { +typedef enum +{ HDMI_ENCODED_OFF, HDMI_ENCODED_AUTO, HDMI_ENCODED_FORCED @@ -40,7 +41,7 @@ typedef enum class cAudio : public OpenThreads::Thread { - friend class cPlayback; + friend class cPlayback; private: int fd; bool Muted; @@ -49,7 +50,7 @@ class cAudio : public OpenThreads::Thread int mixer_fd; /* if we are using the OSS mixer */ int mixer_num; /* oss mixer to use, if any */ - int StreamType; + int StreamType; AUDIO_SYNC_MODE SyncMode; bool started; bool thread_started; @@ -68,32 +69,53 @@ class cAudio : public OpenThreads::Thread /* construct & destruct */ cAudio(void *, void *, void *); ~cAudio(void); - int64_t getPts() { return curr_pts; } + int64_t getPts() + { + return curr_pts; + } - void *GetHandle() { return NULL; }; + void *GetHandle() + { + return NULL; + }; /* shut up */ - int mute(bool remember = true) { return do_mute(true, remember); }; - int unmute(bool remember = true) { return do_mute(false, remember); }; + int mute(bool remember = true) + { + return do_mute(true, remember); + }; + int unmute(bool remember = true) + { + return do_mute(false, remember); + }; /* volume, min = 0, max = 255 */ int setVolume(unsigned int left, unsigned int right); - int getVolume(void) { return volume;} - bool getMuteStatus(void) { return Muted; }; + int getVolume(void) + { + return volume; + } + bool getMuteStatus(void) + { + return Muted; + }; /* start and stop audio */ int Start(void); int Stop(void); bool Pause(bool Pcm = true); void SetStreamType(int bypass); - int GetStreamType(void) { return StreamType; } + int GetStreamType(void) + { + return StreamType; + } void SetSyncMode(AVSYNC_TYPE Mode); /* select channels */ int setChannel(int channel); int PrepareClipPlay(int uNoOfChannels, int uSampleRate, int uBitsPerSample, int bLittleEndian); - int WriteClip(unsigned char * buffer, int size); + int WriteClip(unsigned char *buffer, int size); int StopClip(); - void getAudioInfo(int &type, int &layer, int& freq, int &bitrate, int &mode); + void getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode); void SetSRS(int iq_enable, int nmgr_enable, int iq_mode, int iq_level); bool IsHdmiDDSupported(); void SetHdmiDD(bool enable); diff --git a/libgeneric-pc/clutterfb.cpp b/libgeneric-pc/clutterfb.cpp index c402c16..f1bb790 100644 --- a/libgeneric-pc/clutterfb.cpp +++ b/libgeneric-pc/clutterfb.cpp @@ -1,25 +1,25 @@ /* - Framebuffer implementation using clutter https://developer.gnome.org/clutter/ - Copyright (C) 2016 Stefan Seyfried + Framebuffer implementation using clutter https://developer.gnome.org/clutter/ + Copyright (C) 2016 Stefan Seyfried - based on the openGL framebuffer implementation - Copyright 2010 Carsten Juttner - Copyright 2012,2013 Stefan Seyfried + based on the openGL framebuffer implementation + Copyright 2010 Carsten Juttner + Copyright 2012,2013 Stefan Seyfried - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . - TODO: AV-Sync code is "experimental" at best + TODO: AV-Sync code is "experimental" at best */ #include "config.h" @@ -92,8 +92,8 @@ GLFbPC::GLFbPC(int x, int y, std::vector &buf): mReInit(true), mS *mX = x; *mY = y; av_reduce(&mOA.num, &mOA.den, x, y, INT_MAX); - mVA = mOA; /* initial aspect ratios are from the FB resolution, those */ - _mVA = mVA; /* will be updated by the videoDecoder functions anyway */ + mVA = mOA; /* initial aspect ratios are from the FB resolution, those */ + _mVA = mVA; /* will be updated by the videoDecoder functions anyway */ mVAchanged = true; mCrop = DISPLAY_AR_MODE_PANSCAN; zoom = 1.0; @@ -121,7 +121,7 @@ GLFbPC::GLFbPC(int x, int y, std::vector &buf): mReInit(true), mS unlink("/tmp/neutrino.input"); mkfifo("/tmp/neutrino.input", 0600); - input_fd = open("/tmp/neutrino.input", O_RDWR|O_CLOEXEC|O_NONBLOCK); + input_fd = open("/tmp/neutrino.input", O_RDWR | O_CLOEXEC | O_NONBLOCK); if (input_fd < 0) hal_info("%s: could not open /tmp/neutrino.input FIFO: %m\n", __func__); initKeys(); @@ -214,7 +214,8 @@ void GLFramebuffer::run() argv[0] = a; argv[1] = NULL; hal_info("GLFB: GL thread starting x %d y %d\n", x, y); - if (clutter_init(&argc, &argv) != CLUTTER_INIT_SUCCESS) { + if (clutter_init(&argc, &argv) != CLUTTER_INIT_SUCCESS) + { hal_info("GLFB: error initializing clutter\n"); free(argv); return; @@ -228,7 +229,7 @@ void GLFramebuffer::run() //g_signal_connect(stage, "destroy", G_CALLBACK(clutter_main_quit), NULL); g_signal_connect(stage, "key-press-event", G_CALLBACK(GLFbPC::keyboardcb), (void *)1); g_signal_connect(stage, "key-release-event", G_CALLBACK(GLFbPC::keyboardcb), NULL); - clutter_stage_set_user_resizable(CLUTTER_STAGE (stage), TRUE); + clutter_stage_set_user_resizable(CLUTTER_STAGE(stage), TRUE); clutter_actor_grab_key_focus(stage); clutter_actor_show(stage); @@ -241,7 +242,8 @@ void GLFramebuffer::run() vid_actor = clutter_actor_new(); ClutterContent *fb = clutter_image_new(); /* osd_buf, because it starts up black */ - if (!clutter_image_set_data(CLUTTER_IMAGE(fb), osd_buf.data(), COGL_PIXEL_FORMAT_BGR_888, x, y, x*3, NULL)) { + if (!clutter_image_set_data(CLUTTER_IMAGE(fb), osd_buf.data(), COGL_PIXEL_FORMAT_BGR_888, x, y, x * 3, NULL)) + { hal_info("GLFB::%s clutter_image_set_data failed? (vid)\n", __func__); _exit(1); /* life is hard */ } @@ -260,7 +262,8 @@ void GLFramebuffer::run() fb_actor = clutter_actor_new(); fb = clutter_image_new(); - if (!clutter_image_set_data(CLUTTER_IMAGE(fb), osd_buf.data(), COGL_PIXEL_FORMAT_BGRA_8888, x, y, x*4, NULL)) { + if (!clutter_image_set_data(CLUTTER_IMAGE(fb), osd_buf.data(), COGL_PIXEL_FORMAT_BGRA_8888, x, y, x * 4, NULL)) + { hal_info("GLFB::%s clutter_image_set_data failed? (osd)\n", __func__); _exit(1); /* life is hard */ } @@ -293,14 +296,14 @@ void GLFramebuffer::run() /* static */ bool GLFbPC::keyboardcb(ClutterActor * /*actor*/, ClutterEvent *event, gpointer user_data) { - guint key = clutter_event_get_key_symbol (event); + guint key = clutter_event_get_key_symbol(event); int keystate = user_data ? 1 : 0; hal_info_c("GLFB::%s: 0x%x, %d\n", __func__, key, keystate); struct input_event ev; if (key == 'f' && keystate) { - hal_info_c("GLFB::%s: toggle fullscreen %s\n", __func__, glfb_priv->mFullscreen?"off":"on"); + hal_info_c("GLFB::%s: toggle fullscreen %s\n", __func__, glfb_priv->mFullscreen ? "off" : "on"); glfb_priv->mFullscreen = !(glfb_priv->mFullscreen); glfb_priv->mReInit = true; return true; @@ -314,7 +317,7 @@ void GLFramebuffer::run() gettimeofday(&ev.time, NULL); hal_debug_c("GLFB::%s: pushing 0x%x\n", __func__, ev.code); ssize_t w = write(glfb_priv->input_fd, &ev, sizeof(ev)); - if(w < 0) + if (w < 0) return false; return true; } @@ -323,7 +326,7 @@ int sleep_us = 30000; void GLFbPC::render() { - if(mShutDown) + if (mShutDown) clutter_main_quit(); mReInitLock.lock(); @@ -338,22 +341,26 @@ void GLFbPC::render() mY = &_mY[mFullscreen]; #endif *mX = *mY * mOA.num / mOA.den; - if (mFullscreen) { + if (mFullscreen) + { clutter_stage_set_fullscreen(CLUTTER_STAGE(stage), TRUE); clutter_actor_show(stage); clutter_stage_ensure_redraw(CLUTTER_STAGE(stage)); - } else { + } + else + { clutter_stage_set_fullscreen(CLUTTER_STAGE(stage), FALSE); // *mX = *mY * mOA.num / mOA.den; clutter_actor_set_size(stage, *mX, *mY); } hal_info("%s: reinit mX:%d mY:%d xoff:%d yoff:%d fs %d\n", - __func__, *mX, *mY, xoff, yoff, mFullscreen); + __func__, *mX, *mY, xoff, yoff, mFullscreen); } mReInitLock.unlock(); bltDisplayBuffer(); /* decoded video stream */ - if (mState.blit) { + if (mState.blit) + { /* only blit manually after fb->blit(), this helps to find missed blit() calls */ mState.blit = false; hal_debug("GLFB::%s blit!\n", __func__); @@ -368,15 +375,17 @@ void GLFbPC::render() //xscale = 1.0; int cmp = av_cmp_q(mVA, mOA); const AVRational a149 = { 14, 9 }; - switch (cmp) { + switch (cmp) + { default: - case INT_MIN: /* invalid */ - case 0: /* identical */ + case INT_MIN: /* invalid */ + case 0: /* identical */ hal_debug("%s: mVA == mOA (or fullscreen mode :-)\n", __func__); break; - case 1: /* mVA > mOA -- video is wider than display */ + case 1: /* mVA > mOA -- video is wider than display */ hal_debug("%s: mVA > mOA\n", __func__); - switch (mCrop) { + switch (mCrop) + { case DISPLAY_AR_MODE_PANSCAN: zoom = av_q2d(mVA) / av_q2d(mOA); break; @@ -393,18 +402,20 @@ void GLFbPC::render() break; } break; - case -1: /* mVA < mOA -- video is taller than display */ + case -1: /* mVA < mOA -- video is taller than display */ hal_debug("%s: mVA < mOA\n", __func__); - switch (mCrop) { + switch (mCrop) + { case DISPLAY_AR_MODE_LETTERBOX: break; case DISPLAY_AR_MODE_PANSCAN2: - if (av_cmp_q(a149, mOA) < 0) { + if (av_cmp_q(a149, mOA) < 0) + { zoom = av_q2d(mVA) * av_q2d(a149) / av_q2d(mOA); break; } - // fall through - /* fallthrough for output format 14:9 */ + // fall through + /* fallthrough for output format 14:9 */ case DISPLAY_AR_MODE_PANSCAN: zoom = av_q2d(mOA) / av_q2d(mVA); break; @@ -416,11 +427,11 @@ void GLFbPC::render() } break; } - hal_debug("zoom: %f xscale: %f xzoom: %f\n", zoom, xscale,xzoom); - clutter_actor_set_scale(vid_actor, xscale*zoom*xzoom, zoom); + hal_debug("zoom: %f xscale: %f xzoom: %f\n", zoom, xscale, xzoom); + clutter_actor_set_scale(vid_actor, xscale * zoom * xzoom, zoom); } clutter_timeline_stop(tl); - clutter_timeline_set_delay(tl, sleep_us/1000); + clutter_timeline_set_delay(tl, sleep_us / 1000); clutter_timeline_start(tl); } @@ -430,7 +441,8 @@ void GLFbPC::bltOSDBuffer() int x = glfb_priv->mState.width; int y = glfb_priv->mState.height; ClutterContent *fb = clutter_image_new(); - if (!clutter_image_set_data(CLUTTER_IMAGE(fb), osd_buf->data(), COGL_PIXEL_FORMAT_BGRA_8888, x, y, x*4, NULL)) { + if (!clutter_image_set_data(CLUTTER_IMAGE(fb), osd_buf->data(), COGL_PIXEL_FORMAT_BGRA_8888, x, y, x * 4, NULL)) + { hal_info("GLFB::%s clutter_image_set_data failed?\n", __func__); _exit(1); /* life is hard */ } @@ -446,7 +458,8 @@ void GLFbPC::bltDisplayBuffer() return; static bool warn = true; cVideo::SWFramebuffer *buf = videoDecoder->getDecBuf(); - if (!buf) { + if (!buf) + { if (warn) hal_info("GLFB::%s did not get a buffer...\n", __func__); warn = false; @@ -458,18 +471,20 @@ void GLFbPC::bltDisplayBuffer() return; AVRational a = buf->AR(); - if (a.den != 0 && a.num != 0 && av_cmp_q(a, _mVA)) { + if (a.den != 0 && a.num != 0 && av_cmp_q(a, _mVA)) + { _mVA = a; /* _mVA is the raw buffer's aspect, mVA is the real scaled output aspect */ av_reduce(&mVA.num, &mVA.den, w * a.num, h * a.den, INT_MAX); // mVA.num: 16 mVA.den: 9 w: 720 h: 576 // 16*576/720/9 = 1.42222 - xscale = (double)mVA.num*h/(double)mVA.den/w; + xscale = (double)mVA.num * h / (double)mVA.den / w; mVAchanged = true; } ClutterContent *fb = clutter_image_new(); - if (!clutter_image_set_data(CLUTTER_IMAGE(fb), &(*buf)[0], COGL_PIXEL_FORMAT_BGR_888, w, h, w*3, NULL)) { + if (!clutter_image_set_data(CLUTTER_IMAGE(fb), &(*buf)[0], COGL_PIXEL_FORMAT_BGR_888, w, h, w * 3, NULL)) + { hal_info("GLFB::%s clutter_image_set_data failed?\n", __func__); _exit(1); /* life is hard */ } @@ -484,10 +499,11 @@ void GLFbPC::bltDisplayBuffer() int64_t vpts = buf->pts(); if (audioDecoder) apts = audioDecoder->getPts(); - if (apts != last_apts) { + if (apts != last_apts) + { int rate, dummy1, dummy2; if (apts < vpts) - sleep_us = (sleep_us * 2 + (vpts - apts)*10/9) / 3; + sleep_us = (sleep_us * 2 + (vpts - apts) * 10 / 9) / 3; else if (sleep_us > 1000) sleep_us -= 1000; last_apts = apts; @@ -502,5 +518,5 @@ void GLFbPC::bltDisplayBuffer() sleep_us = 1; } hal_debug("vpts: 0x%" PRIx64 " apts: 0x%" PRIx64 " diff: %6.3f sleep_us %d buf %d\n", - buf->pts(), apts, (buf->pts() - apts)/90000.0, sleep_us, videoDecoder->buf_num); + buf->pts(), apts, (buf->pts() - apts) / 90000.0, sleep_us, videoDecoder->buf_num); } diff --git a/libgeneric-pc/dmx.cpp b/libgeneric-pc/dmx.cpp index 46fddea..b3c8d68 100644 --- a/libgeneric-pc/dmx.cpp +++ b/libgeneric-pc/dmx.cpp @@ -44,15 +44,16 @@ extern cVideo *videoDecoder; #define hal_info_c(args...) _hal_info(HAL_DEBUG_DEMUX, NULL, args) #define dmx_err(_errfmt, _errstr, _revents) do { \ - hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ -} while(0); + hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ + __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ + } while(0); cDemux *videoDemux = NULL; cDemux *audioDemux = NULL; //cDemux *pcrDemux = NULL; -static const char *DMX_T[] = { +static const char *DMX_T[] = +{ "DMX_INVALID", "DMX_VIDEO", "DMX_AUDIO", @@ -64,7 +65,8 @@ static const char *DMX_T[] = { }; /* map the device numbers. for now only demux0 is used */ -static const char *devname[] = { +static const char *devname[] = +{ "/dev/dvb/adapter0/demux0", "/dev/dvb/adapter0/demux0", "/dev/dvb/adapter0/demux0" @@ -97,7 +99,7 @@ cDemux::~cDemux() bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBufferSize) { int devnum = num; - int flags = O_RDWR|O_CLOEXEC; + int flags = O_RDWR | O_CLOEXEC; if (fd > -1) hal_info("%s FD ALREADY OPENED? fd = %d\n", __FUNCTION__, fd); @@ -112,12 +114,12 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe return false; } hal_debug("%s #%d pes_type: %s(%d), uBufferSize: %d fd: %d\n", __func__, - num, DMX_T[pes_type], pes_type, uBufferSize, fd); + num, DMX_T[pes_type], pes_type, uBufferSize, fd); if (dmx_type == DMX_VIDEO_CHANNEL) - uBufferSize = 0x100000; /* 1MB */ + uBufferSize = 0x100000; /* 1MB */ if (dmx_type == DMX_AUDIO_CHANNEL) - uBufferSize = 0x10000; /* 64k */ + uBufferSize = 0x10000; /* 64k */ #if 0 if (!pesfds.empty()) { @@ -191,17 +193,17 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) #if 0 if (len != 4095 && timeout != 100) fprintf(stderr, "cDemux::%s #%d fd: %d type: %s len: %d timeout: %d\n", - __FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout); + __FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout); #endif int rc; struct pollfd ufds; ufds.fd = fd; - ufds.events = POLLIN|POLLPRI|POLLERR; + ufds.events = POLLIN | POLLPRI | POLLERR; ufds.revents = 0; if (timeout > 0) { - retry: +retry: rc = ::poll(&ufds, 1, timeout); if (!rc) return 0; // timeout @@ -242,9 +244,9 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return rc; } -bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, - const unsigned char * const mask, int len, int timeout, - const unsigned char * const negmask) +bool cDemux::sectionFilter(unsigned short _pid, const unsigned char *const filter, + const unsigned char *const mask, int len, int timeout, + const unsigned char *const negmask) { struct dmx_sct_filter_params s_flt; memset(&s_flt, 0, sizeof(s_flt)); @@ -263,79 +265,80 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt if (negmask != NULL) memcpy(s_flt.filter.mode, negmask, len); - s_flt.flags = DMX_IMMEDIATE_START|DMX_CHECK_CRC; + s_flt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; int to = 0; - switch (filter[0]) { - case 0x00: /* program_association_section */ - to = 2000; - break; - case 0x01: /* conditional_access_section */ - to = 6000; - break; - case 0x02: /* program_map_section */ - to = 1500; - break; - case 0x03: /* transport_stream_description_section */ - to = 10000; - break; - /* 0x04 - 0x3F: reserved */ - case 0x40: /* network_information_section - actual_network */ - to = 10000; - break; - case 0x41: /* network_information_section - other_network */ - to = 15000; - break; - case 0x42: /* service_description_section - actual_transport_stream */ - to = 10000; - break; - /* 0x43 - 0x45: reserved for future use */ - case 0x46: /* service_description_section - other_transport_stream */ - to = 10000; - break; - /* 0x47 - 0x49: reserved for future use */ - case 0x4A: /* bouquet_association_section */ - to = 11000; - break; - /* 0x4B - 0x4D: reserved for future use */ - case 0x4E: /* event_information_section - actual_transport_stream, present/following */ - to = 2000; - break; - case 0x4F: /* event_information_section - other_transport_stream, present/following */ - to = 10000; - break; - /* 0x50 - 0x5F: event_information_section - actual_transport_stream, schedule */ - /* 0x60 - 0x6F: event_information_section - other_transport_stream, schedule */ - case 0x70: /* time_date_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - //s_flt.pid = 0x0014; - to = 30000; - break; - case 0x71: /* running_status_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - to = 0; - break; - case 0x72: /* stuffing_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - to = 0; - break; - case 0x73: /* time_offset_section */ - //s_flt.pid = 0x0014; - to = 30000; - break; - /* 0x74 - 0x7D: reserved for future use */ - case 0x7E: /* discontinuity_information_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - to = 0; - break; - case 0x7F: /* selection_information_section */ - to = 0; - break; - /* 0x80 - 0x8F: ca_message_section */ - /* 0x90 - 0xFE: user defined */ - /* 0xFF: reserved */ - default: - break; + switch (filter[0]) + { + case 0x00: /* program_association_section */ + to = 2000; + break; + case 0x01: /* conditional_access_section */ + to = 6000; + break; + case 0x02: /* program_map_section */ + to = 1500; + break; + case 0x03: /* transport_stream_description_section */ + to = 10000; + break; + /* 0x04 - 0x3F: reserved */ + case 0x40: /* network_information_section - actual_network */ + to = 10000; + break; + case 0x41: /* network_information_section - other_network */ + to = 15000; + break; + case 0x42: /* service_description_section - actual_transport_stream */ + to = 10000; + break; + /* 0x43 - 0x45: reserved for future use */ + case 0x46: /* service_description_section - other_transport_stream */ + to = 10000; + break; + /* 0x47 - 0x49: reserved for future use */ + case 0x4A: /* bouquet_association_section */ + to = 11000; + break; + /* 0x4B - 0x4D: reserved for future use */ + case 0x4E: /* event_information_section - actual_transport_stream, present/following */ + to = 2000; + break; + case 0x4F: /* event_information_section - other_transport_stream, present/following */ + to = 10000; + break; + /* 0x50 - 0x5F: event_information_section - actual_transport_stream, schedule */ + /* 0x60 - 0x6F: event_information_section - other_transport_stream, schedule */ + case 0x70: /* time_date_section */ + s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ + //s_flt.pid = 0x0014; + to = 30000; + break; + case 0x71: /* running_status_section */ + s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ + to = 0; + break; + case 0x72: /* stuffing_section */ + s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ + to = 0; + break; + case 0x73: /* time_offset_section */ + //s_flt.pid = 0x0014; + to = 30000; + break; + /* 0x74 - 0x7D: reserved for future use */ + case 0x7E: /* discontinuity_information_section */ + s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ + to = 0; + break; + case 0x7F: /* selection_information_section */ + to = 0; + break; + /* 0x80 - 0x8F: ca_message_section */ + /* 0x90 - 0xFE: user defined */ + /* 0xFF: reserved */ + default: + break; // return -1; } /* the negmask == NULL is a hack: the users of negmask are PMT-update @@ -345,15 +348,22 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt s_flt.timeout = to; hal_debug("%s #%d pid:0x%04hx fd:%d type:%s len:%d to:%d flags:%x flt[0]:%02x\n", __func__, num, - pid, fd, DMX_T[dmx_type], len, s_flt.timeout,s_flt.flags, s_flt.filter.filter[0]); + pid, fd, DMX_T[dmx_type], len, s_flt.timeout, s_flt.flags, s_flt.filter.filter[0]); - if (debuglevel == 2) { - fprintf(stderr,"filt: ");for(int i=0;i= 0x0002 && pid <= 0x000f) || pid >= 0x1fff) return false; @@ -381,35 +391,36 @@ bool cDemux::pesFilter(const unsigned short _pid) p_flt.output = DMX_OUT_DECODER; p_flt.input = DMX_IN_FRONTEND; - switch (dmx_type) { - case DMX_PCR_ONLY_CHANNEL: - p_flt.pes_type = DMX_PES_PCR; - if (HAL_nodec) - return true; - break; - case DMX_AUDIO_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TSDEMUX_TAP; - if (HAL_nodec) /* no need to demux if we don't decode... */ - return true; - break; - case DMX_VIDEO_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TSDEMUX_TAP; - if (HAL_nodec) - return true; - break; - case DMX_PES_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TAP; - break; - case DMX_TP_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TSDEMUX_TAP; - break; - default: - hal_info("%s #%d invalid dmx_type %d!\n", __func__, num, dmx_type); - return false; + switch (dmx_type) + { + case DMX_PCR_ONLY_CHANNEL: + p_flt.pes_type = DMX_PES_PCR; + if (HAL_nodec) + return true; + break; + case DMX_AUDIO_CHANNEL: + p_flt.pes_type = DMX_PES_OTHER; + p_flt.output = DMX_OUT_TSDEMUX_TAP; + if (HAL_nodec) /* no need to demux if we don't decode... */ + return true; + break; + case DMX_VIDEO_CHANNEL: + p_flt.pes_type = DMX_PES_OTHER; + p_flt.output = DMX_OUT_TSDEMUX_TAP; + if (HAL_nodec) + return true; + break; + case DMX_PES_CHANNEL: + p_flt.pes_type = DMX_PES_OTHER; + p_flt.output = DMX_OUT_TAP; + break; + case DMX_TP_CHANNEL: + p_flt.pes_type = DMX_PES_OTHER; + p_flt.output = DMX_OUT_TSDEMUX_TAP; + break; + default: + hal_info("%s #%d invalid dmx_type %d!\n", __func__, num, dmx_type); + return false; } return (ioctl(fd, DMX_SET_PES_FILTER, &p_flt) >= 0); } @@ -461,7 +472,8 @@ void cDemux::removePid(unsigned short Pid) } for (std::vector::iterator i = pesfds.begin(); i != pesfds.end(); ++i) { - if ((*i).pid == Pid) { + if ((*i).pid == Pid) + { hal_debug("removePid: removing demux fd %d pid 0x%04x\n", fd, Pid); if (ioctl(fd, DMX_REMOVE_PID, Pid) < 0) hal_info("%s: (DMX_REMOVE_PID, 0x%04hx): %m\n", __func__, Pid); @@ -472,7 +484,7 @@ void cDemux::removePid(unsigned short Pid) hal_info("%s pid 0x%04x not found\n", __FUNCTION__, Pid); } -void cDemux::getSTC(int64_t * STC) +void cDemux::getSTC(int64_t *STC) { int64_t pts = 0; if (videoDecoder) diff --git a/libgeneric-pc/glfb.cpp b/libgeneric-pc/glfb.cpp index 2ce0fc8..74e3e80 100644 --- a/libgeneric-pc/glfb.cpp +++ b/libgeneric-pc/glfb.cpp @@ -1,25 +1,25 @@ /* - Copyright 2010 Carsten Juttner - Copyright 2012,2013 Stefan Seyfried + Copyright 2010 Carsten Juttner + Copyright 2012,2013 Stefan Seyfried - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . - openGL based framebuffer implementation - based on Carjay's neutrino-hd-dvbapi work, see - http://gitorious.org/neutrino-hd/neutrino-hd-dvbapi + openGL based framebuffer implementation + based on Carjay's neutrino-hd-dvbapi work, see + http://gitorious.org/neutrino-hd/neutrino-hd-dvbapi - TODO: AV-Sync code is "experimental" at best + TODO: AV-Sync code is "experimental" at best */ #include "config.h" @@ -90,8 +90,8 @@ GLFbPC::GLFbPC(int x, int y, std::vector &buf): mReInit(true), mS *mX = x; *mY = y; av_reduce(&mOA.num, &mOA.den, x, y, INT_MAX); - mVA = mOA; /* initial aspect ratios are from the FB resolution, those */ - _mVA = mVA; /* will be updated by the videoDecoder functions anyway */ + mVA = mOA; /* initial aspect ratios are from the FB resolution, those */ + _mVA = mVA; /* will be updated by the videoDecoder functions anyway */ mVAchanged = true; mCrop = DISPLAY_AR_MODE_PANSCAN; zoom = 1.0; @@ -119,7 +119,7 @@ GLFbPC::GLFbPC(int x, int y, std::vector &buf): mReInit(true), mS unlink("/tmp/neutrino.input"); mkfifo("/tmp/neutrino.input", 0600); - input_fd = open("/tmp/neutrino.input", O_RDWR|O_CLOEXEC|O_NONBLOCK); + input_fd = open("/tmp/neutrino.input", O_RDWR | O_CLOEXEC | O_NONBLOCK); if (input_fd < 0) hal_info("%s: could not open /tmp/neutrino.input FIFO: %m\n", __func__); initKeys(); @@ -221,12 +221,12 @@ void GLFramebuffer::run() /* init the good stuff */ GLenum err = glewInit(); - if(err == GLEW_OK) + if (err == GLEW_OK) { - if((!GLEW_VERSION_1_5)||(!GLEW_EXT_pixel_buffer_object)||(!GLEW_ARB_texture_non_power_of_two)) + if ((!GLEW_VERSION_1_5) || (!GLEW_EXT_pixel_buffer_object) || (!GLEW_ARB_texture_non_power_of_two)) { hal_info("GLFB: Sorry, your graphics card is not supported. " - "Needs at least OpenGL 1.5, pixel buffer objects and NPOT textures.\n"); + "Needs at least OpenGL 1.5, pixel buffer objects and NPOT textures.\n"); hal_info("incompatible graphics card: %m"); _exit(1); /* Life is hard */ } @@ -262,7 +262,8 @@ void GLFbPC::setupCtx() } void GLFbPC::setupOSDBuffer() -{ /* the OSD buffer size can be decoupled from the actual +{ + /* the OSD buffer size can be decoupled from the actual window size since the GL can blit-stretch with no trouble at all, ah, the luxury of ignorance... */ // mMutex.lock(); @@ -325,7 +326,7 @@ void GLFbPC::releaseGLObjects() struct input_event ev; if (key == 'f') { - hal_info_c("GLFB::%s: toggle fullscreen %s\n", __func__, glfb_priv->mFullscreen?"off":"on"); + hal_info_c("GLFB::%s: toggle fullscreen %s\n", __func__, glfb_priv->mFullscreen ? "off" : "on"); glfb_priv->mFullscreen = !(glfb_priv->mFullscreen); glfb_priv->mReInit = true; return; @@ -364,7 +365,7 @@ int sleep_us = 30000; void GLFbPC::render() { - if(mShutDown) + if (mShutDown) glutLeaveMainLoop(); mReInitLock.lock(); @@ -376,7 +377,8 @@ void GLFbPC::render() mReInit = false; mX = &_mX[mFullscreen]; mY = &_mY[mFullscreen]; - if (mFullscreen) { + if (mFullscreen) + { int x = glutGet(GLUT_SCREEN_WIDTH); int y = glutGet(GLUT_SCREEN_HEIGHT); *mX = x; @@ -389,17 +391,18 @@ void GLFbPC::render() xoff = (x - *mX) / 2; yoff = (y - *mY) / 2; glutFullScreen(); - } else + } + else *mX = *mY * mOA.num / mOA.den; hal_info("%s: reinit mX:%d mY:%d xoff:%d yoff:%d fs %d\n", - __func__, *mX, *mY, xoff, yoff, mFullscreen); + __func__, *mX, *mY, xoff, yoff, mFullscreen); glViewport(xoff, yoff, *mX, *mY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - float aspect = static_cast(*mX)/ *mY; + float aspect = static_cast(*mX) / *mY; float osdaspect = static_cast(mOA.den) / mOA.num; - glOrtho(aspect*-osdaspect, aspect*osdaspect, -1.0, 1.0, -1.0, 1.0 ); + glOrtho(aspect * -osdaspect, aspect * osdaspect, -1.0, 1.0, -1.0, 1.0); glClearColor(0.0, 0.0, 0.0, 1.0); glMatrixMode(GL_MODELVIEW); @@ -414,7 +417,8 @@ void GLFbPC::render() glutReshapeWindow(*mX, *mY); bltDisplayBuffer(); /* decoded video stream */ - if (mState.blit) { + if (mState.blit) + { /* only blit manually after fb->blit(), this helps to find missed blit() calls */ mState.blit = false; hal_debug("GLFB::%s blit!\n", __func__); @@ -431,16 +435,18 @@ void GLFbPC::render() xscale = 1.0; int cmp = (mCrop == DISPLAY_AR_MODE_NONE) ? 0 : av_cmp_q(mVA, mOA); const AVRational a149 = { 14, 9 }; - switch (cmp) { + switch (cmp) + { default: - case INT_MIN: /* invalid */ - case 0: /* identical */ + case INT_MIN: /* invalid */ + case 0: /* identical */ hal_debug("%s: mVA == mOA (or fullscreen mode :-)\n", __func__); break; - case 1: /* mVA > mOA -- video is wider than display */ + case 1: /* mVA > mOA -- video is wider than display */ hal_debug("%s: mVA > mOA\n", __func__); xscale = av_q2d(mVA) / av_q2d(mOA); - switch (mCrop) { + switch (mCrop) + { case DISPLAY_AR_MODE_PANSCAN: break; case DISPLAY_AR_MODE_LETTERBOX: @@ -453,18 +459,20 @@ void GLFbPC::render() break; } break; - case -1: /* mVA < mOA -- video is taller than display */ + case -1: /* mVA < mOA -- video is taller than display */ hal_debug("%s: mVA < mOA\n", __func__); xscale = av_q2d(mVA) / av_q2d(mOA); - switch (mCrop) { + switch (mCrop) + { case DISPLAY_AR_MODE_LETTERBOX: break; case DISPLAY_AR_MODE_PANSCAN2: - if (av_cmp_q(a149, mOA) < 0) { + if (av_cmp_q(a149, mOA) < 0) + { zoom = av_q2d(mVA) * av_q2d(a149) / av_q2d(mOA); break; } - /* fallthrough for output format 14:9 */ + /* fallthrough for output format 14:9 */ case DISPLAY_AR_MODE_PANSCAN: zoom = av_q2d(mOA) / av_q2d(mVA); break; @@ -500,11 +508,15 @@ void GLFbPC::checkReinit(int x, int y) static int last_x = 0, last_y = 0; mReInitLock.lock(); - if (!mFullscreen && !mReInit && (x != *mX || y != *mY)) { - if (x != *mX && abs(x - last_x) > 2) { + if (!mFullscreen && !mReInit && (x != *mX || y != *mY)) + { + if (x != *mX && abs(x - last_x) > 2) + { *mX = x; *mY = *mX * mOA.den / mOA.num; - } else if (y != *mY && abs(y - last_y) > 2) { + } + else if (y != *mY && abs(y - last_y) > 2) + { *mY = y; *mX = *mY * mOA.num / mOA.den; } @@ -517,25 +529,29 @@ void GLFbPC::checkReinit(int x, int y) void GLFbPC::drawSquare(float size, float x_factor) { - GLfloat vertices[] = { - 1.0f, 1.0f, + GLfloat vertices[] = + { + 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, - 1.0f, -1.0f, + 1.0f, -1.0f, }; GLubyte indices[] = { 0, 1, 2, 3 }; - GLfloat texcoords[] = { - 1.0, 0.0, - 0.0, 0.0, - 0.0, 1.0, - 1.0, 1.0, + GLfloat texcoords[] = + { + 1.0, 0.0, + 0.0, 0.0, + 0.0, 1.0, + 1.0, 1.0, }; - if (x_factor > -99.0) { /* x_factor == -100 => OSD */ + if (x_factor > -99.0) /* x_factor == -100 => OSD */ + { if (videoDecoder && videoDecoder->pig_x > 0 && videoDecoder->pig_y > 0 && - videoDecoder->pig_w > 0 && videoDecoder->pig_h > 0) { + videoDecoder->pig_w > 0 && videoDecoder->pig_h > 0) + { /* these calculations even consider cropping and panscan mode * maybe this could be done with some clever opengl tricks? */ double w2 = (double)mState.width * 0.5l; @@ -546,16 +562,17 @@ void GLFbPC::drawSquare(float size, float x_factor) double h = (double)videoDecoder->pig_h / h2; x += ((1.0l - x_factor * size) / 2.0l) * w / x_factor / size; y += ((size - 1.0l) / 2.0l) * h / size; - vertices[0] = x + w; /* top right x */ - vertices[1] = y; /* top right y */ - vertices[2] = x; /* top left x */ - vertices[3] = y; /* top left y */ - vertices[4] = x; /* bottom left x */ - vertices[5] = y - h; /* bottom left y */ - vertices[6] = vertices[0]; /* bottom right x */ - vertices[7] = vertices[5]; /* bottom right y */ + vertices[0] = x + w; /* top right x */ + vertices[1] = y; /* top right y */ + vertices[2] = x; /* top left x */ + vertices[3] = y; /* top left y */ + vertices[4] = x; /* bottom left x */ + vertices[5] = y - h; /* bottom left y */ + vertices[6] = vertices[0]; /* bottom right x */ + vertices[7] = vertices[5]; /* bottom right y */ } - } else + } + else x_factor = 1.0; /* OSD */ glPushMatrix(); @@ -589,7 +606,8 @@ void GLFbPC::bltDisplayBuffer() return; static bool warn = true; cVideo::SWFramebuffer *buf = videoDecoder->getDecBuf(); - if (!buf) { + if (!buf) + { if (warn) hal_info("GLFB::%s did not get a buffer...\n", __func__); warn = false; @@ -601,7 +619,8 @@ void GLFbPC::bltDisplayBuffer() return; AVRational a = buf->AR(); - if (a.den != 0 && a.num != 0 && av_cmp_q(a, _mVA)) { + if (a.den != 0 && a.num != 0 && av_cmp_q(a, _mVA)) + { _mVA = a; /* _mVA is the raw buffer's aspect, mVA is the real scaled output aspect */ av_reduce(&mVA.num, &mVA.den, w * a.num, h * a.den, INT_MAX); @@ -624,10 +643,11 @@ void GLFbPC::bltDisplayBuffer() int64_t vpts = buf->pts() + 18000; if (audioDecoder) apts = audioDecoder->getPts(); - if (apts != last_apts) { + if (apts != last_apts) + { int rate, dummy1, dummy2; if (apts < vpts) - sleep_us = (sleep_us * 2 + (vpts - apts)*10/9) / 3; + sleep_us = (sleep_us * 2 + (vpts - apts) * 10 / 9) / 3; else if (sleep_us > 1000) sleep_us -= 1000; last_apts = apts; @@ -642,5 +662,5 @@ void GLFbPC::bltDisplayBuffer() sleep_us = 1; } hal_debug("vpts: 0x%" PRIx64 " apts: 0x%" PRIx64 " diff: %6.3f sleep_us %d buf %d\n", - buf->pts(), apts, (buf->pts() - apts)/90000.0, sleep_us, videoDecoder->buf_num); + buf->pts(), apts, (buf->pts() - apts) / 90000.0, sleep_us, videoDecoder->buf_num); } diff --git a/libgeneric-pc/glfb_priv.h b/libgeneric-pc/glfb_priv.h index a51545a..db21609 100644 --- a/libgeneric-pc/glfb_priv.h +++ b/libgeneric-pc/glfb_priv.h @@ -1,23 +1,23 @@ /* - Copyright 2010 Carsten Juttner - Copyright 2012,2013,2016 Stefan Seyfried + Copyright 2010 Carsten Juttner + Copyright 2012,2013,2016 Stefan Seyfried - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . - ******************************************************************** - private stuff of the GLFB thread that is only used inside libstb-hal - and not exposed to the application. + ******************************************************************** + private stuff of the GLFB thread that is only used inside libstb-hal + and not exposed to the application. */ #ifndef __glfb_priv__ @@ -41,86 +41,108 @@ extern "C" { class GLFbPC { -public: - GLFbPC(int x, int y, std::vector &buf); - ~GLFbPC(); - std::vector *getOSDBuffer() { return osd_buf; } /* pointer to OSD bounce buffer */ - int getOSDWidth() { return mState.width; } - int getOSDHeight() { return mState.height; } - void blit() { mState.blit = true; }; - fb_var_screeninfo getScreenInfo() { return si; } - void setOutputFormat(AVRational a, int h, int c) { mOA = a; *mY = h; mCrop = c; mReInit = true; } -/* just make everything public for simplicity - this is only used inside libstb-hal anyway -private: -*/ - fb_var_screeninfo si; - int *mX; - int *mY; - int _mX[2]; /* output window size */ - int _mY[2]; /* [0] = normal, [1] = fullscreen */ - AVRational mOA; /* output window aspect ratio */ - AVRational mVA; /* video aspect ratio */ - AVRational _mVA; /* for detecting changes in mVA */ - bool mVAchanged; - float zoom; /* for cropping */ - float xscale; /* and aspect ratio */ - int mCrop; /* DISPLAY_AR_MODE */ + public: + GLFbPC(int x, int y, std::vector &buf); + ~GLFbPC(); + std::vector *getOSDBuffer() + { + return osd_buf; /* pointer to OSD bounce buffer */ + } + int getOSDWidth() + { + return mState.width; + } + int getOSDHeight() + { + return mState.height; + } + void blit() + { + mState.blit = true; + }; + fb_var_screeninfo getScreenInfo() + { + return si; + } + void setOutputFormat(AVRational a, int h, int c) + { + mOA = a; + *mY = h; + mCrop = c; + mReInit = true; + } + /* just make everything public for simplicity - this is only used inside libstb-hal anyway + private: + */ + fb_var_screeninfo si; + int *mX; + int *mY; + int _mX[2]; /* output window size */ + int _mY[2]; /* [0] = normal, [1] = fullscreen */ + AVRational mOA; /* output window aspect ratio */ + AVRational mVA; /* video aspect ratio */ + AVRational _mVA; /* for detecting changes in mVA */ + bool mVAchanged; + float zoom; /* for cropping */ + float xscale; /* and aspect ratio */ + int mCrop; /* DISPLAY_AR_MODE */ - bool mFullscreen; /* fullscreen? */ - bool mReInit; /* setup things for GL */ - OpenThreads::Mutex mReInitLock; - bool mShutDown; /* if set main loop is left */ - bool mInitDone; /* condition predicate */ - // OpenThreads::Condition mInitCond; /* condition variable for init */ - // mutable OpenThreads::Mutex mMutex; /* lock our data */ + bool mFullscreen; /* fullscreen? */ + bool mReInit; /* setup things for GL */ + OpenThreads::Mutex mReInitLock; + bool mShutDown; /* if set main loop is left */ + bool mInitDone; /* condition predicate */ + // OpenThreads::Condition mInitCond; /* condition variable for init */ + // mutable OpenThreads::Mutex mMutex; /* lock our data */ - std::vector *osd_buf; /* silly bounce buffer */ + std::vector *osd_buf; /* silly bounce buffer */ #if USE_OPENGL - std::map mKeyMap; - std::map mSpecialMap; + std::map mKeyMap; + std::map mSpecialMap; #endif #if USE_CLUTTER - std::map mKeyMap; + std::map mKeyMap; #endif - int input_fd; - int64_t last_apts; - void run(); + int input_fd; + int64_t last_apts; + void run(); - static void rendercb(); /* callback for GLUT */ - void render(); /* actual render function */ + static void rendercb(); /* callback for GLUT */ + void render(); /* actual render function */ #if USE_OPENGL - static void keyboardcb(unsigned char key, int x, int y); - static void specialcb(int key, int x, int y); - static void resizecb(int w, int h); - void checkReinit(int w, int h); /* e.g. in case window was resized */ - void setupGLObjects(); /* PBOs, textures and stuff */ - void releaseGLObjects(); - void drawSquare(float size, float x_factor = 1); /* do not be square */ + static void keyboardcb(unsigned char key, int x, int y); + static void specialcb(int key, int x, int y); + static void resizecb(int w, int h); + void checkReinit(int w, int h); /* e.g. in case window was resized */ + void setupGLObjects(); /* PBOs, textures and stuff */ + void releaseGLObjects(); + void drawSquare(float size, float x_factor = 1); /* do not be square */ #endif #if USE_CLUTTER - static bool keyboardcb(ClutterActor *actor, ClutterEvent *event, gpointer user_data); + static bool keyboardcb(ClutterActor *actor, ClutterEvent *event, gpointer user_data); #endif - void initKeys(); /* setup key bindings for window */ + void initKeys(); /* setup key bindings for window */ #if 0 - void setupCtx(); /* create the window and make the context current */ - void setupOSDBuffer(); /* create the OSD buffer */ + void setupCtx(); /* create the window and make the context current */ + void setupOSDBuffer(); /* create the OSD buffer */ #endif - struct { - int width; /* width and height, fixed for a framebuffer instance */ - int height; - bool blit; + struct + { + int width; /* width and height, fixed for a framebuffer instance */ + int height; + bool blit; #if USE_OPENGL - GLuint osdtex; /* holds the OSD texture */ - GLuint pbo; /* PBO we use for transfer to texture */ - GLuint displaytex; /* holds the display texture */ - GLuint displaypbo; + GLuint osdtex; /* holds the OSD texture */ + GLuint pbo; /* PBO we use for transfer to texture */ + GLuint displaytex; /* holds the display texture */ + GLuint displaypbo; #endif - } mState; + } mState; - void bltOSDBuffer(); - void bltDisplayBuffer(); + void bltOSDBuffer(); + void bltDisplayBuffer(); }; #endif diff --git a/libgeneric-pc/hardware_caps.c b/libgeneric-pc/hardware_caps.c index f84720f..999e011 100644 --- a/libgeneric-pc/hardware_caps.c +++ b/libgeneric-pc/hardware_caps.c @@ -29,7 +29,7 @@ hw_caps_t *get_hwcaps(void) initialized = 1; caps.can_cpufreq = 0; - caps.can_shutdown = 1; /* for testing */ + caps.can_shutdown = 1; /* for testing */ caps.display_type = HW_DISPLAY_LINE_TEXT; caps.has_HDMI = 1; caps.display_xres = 8; @@ -40,9 +40,10 @@ hw_caps_t *get_hwcaps(void) strcpy(caps.startup_file, ""); strcpy(caps.boxvendor, "Generic"); strcpy(caps.boxname, "PC"); - if (! uname(&u)){ + if (! uname(&u)) + { strncpy(caps.boxarch, u.machine, sizeof(caps.boxarch)); - caps.boxarch[sizeof(caps.boxarch)-1] = '\0'; + caps.boxarch[sizeof(caps.boxarch) - 1] = '\0'; } else fprintf(stderr, "%s: uname() failed: %m\n", __func__); diff --git a/libgeneric-pc/init.cpp b/libgeneric-pc/init.cpp index 1447eb3..52151ea 100644 --- a/libgeneric-pc/init.cpp +++ b/libgeneric-pc/init.cpp @@ -18,7 +18,8 @@ void hal_api_init() if (!initialized) hal_debug_init(); hal_info("%s begin, initialized=%d, debug=0x%02x\n", __func__, (int)initialized, debuglevel); - if (! glfb) { + if (! glfb) + { int x = 1280, y = 720; /* default OSD FB resolution */ /* * export GLFB_RESOLUTION=720,576 @@ -28,7 +29,8 @@ void hal_api_init() const char *p = NULL; if (tmp) p = strchr(tmp, ','); - if (p) { + if (p) + { x = atoi(tmp); y = atoi(p + 1); } diff --git a/libgeneric-pc/playback.cpp b/libgeneric-pc/playback.cpp index 2f5c44a..9932b1c 100644 --- a/libgeneric-pc/playback.cpp +++ b/libgeneric-pc/playback.cpp @@ -2,7 +2,7 @@ #include "playback_lib.h" -static const char * FILENAME = "playback-dummy"; +static const char *FILENAME = "playback-dummy"; bool cPlayback::Open(playmode_t) { @@ -15,13 +15,13 @@ void cPlayback::Close(void) bool cPlayback::Start(std::string filename, std::string headers) { - return Start((char*) filename.c_str(),0,0,0,0,0, headers); + return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers); } bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, int duration, std::string /*headers*/) { printf("%s:%s - filename=%s vpid=%u vtype=%d apid=%u ac3=%d duration=%i\n", - FILENAME, __func__, filename, vpid, vtype, apid, ac3, duration); + FILENAME, __func__, filename, vpid, vtype, apid, ac3, duration); return true; } @@ -58,7 +58,7 @@ bool cPlayback::GetPosition(int &position, int &duration) bool cPlayback::SetPosition(int position, bool) { - printf("%s:%s %d\n", FILENAME, __func__,position); + printf("%s:%s %d\n", FILENAME, __func__, position); return true; } diff --git a/libgeneric-pc/playback_gst.h b/libgeneric-pc/playback_gst.h index ed29b8b..1195017 100644 --- a/libgeneric-pc/playback_gst.h +++ b/libgeneric-pc/playback_gst.h @@ -46,61 +46,67 @@ struct AVFormatContext; class cPlayback { -private: - bool playing, first; - bool decoders_closed; + private: + bool playing, first; + bool decoders_closed; - int mSpeed; - int mAudioStream; - int init_jump; + int mSpeed; + int mAudioStream; + int init_jump; -public: - playstate_t playstate; + public: + playstate_t playstate; - cPlayback(int); - bool Open(playmode_t PlayMode); - void Close(void); - bool Start(char *filename, int vpid, int vtype, int apid, int ac3, int duration, std::string headers = ""); - bool Start(std::string filename, std::string headers = ""); - bool Play(void); - bool SyncAV(void); + cPlayback(int); + bool Open(playmode_t PlayMode); + void Close(void); + bool Start(char *filename, int vpid, int vtype, int apid, int ac3, int duration, std::string headers = ""); + bool Start(std::string filename, std::string headers = ""); + bool Play(void); + bool SyncAV(void); - bool Stop(void); - bool SetAPid(int pid, bool ac3); - bool SetSubtitlePid(int pid); - bool SetTeletextPid(int pid); + bool Stop(void); + bool SetAPid(int pid, bool ac3); + bool SetSubtitlePid(int pid); + bool SetTeletextPid(int pid); - void trickSeek(int ratio); - bool SetSpeed(int speed); - bool SetSlow(int slow); - bool GetSpeed(int &speed) const; - bool GetPosition(int &position, int &duration); - void GetPts(uint64_t &pts); - int GetAPid(void); - int GetVPid(void); - int GetSubtitlePid(void); - bool SetPosition(int position, bool absolute = false); - void FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language); - void FindAllPids(uint16_t *apids, unsigned short *ac3flags, uint16_t *numpida, std::string *language) { FindAllPids((int*) apids, (unsigned int*) ac3flags, (unsigned int*) numpida, language); }; - void FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language); - void FindAllTeletextsubtitlePids(int *pids, unsigned int *numpidt, std::string *tlanguage, int *mags, int *pages); - void RequestAbort(void); - void FindAllSubs(int *pids, unsigned int *supported, unsigned int *numpida, std::string *language); - void FindAllSubs(uint16_t *pids, unsigned short *supported, uint16_t *numpida, std::string *language) { FindAllSubs((int*) pids, (unsigned int*) supported, (unsigned int*) numpida, language); }; - bool SelectSubtitles(int pid, std::string charset = ""); - void GetTitles(std::vector &playlists, std::vector &titles, int ¤t); - void SetTitle(int title); - uint64_t GetReadCount(void); - void GetChapters(std::vector &positions, std::vector &titles); - void GetMetadata(std::vector &keys, std::vector &values); - AVFormatContext *GetAVFormatContext(); - void ReleaseAVFormatContext(); - std::string extra_headers; - std::string user_agent; + void trickSeek(int ratio); + bool SetSpeed(int speed); + bool SetSlow(int slow); + bool GetSpeed(int &speed) const; + bool GetPosition(int &position, int &duration); + void GetPts(uint64_t &pts); + int GetAPid(void); + int GetVPid(void); + int GetSubtitlePid(void); + bool SetPosition(int position, bool absolute = false); + void FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language); + void FindAllPids(uint16_t *apids, unsigned short *ac3flags, uint16_t *numpida, std::string *language) + { + FindAllPids((int *) apids, (unsigned int *) ac3flags, (unsigned int *) numpida, language); + }; + void FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language); + void FindAllTeletextsubtitlePids(int *pids, unsigned int *numpidt, std::string *tlanguage, int *mags, int *pages); + void RequestAbort(void); + void FindAllSubs(int *pids, unsigned int *supported, unsigned int *numpida, std::string *language); + void FindAllSubs(uint16_t *pids, unsigned short *supported, uint16_t *numpida, std::string *language) + { + FindAllSubs((int *) pids, (unsigned int *) supported, (unsigned int *) numpida, language); + }; + bool SelectSubtitles(int pid, std::string charset = ""); + void GetTitles(std::vector &playlists, std::vector &titles, int ¤t); + void SetTitle(int title); + uint64_t GetReadCount(void); + void GetChapters(std::vector &positions, std::vector &titles); + void GetMetadata(std::vector &keys, std::vector &values); + AVFormatContext *GetAVFormatContext(); + void ReleaseAVFormatContext(); + std::string extra_headers; + std::string user_agent; - // - ~cPlayback(); - void getMeta(); + // + ~cPlayback(); + void getMeta(); }; #endif // __PLAYBACK_GST_H__ diff --git a/libgeneric-pc/playback_gst_01.cpp b/libgeneric-pc/playback_gst_01.cpp index 8694724..897838d 100644 --- a/libgeneric-pc/playback_gst_01.cpp +++ b/libgeneric-pc/playback_gst_01.cpp @@ -43,7 +43,7 @@ #define hal_debug_c(args...) _hal_debug(HAL_DEBUG_PLAYBACK, NULL, args) #define hal_info_c(args...) _hal_info(HAL_DEBUG_PLAYBACK, NULL, args) -static const char * FILENAME = "[playback.cpp]"; +static const char *FILENAME = "[playback.cpp]"; #include #include @@ -63,86 +63,86 @@ typedef enum } GstPlayFlags; -GstElement * m_gst_playbin = NULL; -GstElement * audioSink = NULL; -GstElement * videoSink = NULL; -gchar * uri = NULL; -GstTagList * m_stream_tags = 0; +GstElement *m_gst_playbin = NULL; +GstElement *audioSink = NULL; +GstElement *videoSink = NULL; +gchar *uri = NULL; +GstTagList *m_stream_tags = 0; static int end_eof = 0; extern GLFramebuffer *glfb; gint match_sinktype(GstElement *element, gpointer type) { - return strcmp(g_type_name(G_OBJECT_TYPE(element)), (const char*)type); + return strcmp(g_type_name(G_OBJECT_TYPE(element)), (const char *)type); } -GstBusSyncReply Gst_bus_call(GstBus * bus, GstMessage *msg, gpointer user_data) +GstBusSyncReply Gst_bus_call(GstBus *bus, GstMessage *msg, gpointer user_data) { - gchar * sourceName; - + gchar *sourceName; + // source - GstObject * source; + GstObject *source; source = GST_MESSAGE_SRC(msg); - + if (!GST_IS_OBJECT(source)) return GST_BUS_DROP; - + sourceName = gst_object_get_name(source); - switch (GST_MESSAGE_TYPE(msg)) + switch (GST_MESSAGE_TYPE(msg)) { - case GST_MESSAGE_EOS: + case GST_MESSAGE_EOS: { g_message("End-of-stream"); end_eof = 1; break; } - - case GST_MESSAGE_ERROR: + + case GST_MESSAGE_ERROR: { - gchar * debug; + gchar *debug; GError *err; gst_message_parse_error(msg, &err, &debug); - g_free (debug); - hal_info_c( "%s:%s - GST_MESSAGE_ERROR: %s (%i) from %s\n", FILENAME, __FUNCTION__, err->message, err->code, sourceName ); - if ( err->domain == GST_STREAM_ERROR ) + g_free(debug); + hal_info_c("%s:%s - GST_MESSAGE_ERROR: %s (%i) from %s\n", FILENAME, __FUNCTION__, err->message, err->code, sourceName); + if (err->domain == GST_STREAM_ERROR) { - if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND ) + if (err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND) { - if ( g_strrstr(sourceName, "videosink") ) - hal_info_c( "%s:%s - GST_MESSAGE_ERROR: videosink\n", FILENAME, __FUNCTION__ ); //FIXME: how shall playback handle this event??? - else if ( g_strrstr(sourceName, "audiosink") ) - hal_info_c( "%s:%s - GST_MESSAGE_ERROR: audioSink\n", FILENAME, __FUNCTION__ ); //FIXME: how shall playback handle this event??? + if (g_strrstr(sourceName, "videosink")) + hal_info_c("%s:%s - GST_MESSAGE_ERROR: videosink\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? + else if (g_strrstr(sourceName, "audiosink")) + hal_info_c("%s:%s - GST_MESSAGE_ERROR: audioSink\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? } } g_error_free(err); - end_eof = 1; // NOTE: just to exit - + end_eof = 1; // NOTE: just to exit + break; } - + case GST_MESSAGE_INFO: { gchar *debug; GError *inf; - - gst_message_parse_info (msg, &inf, &debug); - g_free (debug); - if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE ) + + gst_message_parse_info(msg, &inf, &debug); + g_free(debug); + if (inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE) { - if ( g_strrstr(sourceName, "videosink") ) - hal_info_c( "%s:%s - GST_MESSAGE_INFO: videosink\n", FILENAME, __FUNCTION__ ); //FIXME: how shall playback handle this event??? + if (g_strrstr(sourceName, "videosink")) + hal_info_c("%s:%s - GST_MESSAGE_INFO: videosink\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? } g_error_free(inf); break; } - + case GST_MESSAGE_TAG: { GstTagList *tags, *result; gst_message_parse_tag(msg, &tags); - + result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE); if (result) { @@ -150,45 +150,45 @@ GstBusSyncReply Gst_bus_call(GstBus * bus, GstMessage *msg, gpointer user_data) gst_tag_list_free(m_stream_tags); m_stream_tags = result; } - + const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0); - if ( gv_image ) + if (gv_image) { GstBuffer *buf_image; - buf_image = gst_value_get_buffer (gv_image); - int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644); - if(fd >= 0) + buf_image = gst_value_get_buffer(gv_image); + int fd = open("/tmp/.id3coverart", O_CREAT | O_WRONLY | O_TRUNC, 0644); + if (fd >= 0) { int ret = write(fd, GST_BUFFER_DATA(buf_image), GST_BUFFER_SIZE(buf_image)); close(fd); - hal_info_c( "%s:%s - GST_MESSAGE_INFO: cPlayback::state /tmp/.id3coverart %d bytes written\n", FILENAME, __FUNCTION__ , ret); + hal_info_c("%s:%s - GST_MESSAGE_INFO: cPlayback::state /tmp/.id3coverart %d bytes written\n", FILENAME, __FUNCTION__, ret); } //FIXME: how shall playback handle this event??? } gst_tag_list_free(tags); - hal_info_c( "%s:%s - GST_MESSAGE_INFO: update info tags\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? + hal_info_c("%s:%s - GST_MESSAGE_INFO: update info tags\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? break; } - + case GST_MESSAGE_STATE_CHANGED: { - if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin)) + if (GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin)) break; GstState old_state, new_state; gst_message_parse_state_changed(msg, &old_state, &new_state, NULL); - - if(old_state == new_state) + + if (old_state == new_state) break; - hal_info_c( "%s:%s - GST_MESSAGE_STATE_CHANGED: state transition %s -> %s\n", FILENAME, __FUNCTION__, gst_element_state_get_name(old_state), gst_element_state_get_name(new_state)); - + hal_info_c("%s:%s - GST_MESSAGE_STATE_CHANGED: state transition %s -> %s\n", FILENAME, __FUNCTION__, gst_element_state_get_name(old_state), gst_element_state_get_name(new_state)); + GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state); - - switch(transition) + + switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: { - } break; + } break; case GST_STATE_CHANGE_READY_TO_PAUSED: { GstIterator *children; @@ -197,7 +197,7 @@ GstBusSyncReply Gst_bus_call(GstBus * bus, GstMessage *msg, gpointer user_data) gst_object_unref(GST_OBJECT(audioSink)); audioSink = NULL; } - + if (videoSink) { gst_object_unref(GST_OBJECT(videoSink)); @@ -207,14 +207,15 @@ GstBusSyncReply Gst_bus_call(GstBus * bus, GstMessage *msg, gpointer user_data) audioSink = GST_ELEMENT_CAST(gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, (gpointer)"GstDVBAudioSink")); videoSink = GST_ELEMENT_CAST(gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, (gpointer)"GstDVBVideoSink")); gst_iterator_free(children); - - } break; + + } + break; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: { - } break; + } break; case GST_STATE_CHANGE_PLAYING_TO_PAUSED: { - } break; + } break; case GST_STATE_CHANGE_PAUSED_TO_READY: { if (audioSink) @@ -227,26 +228,27 @@ GstBusSyncReply Gst_bus_call(GstBus * bus, GstMessage *msg, gpointer user_data) gst_object_unref(GST_OBJECT(videoSink)); videoSink = NULL; } - } break; + } + break; case GST_STATE_CHANGE_READY_TO_NULL: { - } break; + } break; } break; } #if 0 case GST_MESSAGE_ELEMENT: { - if(gst_structure_has_name(gst_message_get_structure(msg), "prepare-xwindow-id")) + if (gst_structure_has_name(gst_message_get_structure(msg), "prepare-xwindow-id")) { // set window id - gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(GST_MESSAGE_SRC (msg)), glfb->getWindowID()); - + gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(GST_MESSAGE_SRC(msg)), glfb->getWindowID()); + // reshape window - gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(GST_MESSAGE_SRC (msg)), 0, 0, glfb->getOSDWidth(), glfb->getOSDHeight()); - + gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(GST_MESSAGE_SRC(msg)), 0, 0, glfb->getOSDWidth(), glfb->getOSDHeight()); + // sync frames - gst_x_overlay_expose(GST_X_OVERLAY(GST_MESSAGE_SRC (msg))); + gst_x_overlay_expose(GST_X_OVERLAY(GST_MESSAGE_SRC(msg))); } } #endif @@ -260,25 +262,25 @@ GstBusSyncReply Gst_bus_call(GstBus * bus, GstMessage *msg, gpointer user_data) cPlayback::cPlayback(int num) -{ - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); - const gchar *nano_str; - guint major, minor, micro, nano; +{ + hal_info("%s:%s\n", FILENAME, __FUNCTION__); + const gchar *nano_str; + guint major, minor, micro, nano; gst_init(NULL, NULL); - gst_version (&major, &minor, µ, &nano); + gst_version(&major, &minor, µ, &nano); - if (nano == 1) - nano_str = "(CVS)"; - else if (nano == 2) - nano_str = "(Prerelease)"; + if (nano == 1) + nano_str = "(CVS)"; + else if (nano == 2) + nano_str = "(Prerelease)"; else - nano_str = ""; + nano_str = ""; - hal_info( "%s:%s - This program is linked against GStreamer %d.%d.%d %s\n", - FILENAME, __FUNCTION__, - major, minor, micro, nano_str); + hal_info("%s:%s - This program is linked against GStreamer %d.%d.%d %s\n", + FILENAME, __FUNCTION__, + major, minor, micro, nano_str); mAudioStream = 0; mSpeed = 0; @@ -288,8 +290,8 @@ cPlayback::cPlayback(int num) } cPlayback::~cPlayback() -{ - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); +{ + hal_info("%s:%s\n", FILENAME, __FUNCTION__); //FIXME: all deleting stuff is done in Close() } @@ -302,21 +304,21 @@ bool cPlayback::Open(playmode_t PlayMode) // used by movieplay void cPlayback::Close(void) -{ - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); +{ + hal_info("%s:%s\n", FILENAME, __FUNCTION__); Stop(); - + // disconnect bus handler if (m_gst_playbin) { // disconnect sync handler callback - GstBus * bus = gst_pipeline_get_bus(GST_PIPELINE (m_gst_playbin)); + GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(m_gst_playbin)); gst_bus_set_sync_handler(bus, NULL, NULL); gst_object_unref(bus); - hal_info( "%s:%s - GST bus handler closed\n", FILENAME, __FUNCTION__); + hal_info("%s:%s - GST bus handler closed\n", FILENAME, __FUNCTION__); } - + if (m_stream_tags) gst_tag_list_free(m_stream_tags); @@ -327,22 +329,22 @@ void cPlayback::Close(void) { gst_object_unref(GST_OBJECT(audioSink)); audioSink = NULL; - - hal_info( "%s:%s - GST audio Sink closed\n", FILENAME, __FUNCTION__); + + hal_info("%s:%s - GST audio Sink closed\n", FILENAME, __FUNCTION__); } - + if (videoSink) { gst_object_unref(GST_OBJECT(videoSink)); videoSink = NULL; - - hal_info( "%s:%s - GST video Sink closed\n", FILENAME, __FUNCTION__); + + hal_info("%s:%s - GST video Sink closed\n", FILENAME, __FUNCTION__); } - + // unref m_gst_playbin - gst_object_unref (GST_OBJECT (m_gst_playbin)); - hal_info( "%s:%s - GST playbin closed\n", FILENAME, __FUNCTION__); - + gst_object_unref(GST_OBJECT(m_gst_playbin)); + hal_info("%s:%s - GST playbin closed\n", FILENAME, __FUNCTION__); + m_gst_playbin = NULL; } } @@ -350,80 +352,80 @@ void cPlayback::Close(void) // start bool cPlayback::Start(std::string filename, std::string headers) { - return Start((char*) filename.c_str(),0,0,0,0,0, headers); + return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers); } bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, int /*ac3*/, int /*duration*/, std::string headers) { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); mAudioStream = 0; - + //create playback path char file[400] = {""}; bool isHTTP = false; - if(!strncmp("http://", filename, 7)) + if (!strncmp("http://", filename, 7)) { isHTTP = true; } - else if(!strncmp("file://", filename, 7)) + else if (!strncmp("file://", filename, 7)) { isHTTP = false; } - else if(!strncmp("upnp://", filename, 7)) + else if (!strncmp("upnp://", filename, 7)) { isHTTP = true; } - else if(!strncmp("rtmp://", filename, 7)) + else if (!strncmp("rtmp://", filename, 7)) { isHTTP = true; } - else if(!strncmp("rtsp://", filename, 7)) + else if (!strncmp("rtsp://", filename, 7)) { isHTTP = true; } - else if(!strncmp("mms://", filename, 6)) + else if (!strncmp("mms://", filename, 6)) { isHTTP = true; } else - strcat(file, "file://"); - + strcat(file, "file://"); + strcat(file, filename); - + if (isHTTP) uri = g_uri_escape_string(filename, G_URI_RESERVED_CHARS_GENERIC_DELIMITERS, true); else uri = g_filename_to_uri(filename, NULL, NULL); - + hal_info("%s:%s - filename=%s\n", FILENAME, __FUNCTION__, filename); // create gst pipeline m_gst_playbin = gst_element_factory_make("playbin2", "playbin"); - if(m_gst_playbin) + if (m_gst_playbin) { hal_info("%s:%s - m_gst_playbin\n", FILENAME, __FUNCTION__); guint flags; - g_object_get(G_OBJECT (m_gst_playbin), "flags", &flags, NULL); + g_object_get(G_OBJECT(m_gst_playbin), "flags", &flags, NULL); /* avoid video conversion, let the (hardware) sinks handle that */ flags |= GST_PLAY_FLAG_NATIVE_VIDEO; /* volume control is done by hardware */ flags &= ~GST_PLAY_FLAG_SOFT_VOLUME; - g_object_set(G_OBJECT (m_gst_playbin), "uri", uri, NULL); - g_object_set(G_OBJECT (m_gst_playbin), "flags", flags, NULL); - + g_object_set(G_OBJECT(m_gst_playbin), "uri", uri, NULL); + g_object_set(G_OBJECT(m_gst_playbin), "flags", flags, NULL); + //gstbus handler - GstBus * bus = gst_pipeline_get_bus( GST_PIPELINE(m_gst_playbin) ); + GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(m_gst_playbin)); gst_bus_set_sync_handler(bus, Gst_bus_call, NULL); - gst_object_unref(bus); - + gst_object_unref(bus); + // state playing gst_element_set_state(GST_ELEMENT(m_gst_playbin), GST_STATE_PLAYING); - + playing = true; playstate = STATE_PLAY; } @@ -431,32 +433,32 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, { hal_info("%s:%s - failed to create GStreamer pipeline!, sorry we can not play\n", FILENAME, __FUNCTION__); playing = false; - + return false; } - - g_free(uri); + + g_free(uri); // set buffer size /* increase the default 2 second / 2 MB buffer limitations to 5s / 5MB */ - int m_buffer_size = 5*1024*1024; + int m_buffer_size = 5 * 1024 * 1024; //g_object_set(G_OBJECT(m_gst_playbin), "buffer-duration", 5LL * GST_SECOND, NULL); g_object_set(G_OBJECT(m_gst_playbin), "buffer-size", m_buffer_size, NULL); - + return true; } bool cPlayback::Play(void) { - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - if(playing == true) + if (playing == true) return true; - - if(m_gst_playbin) + + if (m_gst_playbin) { gst_element_set_state(GST_ELEMENT(m_gst_playbin), GST_STATE_PLAYING); - + playing = true; playstate = STATE_PLAY; } @@ -466,35 +468,35 @@ bool cPlayback::Play(void) } bool cPlayback::Stop(void) -{ - if(playing == false) +{ + if (playing == false) return false; - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + // stop - if(m_gst_playbin) + if (m_gst_playbin) { gst_element_set_state(m_gst_playbin, GST_STATE_NULL); } playing = false; - - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - + + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + playstate = STATE_STOP; return true; } -bool cPlayback::SetAPid(int pid , bool /*ac3*/) +bool cPlayback::SetAPid(int pid, bool /*ac3*/) { hal_info("%s: pid %i\n", __func__, pid); - + int current_audio; - - if(pid != mAudioStream) + + if (pid != mAudioStream) { - g_object_set (G_OBJECT (m_gst_playbin), "current-audio", pid, NULL); + g_object_set(G_OBJECT(m_gst_playbin), "current-audio", pid, NULL); printf("%s: switched to audio stream %i\n", __FUNCTION__, pid); mAudioStream = pid; } @@ -508,18 +510,18 @@ void cPlayback::trickSeek(int ratio) gint64 pos = 0; int position; int duration; - - if( GetPosition(position, duration) ) + + if (GetPosition(position, duration)) { validposition = true; pos = position; } gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING); - + if (validposition) { - if(ratio >= 0.0) + if (ratio >= 0.0) gst_element_seek(m_gst_playbin, ratio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, -1); else gst_element_seek(m_gst_playbin, ratio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, pos); @@ -527,23 +529,23 @@ void cPlayback::trickSeek(int ratio) } bool cPlayback::SetSpeed(int speed) -{ - hal_info( "%s:%s speed %d\n", FILENAME, __FUNCTION__, speed); +{ + hal_info("%s:%s speed %d\n", FILENAME, __FUNCTION__, speed); - if(playing == false) + if (playing == false) return false; - if(m_gst_playbin) - { + if (m_gst_playbin) + { // pause - if(speed == 0) + if (speed == 0) { gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED); //trickSeek(0); playstate = STATE_PAUSE; } // play/continue - else if(speed == 1) + else if (speed == 1) { trickSeek(1); //gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING); @@ -551,14 +553,14 @@ bool cPlayback::SetSpeed(int speed) playstate = STATE_PLAY; } //ff - else if(speed > 1) + else if (speed > 1) { trickSeek(speed); // playstate = STATE_FF; } //rf - else if(speed < 0) + else if (speed < 0) { trickSeek(speed); // @@ -572,13 +574,13 @@ bool cPlayback::SetSpeed(int speed) } bool cPlayback::SetSlow(int slow) -{ - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); +{ + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - if(playing == false) + if (playing == false) return false; - if(m_gst_playbin) + if (m_gst_playbin) { trickSeek(0.5); } @@ -600,27 +602,27 @@ bool cPlayback::GetSpeed(int &speed) const // in milliseconds bool cPlayback::GetPosition(int &position, int &duration) { - if(playing == false) - return false; + if (playing == false) + return false; //EOF - if(end_eof) + if (end_eof) { end_eof = 0; return false; } - - if(m_gst_playbin) + + if (m_gst_playbin) { //position GstFormat fmt = GST_FORMAT_TIME; //Returns time in nanosecs - + gint64 pts = 0; unsigned long long int sec = 0; - + gst_element_query_position(m_gst_playbin, &fmt, &pts); position = pts / 1000000.0; - + // duration GstFormat fmt_d = GST_FORMAT_TIME; //Returns time in nanosecs double length = 0; @@ -628,94 +630,94 @@ bool cPlayback::GetPosition(int &position, int &duration) gst_element_query_duration(m_gst_playbin, &fmt_d, &len); length = len / 1000000.0; - if(length < 0) + if (length < 0) length = 0; - + duration = (int)(length); } - + return true; } bool cPlayback::SetPosition(int position, bool absolute) { hal_info("%s: pos %d abs %d playing %d\n", __func__, position, absolute, playing); - - if(playing == false) + + if (playing == false) return false; - + gint64 time_nanoseconds; gint64 pos; GstFormat fmt = GST_FORMAT_TIME; - - if(m_gst_playbin) + + if (m_gst_playbin) { gst_element_query_position(m_gst_playbin, &fmt, &pos); time_nanoseconds = pos + (position * 1000000.0); - if(time_nanoseconds < 0) + if (time_nanoseconds < 0) time_nanoseconds = 0; - + gst_element_seek(m_gst_playbin, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, time_nanoseconds, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE); } return true; } -void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string * language) -{ - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); +void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language) +{ + hal_info("%s:%s\n", FILENAME, __FUNCTION__); - if(m_gst_playbin) + if (m_gst_playbin) { gint i, n_audio = 0; //GstStructure * structure = NULL; - + // get audio - g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL); + g_object_get(m_gst_playbin, "n-audio", &n_audio, NULL); printf("%s: %d audio\n", __FUNCTION__, n_audio); - - if(n_audio == 0) + + if (n_audio == 0) return; - + for (i = 0; i < n_audio; i++) { // apids - apids[i]=i; - - GstPad * pad = 0; - g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad); - GstCaps * caps = gst_pad_get_negotiated_caps(pad); + apids[i] = i; + + GstPad *pad = 0; + g_signal_emit_by_name(m_gst_playbin, "get-audio-pad", i, &pad); + GstCaps *caps = gst_pad_get_negotiated_caps(pad); if (!caps) continue; - - GstStructure * structure = gst_caps_get_structure(caps, 0); + + GstStructure *structure = gst_caps_get_structure(caps, 0); //const gchar *g_type = gst_structure_get_name(structure); - + //if (!structure) - //return atUnknown; + //return atUnknown; //ac3flags[0] = 0; // ac3flags - if ( gst_structure_has_name (structure, "audio/mpeg")) + if (gst_structure_has_name(structure, "audio/mpeg")) { gint mpegversion, layer = -1; - - if (!gst_structure_get_int (structure, "mpegversion", &mpegversion)) + + if (!gst_structure_get_int(structure, "mpegversion", &mpegversion)) //return atUnknown; ac3flags[i] = 0; - switch (mpegversion) + switch (mpegversion) { case 1: /* { - gst_structure_get_int (structure, "layer", &layer); - if ( layer == 3 ) - return atMP3; - else - return atMPEG; - ac3flags[0] = 4; - break; + gst_structure_get_int (structure, "layer", &layer); + if ( layer == 3 ) + return atMP3; + else + return atMPEG; + ac3flags[0] = 4; + break; } */ ac3flags[i] = 4; @@ -730,35 +732,35 @@ void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *nu ac3flags[i] = 0; } } - else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") ) + else if (gst_structure_has_name(structure, "audio/x-ac3") || gst_structure_has_name(structure, "audio/ac3")) //return atAC3; ac3flags[i] = 1; - else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") ) + else if (gst_structure_has_name(structure, "audio/x-dts") || gst_structure_has_name(structure, "audio/dts")) //return atDTS; ac3flags[i] = 6; - else if ( gst_structure_has_name (structure, "audio/x-raw-int") ) + else if (gst_structure_has_name(structure, "audio/x-raw-int")) //return atPCM; ac3flags[i] = 0; - + gst_caps_unref(caps); } - + // numpids - *numpida=i; + *numpida = i; } } void cPlayback::getMeta() { - if(playing) + if (playing) return; } bool cPlayback::SyncAV(void) { - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - if(playing == false ) + if (playing == false) return false; return true; diff --git a/libgeneric-pc/playback_gst_10.cpp b/libgeneric-pc/playback_gst_10.cpp index 68c621b..0d19d1e 100644 --- a/libgeneric-pc/playback_gst_10.cpp +++ b/libgeneric-pc/playback_gst_10.cpp @@ -42,7 +42,7 @@ #define hal_debug_c(args...) _hal_debug(HAL_DEBUG_PLAYBACK, NULL, args) #define hal_info_c(args...) _hal_info(HAL_DEBUG_PLAYBACK, NULL, args) -static const char * FILENAME = "[playback.cpp]"; +static const char *FILENAME = "[playback.cpp]"; #include #include @@ -52,26 +52,26 @@ static const char * FILENAME = "[playback.cpp]"; typedef enum { - GST_PLAY_FLAG_VIDEO = (1 << 0), - GST_PLAY_FLAG_AUDIO = (1 << 1), - GST_PLAY_FLAG_TEXT = (1 << 2), - GST_PLAY_FLAG_VIS = (1 << 3), - GST_PLAY_FLAG_SOFT_VOLUME = (1 << 4), - GST_PLAY_FLAG_NATIVE_AUDIO = (1 << 5), - GST_PLAY_FLAG_NATIVE_VIDEO = (1 << 6), - GST_PLAY_FLAG_DOWNLOAD = (1 << 7), - GST_PLAY_FLAG_BUFFERING = (1 << 8), - GST_PLAY_FLAG_DEINTERLACE = (1 << 9), - GST_PLAY_FLAG_SOFT_COLORBALANCE = (1 << 10), - GST_PLAY_FLAG_FORCE_FILTERS = (1 << 11), + GST_PLAY_FLAG_VIDEO = (1 << 0), + GST_PLAY_FLAG_AUDIO = (1 << 1), + GST_PLAY_FLAG_TEXT = (1 << 2), + GST_PLAY_FLAG_VIS = (1 << 3), + GST_PLAY_FLAG_SOFT_VOLUME = (1 << 4), + GST_PLAY_FLAG_NATIVE_AUDIO = (1 << 5), + GST_PLAY_FLAG_NATIVE_VIDEO = (1 << 6), + GST_PLAY_FLAG_DOWNLOAD = (1 << 7), + GST_PLAY_FLAG_BUFFERING = (1 << 8), + GST_PLAY_FLAG_DEINTERLACE = (1 << 9), + GST_PLAY_FLAG_SOFT_COLORBALANCE = (1 << 10), + GST_PLAY_FLAG_FORCE_FILTERS = (1 << 11), } GstPlayFlags; -GstElement * m_gst_playbin = NULL; -GstElement * audioSink = NULL; -GstElement * videoSink = NULL; -gchar * uri = NULL; -GstTagList * m_stream_tags = NULL; +GstElement *m_gst_playbin = NULL; +GstElement *audioSink = NULL; +GstElement *videoSink = NULL; +gchar *uri = NULL; +GstTagList *m_stream_tags = NULL; pthread_mutex_t mutex_tag_ist; static int end_eof = 0; @@ -90,21 +90,25 @@ gint match_sinktype(const GValue *velement, const gchar *type) void resetPids() { - for (unsigned int i = 0; i < REC_MAX_APIDS; i++) { + for (unsigned int i = 0; i < REC_MAX_APIDS; i++) + { real_apids[i] = 0; } } -void processMpegTsSection(GstMpegtsSection* section) +void processMpegTsSection(GstMpegtsSection *section) { resetPids(); int cnt = 0; - if (section->section_type == GST_MPEGTS_SECTION_PMT) { - const GstMpegtsPMT* pmt = gst_mpegts_section_get_pmt(section); - for (guint i = 0; i < pmt->streams->len; ++i) { - const GstMpegtsPMTStream* stream = static_cast(g_ptr_array_index(pmt->streams, i)); - if (stream->stream_type == 0x05 || stream->stream_type >= 0x80) { - hal_info_c( "%s:%s Audio Stream pid: %d\n", FILENAME, __FUNCTION__, stream->pid); + if (section->section_type == GST_MPEGTS_SECTION_PMT) + { + const GstMpegtsPMT *pmt = gst_mpegts_section_get_pmt(section); + for (guint i = 0; i < pmt->streams->len; ++i) + { + const GstMpegtsPMTStream *stream = static_cast(g_ptr_array_index(pmt->streams, i)); + if (stream->stream_type == 0x05 || stream->stream_type >= 0x80) + { + hal_info_c("%s:%s Audio Stream pid: %d\n", FILENAME, __FUNCTION__, stream->pid); real_apids[cnt] = stream->pid; cnt++; } @@ -115,7 +119,7 @@ void processMpegTsSection(GstMpegtsSection* section) void playbinNotifySource(GObject *object, GParamSpec *param_spec, gpointer user_data) { GstElement *source = NULL; - cPlayback *_this = (cPlayback*)user_data; + cPlayback *_this = (cPlayback *)user_data; g_object_get(object, "source", &source, NULL); if (source) @@ -168,7 +172,7 @@ void playbinNotifySource(GObject *object, GParamSpec *param_spec, gpointer user_ if (!name.empty() && !value.empty()) { GValue header; - hal_info_c( "%s:%s setting extra-header '%s:%s'\n", FILENAME, __FUNCTION__, name.c_str(), value.c_str()); + hal_info_c("%s:%s setting extra-header '%s:%s'\n", FILENAME, __FUNCTION__, name.c_str(), value.c_str()); memset(&header, 0, sizeof(GValue)); g_value_init(&header, G_TYPE_STRING); g_value_set_string(&header, value.c_str()); @@ -176,7 +180,7 @@ void playbinNotifySource(GObject *object, GParamSpec *param_spec, gpointer user_ } else { - hal_info_c( "%s:%s Invalid header format %s\n", FILENAME, __FUNCTION__, _this->extra_headers.c_str()); + hal_info_c("%s:%s Invalid header format %s\n", FILENAME, __FUNCTION__, _this->extra_headers.c_str()); break; } } @@ -193,7 +197,7 @@ void playbinNotifySource(GObject *object, GParamSpec *param_spec, gpointer user_ GstBusSyncReply Gst_bus_call(GstBus *bus, GstMessage *msg, gpointer user_data) { // source - GstObject * source; + GstObject *source; source = GST_MESSAGE_SRC(msg); if (!GST_IS_OBJECT(source)) @@ -201,223 +205,224 @@ GstBusSyncReply Gst_bus_call(GstBus *bus, GstMessage *msg, gpointer user_data) switch (GST_MESSAGE_TYPE(msg)) { - case GST_MESSAGE_EOS: - { - g_message("End-of-stream"); - end_eof = 1; - break; - } - - case GST_MESSAGE_ERROR: - { - gchar * debug; - GError *err; - gst_message_parse_error(msg, &err, &debug); - g_free (debug); - gchar * sourceName = gst_object_get_name(source); - hal_info_c( "%s:%s - GST_MESSAGE_ERROR: %s (%i) from %s\n", FILENAME, __FUNCTION__, err->message, err->code, sourceName ); - if ( err->domain == GST_STREAM_ERROR ) + case GST_MESSAGE_EOS: { - if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND ) - { - if ( g_strrstr(sourceName, "videosink") ) - hal_info_c( "%s:%s - GST_MESSAGE_ERROR: videosink\n", FILENAME, __FUNCTION__ ); //FIXME: how shall playback handle this event??? - else if ( g_strrstr(sourceName, "audiosink") ) - hal_info_c( "%s:%s - GST_MESSAGE_ERROR: audioSink\n", FILENAME, __FUNCTION__ ); //FIXME: how shall playback handle this event??? - } + g_message("End-of-stream"); + end_eof = 1; + break; } - g_error_free(err); - if(sourceName) - g_free(sourceName); - end_eof = 1; // NOTE: just to exit - - break; - } - - case GST_MESSAGE_INFO: - { - gchar *debug; - GError *inf; - - gst_message_parse_info (msg, &inf, &debug); - g_free (debug); - if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE ) + case GST_MESSAGE_ERROR: { - gchar * sourceName = gst_object_get_name(source); - if ( g_strrstr(sourceName, "videosink") ) - hal_info_c( "%s:%s - GST_MESSAGE_INFO: videosink\n", FILENAME, __FUNCTION__ ); //FIXME: how shall playback handle this event??? - if(sourceName) + gchar *debug; + GError *err; + gst_message_parse_error(msg, &err, &debug); + g_free(debug); + gchar *sourceName = gst_object_get_name(source); + hal_info_c("%s:%s - GST_MESSAGE_ERROR: %s (%i) from %s\n", FILENAME, __FUNCTION__, err->message, err->code, sourceName); + if (err->domain == GST_STREAM_ERROR) + { + if (err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND) + { + if (g_strrstr(sourceName, "videosink")) + hal_info_c("%s:%s - GST_MESSAGE_ERROR: videosink\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? + else if (g_strrstr(sourceName, "audiosink")) + hal_info_c("%s:%s - GST_MESSAGE_ERROR: audioSink\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? + } + } + g_error_free(err); + if (sourceName) g_free(sourceName); + end_eof = 1; // NOTE: just to exit + + break; } - g_error_free(inf); - break; - } - case GST_MESSAGE_TAG: - { - GstTagList *tags = NULL, *result = NULL; - gst_message_parse_tag(msg, &tags); - - if(tags == NULL) - break; - if(!GST_IS_TAG_LIST(tags)) - break; - - pthread_mutex_lock (&mutex_tag_ist); - - result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE); - if (result) + case GST_MESSAGE_INFO: { - if (m_stream_tags && gst_tag_list_is_equal(m_stream_tags, result)) - { - gst_tag_list_unref(tags); - gst_tag_list_unref(result); + gchar *debug; + GError *inf; - pthread_mutex_unlock (&mutex_tag_ist); + gst_message_parse_info(msg, &inf, &debug); + g_free(debug); + if (inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE) + { + gchar *sourceName = gst_object_get_name(source); + if (g_strrstr(sourceName, "videosink")) + hal_info_c("%s:%s - GST_MESSAGE_INFO: videosink\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? + if (sourceName) + g_free(sourceName); + + } + g_error_free(inf); + break; + } + + case GST_MESSAGE_TAG: + { + GstTagList *tags = NULL, *result = NULL; + gst_message_parse_tag(msg, &tags); + + if (tags == NULL) + break; + if (!GST_IS_TAG_LIST(tags)) break; - } - if (m_stream_tags) - gst_tag_list_unref(m_stream_tags); - m_stream_tags = gst_tag_list_copy(result); - gst_tag_list_unref(result); - } - pthread_mutex_unlock (&mutex_tag_ist); + pthread_mutex_lock(&mutex_tag_ist); - const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0); - if ( gv_image ) - { - GstBuffer *buf_image; - GstSample *sample; - sample = (GstSample *)g_value_get_boxed(gv_image); - buf_image = gst_sample_get_buffer(sample); - int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644); - if (fd >= 0) + result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE); + if (result) { - guint8 *data; - gsize size; - GstMapInfo map; - gst_buffer_map(buf_image, &map, GST_MAP_READ); - data = map.data; - size = map.size; - int ret = write(fd, data, size); - gst_buffer_unmap(buf_image, &map); - close(fd); - hal_info_c("%s:%s - /tmp/.id3coverart %d bytes written\n", FILENAME, __FUNCTION__, ret); + if (m_stream_tags && gst_tag_list_is_equal(m_stream_tags, result)) + { + gst_tag_list_unref(tags); + gst_tag_list_unref(result); + + pthread_mutex_unlock(&mutex_tag_ist); + break; + } + if (m_stream_tags) + gst_tag_list_unref(m_stream_tags); + m_stream_tags = gst_tag_list_copy(result); + gst_tag_list_unref(result); } + + pthread_mutex_unlock(&mutex_tag_ist); + + const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0); + if (gv_image) + { + GstBuffer *buf_image; + GstSample *sample; + sample = (GstSample *)g_value_get_boxed(gv_image); + buf_image = gst_sample_get_buffer(sample); + int fd = open("/tmp/.id3coverart", O_CREAT | O_WRONLY | O_TRUNC, 0644); + if (fd >= 0) + { + guint8 *data; + gsize size; + GstMapInfo map; + gst_buffer_map(buf_image, &map, GST_MAP_READ); + data = map.data; + size = map.size; + int ret = write(fd, data, size); + gst_buffer_unmap(buf_image, &map); + close(fd); + hal_info_c("%s:%s - /tmp/.id3coverart %d bytes written\n", FILENAME, __FUNCTION__, ret); + } + } + if (tags) + gst_tag_list_unref(tags); + hal_debug_c("%s:%s - GST_MESSAGE_INFO: update info tags\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? + break; } - if (tags) - gst_tag_list_unref(tags); - hal_debug_c( "%s:%s - GST_MESSAGE_INFO: update info tags\n", FILENAME, __FUNCTION__); //FIXME: how shall playback handle this event??? - break; - } - case GST_MESSAGE_ELEMENT: - { + case GST_MESSAGE_ELEMENT: + { #if 0 - if(gst_structure_has_name(gst_message_get_structure(msg), "prepare-window-handle")) - { - // set window id - gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(GST_MESSAGE_SRC (msg)), glfb->getWindowID()); - - // reshape window - gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(GST_MESSAGE_SRC (msg)), 0, 0, glfb->getOSDWidth(), glfb->getOSDHeight()); - - // sync frames - gst_video_overlay_expose(GST_VIDEO_OVERLAY(GST_MESSAGE_SRC (msg))); - } + if (gst_structure_has_name(gst_message_get_structure(msg), "prepare-window-handle")) + { + // set window id + gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(GST_MESSAGE_SRC(msg)), glfb->getWindowID()); + + // reshape window + gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(GST_MESSAGE_SRC(msg)), 0, 0, glfb->getOSDWidth(), glfb->getOSDHeight()); + + // sync frames + gst_video_overlay_expose(GST_VIDEO_OVERLAY(GST_MESSAGE_SRC(msg))); + } #endif - GstMpegtsSection* section = gst_message_parse_mpegts_section(msg); - if (section) { - processMpegTsSection(section); - gst_mpegts_section_unref(section); + GstMpegtsSection *section = gst_message_parse_mpegts_section(msg); + if (section) + { + processMpegTsSection(section); + gst_mpegts_section_unref(section); + } } - } - case GST_MESSAGE_STATE_CHANGED: - { - if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin)) + case GST_MESSAGE_STATE_CHANGED: + { + if (GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin)) + break; + + GstState old_state, new_state; + gst_message_parse_state_changed(msg, &old_state, &new_state, NULL); + + if (old_state == new_state) + break; + hal_info_c("%s:%s - GST_MESSAGE_STATE_CHANGED: state transition %s -> %s\n", FILENAME, __FUNCTION__, gst_element_state_get_name(old_state), gst_element_state_get_name(new_state)); + + GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state); + + switch (transition) + { + case GST_STATE_CHANGE_NULL_TO_READY: + { + } break; + case GST_STATE_CHANGE_READY_TO_PAUSED: + { + GstIterator *children; + GValue r = G_VALUE_INIT; + + if (audioSink) + { + gst_object_unref(GST_OBJECT(audioSink)); + audioSink = NULL; + } + + if (videoSink) + { + gst_object_unref(GST_OBJECT(videoSink)); + videoSink = NULL; + } + children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin)); + if (children && gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &r, (gpointer)"GstDVBAudioSink")) + { + audioSink = GST_ELEMENT_CAST(g_value_dup_object(&r)); + g_value_unset(&r); + hal_info_c("%s %s - audio sink created\n", FILENAME, __FUNCTION__); + } + + gst_iterator_free(children); + children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin)); + if (children && gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &r, (gpointer)"GstDVBVideoSink")) + { + videoSink = GST_ELEMENT_CAST(g_value_dup_object(&r)); + g_value_unset(&r); + hal_info_c("%s %s - video sink created\n", FILENAME, __FUNCTION__); + } + gst_iterator_free(children); + + } + break; + case GST_STATE_CHANGE_PAUSED_TO_PLAYING: + { + } break; + case GST_STATE_CHANGE_PLAYING_TO_PAUSED: + { + } break; + case GST_STATE_CHANGE_PAUSED_TO_READY: + { + if (audioSink) + { + gst_object_unref(GST_OBJECT(audioSink)); + audioSink = NULL; + } + if (videoSink) + { + gst_object_unref(GST_OBJECT(videoSink)); + videoSink = NULL; + } + } + break; + case GST_STATE_CHANGE_READY_TO_NULL: + { + } break; + } break; - - GstState old_state, new_state; - gst_message_parse_state_changed(msg, &old_state, &new_state, NULL); - - if(old_state == new_state) + } + break; + default: break; - hal_info_c( "%s:%s - GST_MESSAGE_STATE_CHANGED: state transition %s -> %s\n", FILENAME, __FUNCTION__, gst_element_state_get_name(old_state), gst_element_state_get_name(new_state)); - - GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state); - - switch(transition) - { - case GST_STATE_CHANGE_NULL_TO_READY: - { - } break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - { - GstIterator *children; - GValue r = G_VALUE_INIT; - - if (audioSink) - { - gst_object_unref(GST_OBJECT(audioSink)); - audioSink = NULL; - } - - if (videoSink) - { - gst_object_unref(GST_OBJECT(videoSink)); - videoSink = NULL; - } - children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin)); - if (children && gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &r, (gpointer)"GstDVBAudioSink")) - { - audioSink = GST_ELEMENT_CAST(g_value_dup_object (&r)); - g_value_unset (&r); - hal_info_c( "%s %s - audio sink created\n", FILENAME, __FUNCTION__); - } - - gst_iterator_free(children); - children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin)); - if (children && gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &r, (gpointer)"GstDVBVideoSink")) - { - videoSink = GST_ELEMENT_CAST(g_value_dup_object (&r)); - g_value_unset (&r); - hal_info_c( "%s %s - video sink created\n", FILENAME, __FUNCTION__); - } - gst_iterator_free(children); - - } - break; - case GST_STATE_CHANGE_PAUSED_TO_PLAYING: - { - } break; - case GST_STATE_CHANGE_PLAYING_TO_PAUSED: - { - } break; - case GST_STATE_CHANGE_PAUSED_TO_READY: - { - if (audioSink) - { - gst_object_unref(GST_OBJECT(audioSink)); - audioSink = NULL; - } - if (videoSink) - { - gst_object_unref(GST_OBJECT(videoSink)); - videoSink = NULL; - } - } - break; - case GST_STATE_CHANGE_READY_TO_NULL: - { - } break; - } - break; - } - break; - default: - break; } return GST_BUS_DROP; @@ -426,17 +431,17 @@ GstBusSyncReply Gst_bus_call(GstBus *bus, GstMessage *msg, gpointer user_data) cPlayback::cPlayback(int num) { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); const gchar *nano_str; guint major, minor, micro, nano; gst_init(NULL, NULL); - gst_version (&major, &minor, µ, &nano); + gst_version(&major, &minor, µ, &nano); gst_mpegts_initialize(); - pthread_mutex_init (&mutex_tag_ist, NULL); + pthread_mutex_init(&mutex_tag_ist, NULL); if (nano == 1) nano_str = "(CVS)"; @@ -445,9 +450,9 @@ cPlayback::cPlayback(int num) else nano_str = ""; - hal_info( "%s:%s - This program is linked against GStreamer %d.%d.%d %s\n", - FILENAME, __FUNCTION__, - major, minor, micro, nano_str); + hal_info("%s:%s - This program is linked against GStreamer %d.%d.%d %s\n", + FILENAME, __FUNCTION__, + major, minor, micro, nano_str); mAudioStream = 0; mSpeed = 0; @@ -460,12 +465,12 @@ cPlayback::cPlayback(int num) cPlayback::~cPlayback() { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); //FIXME: all deleting stuff is done in Close() - pthread_mutex_lock (&mutex_tag_ist); + pthread_mutex_lock(&mutex_tag_ist); if (m_stream_tags) gst_tag_list_unref(m_stream_tags); - pthread_mutex_unlock (&mutex_tag_ist); + pthread_mutex_unlock(&mutex_tag_ist); } //Used by Fileplay @@ -480,7 +485,7 @@ bool cPlayback::Open(playmode_t PlayMode) // used by movieplay void cPlayback::Close(void) { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); Stop(); @@ -488,11 +493,11 @@ void cPlayback::Close(void) if (m_gst_playbin) { // disconnect sync handler callback - GstBus * bus = gst_pipeline_get_bus(GST_PIPELINE (m_gst_playbin)); + GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(m_gst_playbin)); gst_bus_set_sync_handler(bus, NULL, NULL, NULL); if (bus) gst_object_unref(bus); - hal_info( "%s:%s - GST bus handler closed\n", FILENAME, __FUNCTION__); + hal_info("%s:%s - GST bus handler closed\n", FILENAME, __FUNCTION__); } // close gst @@ -503,7 +508,7 @@ void cPlayback::Close(void) gst_object_unref(GST_OBJECT(audioSink)); audioSink = NULL; - hal_info( "%s:%s - GST audio Sink closed\n", FILENAME, __FUNCTION__); + hal_info("%s:%s - GST audio Sink closed\n", FILENAME, __FUNCTION__); } if (videoSink) @@ -511,12 +516,12 @@ void cPlayback::Close(void) gst_object_unref(GST_OBJECT(videoSink)); videoSink = NULL; - hal_info( "%s:%s - GST video Sink closed\n", FILENAME, __FUNCTION__); + hal_info("%s:%s - GST video Sink closed\n", FILENAME, __FUNCTION__); } // unref m_gst_playbin - gst_object_unref (GST_OBJECT (m_gst_playbin)); - hal_info( "%s:%s - GST playbin closed\n", FILENAME, __FUNCTION__); + gst_object_unref(GST_OBJECT(m_gst_playbin)); + hal_info("%s:%s - GST playbin closed\n", FILENAME, __FUNCTION__); m_gst_playbin = NULL; @@ -527,12 +532,12 @@ void cPlayback::Close(void) // start bool cPlayback::Start(std::string filename, std::string headers) { - return Start((char*) filename.c_str(),0,0,0,0,0, headers); + return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers); } bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, int /*ac3*/, int /*duration*/, std::string headers) { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); if (!headers.empty()) extra_headers = headers; @@ -544,68 +549,68 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, mAudioStream = 0; init_jump = -1; - pthread_mutex_lock (&mutex_tag_ist); + pthread_mutex_lock(&mutex_tag_ist); if (m_stream_tags) gst_tag_list_unref(m_stream_tags); m_stream_tags = NULL; - pthread_mutex_unlock (&mutex_tag_ist); + pthread_mutex_unlock(&mutex_tag_ist); unlink("/tmp/.id3coverart"); //create playback path bool isHTTP = false; - if(!strncmp("http://", filename, 7)) + if (!strncmp("http://", filename, 7)) { isHTTP = true; } - else if(!strncmp("https://", filename, 8)) + else if (!strncmp("https://", filename, 8)) { isHTTP = true; } - else if(!strncmp("file://", filename, 7)) + else if (!strncmp("file://", filename, 7)) { isHTTP = false; } - else if(!strncmp("upnp://", filename, 7)) + else if (!strncmp("upnp://", filename, 7)) { isHTTP = true; } - else if(!strncmp("rtmp://", filename, 7)) + else if (!strncmp("rtmp://", filename, 7)) { isHTTP = true; } - else if(!strncmp("rtsp://", filename, 7)) + else if (!strncmp("rtsp://", filename, 7)) { isHTTP = true; } - else if(!strncmp("mms://", filename, 6)) + else if (!strncmp("mms://", filename, 6)) { isHTTP = true; } if (isHTTP) - uri = g_strdup_printf ("%s", filename); + uri = g_strdup_printf("%s", filename); else uri = g_filename_to_uri(filename, NULL, NULL); hal_info("%s:%s - filename=%s\n", FILENAME, __FUNCTION__, filename); - guint flags = GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_NATIVE_VIDEO; + guint flags = GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_NATIVE_VIDEO; /* increase the default 2 second / 2 MB buffer limitations to 5s / 5MB */ - int m_buffer_size = 5*1024*1024; + int m_buffer_size = 5 * 1024 * 1024; // create gst pipeline - m_gst_playbin = gst_element_factory_make ("playbin", "playbin"); + m_gst_playbin = gst_element_factory_make("playbin", "playbin"); - if(m_gst_playbin) + if (m_gst_playbin) { hal_info("%s:%s - m_gst_playbin\n", FILENAME, __FUNCTION__); - if(isHTTP) + if (isHTTP) { - g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (playbinNotifySource), this); + g_signal_connect(G_OBJECT(m_gst_playbin), "notify::source", G_CALLBACK(playbinNotifySource), this); // set buffer size g_object_set(G_OBJECT(m_gst_playbin), "buffer-size", m_buffer_size, NULL); @@ -613,12 +618,12 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, flags |= GST_PLAY_FLAG_BUFFERING; } - g_object_set(G_OBJECT (m_gst_playbin), "flags", flags, NULL); + g_object_set(G_OBJECT(m_gst_playbin), "flags", flags, NULL); - g_object_set(G_OBJECT (m_gst_playbin), "uri", uri, NULL); + g_object_set(G_OBJECT(m_gst_playbin), "uri", uri, NULL); //gstbus handler - GstBus * bus = gst_pipeline_get_bus( GST_PIPELINE(m_gst_playbin) ); + GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(m_gst_playbin)); gst_bus_set_sync_handler(bus, Gst_bus_call, NULL, NULL); if (bus) gst_object_unref(bus); @@ -626,7 +631,7 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, first = true; // state playing - if(isHTTP) + if (isHTTP) { gst_element_set_state(GST_ELEMENT(m_gst_playbin), GST_STATE_PLAYING); playstate = STATE_PLAY; @@ -654,12 +659,12 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, bool cPlayback::Play(void) { - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - if(playing == true) + if (playing == true) return true; - if(m_gst_playbin) + if (m_gst_playbin) { gst_element_set_state(GST_ELEMENT(m_gst_playbin), GST_STATE_PLAYING); @@ -673,19 +678,19 @@ bool cPlayback::Play(void) bool cPlayback::Stop(void) { - if(playing == false) + if (playing == false) return false; - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); // stop - if(m_gst_playbin) + if (m_gst_playbin) { gst_element_set_state(m_gst_playbin, GST_STATE_NULL); } playing = false; - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); playstate = STATE_STOP; @@ -698,15 +703,16 @@ bool cPlayback::SetAPid(int pid, bool /*ac3*/) int to_audio = pid; - for (unsigned int i = 0; i < REC_MAX_APIDS; i++) { + for (unsigned int i = 0; i < REC_MAX_APIDS; i++) + { if (real_apids[i]) if (real_apids[i] == pid) to_audio = i; } - if(to_audio != mAudioStream) + if (to_audio != mAudioStream) { - g_object_set (G_OBJECT (m_gst_playbin), "current-audio", to_audio, NULL); + g_object_set(G_OBJECT(m_gst_playbin), "current-audio", to_audio, NULL); printf("%s: switched to audio stream %i\n", __FUNCTION__, to_audio); mAudioStream = to_audio; } @@ -723,7 +729,7 @@ void cPlayback::trickSeek(int ratio) if (gst_element_query_position(m_gst_playbin, fmt, &pos)) { - if(ratio >= 0.0) + if (ratio >= 0.0) gst_element_seek(m_gst_playbin, ratio, fmt, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, -1); else gst_element_seek(m_gst_playbin, ratio, fmt, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, pos); @@ -732,22 +738,22 @@ void cPlayback::trickSeek(int ratio) bool cPlayback::SetSpeed(int speed) { - hal_info( "%s:%s speed %d\n", FILENAME, __FUNCTION__, speed); + hal_info("%s:%s speed %d\n", FILENAME, __FUNCTION__, speed); - if(playing == false) + if (playing == false) return false; - if(m_gst_playbin) + if (m_gst_playbin) { // pause - if(speed == 0) + if (speed == 0) { gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED); //trickSeek(0); playstate = STATE_PAUSE; } // play/continue - else if(speed == 1) + else if (speed == 1) { trickSeek(1); //gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING); @@ -755,14 +761,14 @@ bool cPlayback::SetSpeed(int speed) playstate = STATE_PLAY; } //ff - else if(speed > 1) + else if (speed > 1) { trickSeek(speed); // playstate = STATE_FF; } //rf - else if(speed < 0) + else if (speed < 0) { trickSeek(speed); // @@ -771,7 +777,7 @@ bool cPlayback::SetSpeed(int speed) if (init_jump > -1) { - SetPosition(init_jump,true); + SetPosition(init_jump, true); init_jump = -1; } } @@ -783,12 +789,12 @@ bool cPlayback::SetSpeed(int speed) bool cPlayback::SetSlow(int slow) { - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - if(playing == false) + if (playing == false) return false; - if(m_gst_playbin) + if (m_gst_playbin) { trickSeek(0.5); } @@ -810,17 +816,17 @@ bool cPlayback::GetSpeed(int &speed) const // in milliseconds bool cPlayback::GetPosition(int &position, int &duration) { - if(playing == false) + if (playing == false) return false; //EOF - if(end_eof) + if (end_eof) { end_eof = 0; return false; } - if(m_gst_playbin) + if (m_gst_playbin) { //position GstFormat fmt = GST_FORMAT_TIME; //Returns time in nanosecs @@ -830,14 +836,14 @@ bool cPlayback::GetPosition(int &position, int &duration) g_signal_emit_by_name(audioSink ? audioSink : videoSink, "get-decoder-time", &pts); if (!GST_CLOCK_TIME_IS_VALID(pts)) { - hal_info( "%s - %d failed\n", __FUNCTION__, __LINE__); + hal_info("%s - %d failed\n", __FUNCTION__, __LINE__); } } else { - if(!gst_element_query_position(m_gst_playbin, fmt, &pts)) + if (!gst_element_query_position(m_gst_playbin, fmt, &pts)) { - hal_info( "%s - %d failed\n", __FUNCTION__, __LINE__); + hal_info("%s - %d failed\n", __FUNCTION__, __LINE__); } } position = pts / 1000000.0; @@ -848,7 +854,7 @@ bool cPlayback::GetPosition(int &position, int &duration) gst_element_query_duration(m_gst_playbin, fmt_d, &len); length = len / 1000000.0; - if(length < 0) + if (length < 0) length = 0; duration = (int)(length); @@ -862,12 +868,13 @@ bool cPlayback::SetPosition(int position, bool absolute) hal_info("%s: pos %d abs %d playing %d\n", __func__, position, absolute, playing); - if(m_gst_playbin) + if (m_gst_playbin) { - if(first){ + if (first) + { GstState state; gst_element_get_state(m_gst_playbin, &state, NULL, GST_CLOCK_TIME_NONE); - if ( (state == GST_STATE_PAUSED) && first) + if ((state == GST_STATE_PAUSED) && first) { init_jump = position; first = false; @@ -882,7 +889,7 @@ bool cPlayback::SetPosition(int position, bool absolute) { gst_element_query_position(m_gst_playbin, fmt, &pos); time_nanoseconds = pos + (position * 1000000.0); - if(time_nanoseconds < 0) + if (time_nanoseconds < 0) time_nanoseconds = 0; } else @@ -896,19 +903,19 @@ bool cPlayback::SetPosition(int position, bool absolute) return true; } -void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string * language) +void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language) { - hal_info( "%s:%s\n", FILENAME, __FUNCTION__); + hal_info("%s:%s\n", FILENAME, __FUNCTION__); - if(m_gst_playbin) + if (m_gst_playbin) { gint i, n_audio = 0; // get audio - g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL); + g_object_get(m_gst_playbin, "n-audio", &n_audio, NULL); hal_info("%s: %d audio\n", __FUNCTION__, n_audio); - if(n_audio == 0) + if (n_audio == 0) return; language->clear(); @@ -916,61 +923,61 @@ void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *nu for (i = 0; i < n_audio && i < *numpida; i++) { // apids - apids[i]= real_apids[i] ? real_apids[i] : i; + apids[i] = real_apids[i] ? real_apids[i] : i; - GstPad * pad = 0; - g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad); + GstPad *pad = 0; + g_signal_emit_by_name(m_gst_playbin, "get-audio-pad", i, &pad); - GstCaps * caps = gst_pad_get_current_caps(pad); + GstCaps *caps = gst_pad_get_current_caps(pad); if (pad) gst_object_unref(pad); if (!caps) continue; - GstStructure * structure = gst_caps_get_structure(caps, 0); - GstTagList * tags = NULL; - gchar * g_lang = NULL; + GstStructure *structure = gst_caps_get_structure(caps, 0); + GstTagList *tags = NULL; + gchar *g_lang = NULL; // ac3flags - if ( gst_structure_has_name (structure, "audio/mpeg")) + if (gst_structure_has_name(structure, "audio/mpeg")) { gint mpegversion; - if (!gst_structure_get_int (structure, "mpegversion", &mpegversion)) + if (!gst_structure_get_int(structure, "mpegversion", &mpegversion)) ac3flags[i] = 0; switch (mpegversion) { - case 1: - ac3flags[i] = 4; - case 2: - //return atAAC; - ac3flags[i] = 5; - case 4: - //return atAAC; - ac3flags[i] = 5; - default: - //return atUnknown; - ac3flags[i] = 0; + case 1: + ac3flags[i] = 4; + case 2: + //return atAAC; + ac3flags[i] = 5; + case 4: + //return atAAC; + ac3flags[i] = 5; + default: + //return atUnknown; + ac3flags[i] = 0; } } - else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") ) + else if (gst_structure_has_name(structure, "audio/x-ac3") || gst_structure_has_name(structure, "audio/ac3")) //return atAC3; ac3flags[i] = 1; - else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") ) + else if (gst_structure_has_name(structure, "audio/x-dts") || gst_structure_has_name(structure, "audio/dts")) //return atDTS; ac3flags[i] = 6; - else if ( gst_structure_has_name (structure, "audio/x-raw-int") ) + else if (gst_structure_has_name(structure, "audio/x-raw-int")) //return atPCM; ac3flags[i] = 0; if (caps) gst_caps_unref(caps); - //(ac3flags[i] > 2) ? ac3flags[i] = 1 : ac3flags[i] = 0; + //(ac3flags[i] > 2) ? ac3flags[i] = 1 : ac3flags[i] = 0; - g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags); + g_signal_emit_by_name(m_gst_playbin, "get-audio-tags", i, &tags); if (tags) { if (GST_IS_TAG_LIST(tags) && gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang)) @@ -990,21 +997,21 @@ void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *nu gst_tag_list_free(tags); } } - *numpida=i; + *numpida = i; } } void cPlayback::getMeta() { - if(playing) + if (playing) return; } bool cPlayback::SyncAV(void) { - hal_info( "%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + hal_info("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); - if(playing == false ) + if (playing == false) return false; return true; @@ -1049,18 +1056,20 @@ void cPlayback::GetMetadata(std::vector &keys, std::vector &keys, std::vector #include -typedef enum { +typedef enum +{ PLAYMODE_TS = 0, PLAYMODE_FILE, -} playmode_t; +} playmode_t; struct AVFormatContext; class cPlayback @@ -27,9 +28,15 @@ class cPlayback bool SetAPid(int pid, bool ac3); bool SetSubtitlePid(int pid); bool SetTeletextPid(int pid); - int GetAPid(void) { return mAudioStream; } + int GetAPid(void) + { + return mAudioStream; + } int GetVPid(void); - int GetSubtitlePid(void) { return mSubtitleStream; } + int GetSubtitlePid(void) + { + return mSubtitleStream; + } int GetTeletextPid(void); void SuspendSubtitle(bool); int GetFirstTeletextPid(void); @@ -39,14 +46,23 @@ class cPlayback void GetPts(uint64_t &pts); bool SetPosition(int position, bool absolute = false); void FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language); - void FindAllPids(uint16_t *apids, unsigned short *ac3flags, uint16_t *numpida, std::string *language) { FindAllPids((int*) apids, (unsigned int*) ac3flags, (unsigned int*) numpida, language); }; + void FindAllPids(uint16_t *apids, unsigned short *ac3flags, uint16_t *numpida, std::string *language) + { + FindAllPids((int *) apids, (unsigned int *) ac3flags, (unsigned int *) numpida, language); + }; void FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language); void FindAllTeletextsubtitlePids(int *pids, unsigned int *numpidt, std::string *tlanguage, int *mags, int *pages); void RequestAbort(void); - bool IsPlaying(void) { return false; } + bool IsPlaying(void) + { + return false; + } uint64_t GetReadCount(void); void FindAllSubs(int *pids, unsigned int *supported, unsigned int *numpida, std::string *language); - void FindAllSubs(uint16_t *pids, unsigned short *supported, uint16_t *numpida, std::string *language) { FindAllSubs((int*) pids, (unsigned int*) supported, (unsigned int*) numpida, language); }; + void FindAllSubs(uint16_t *pids, unsigned short *supported, uint16_t *numpida, std::string *language) + { + FindAllSubs((int *) pids, (unsigned int *) supported, (unsigned int *) numpida, language); + }; bool SelectSubtitles(int pid, std::string charset = ""); void GetTitles(std::vector &playlists, std::vector &titles, int ¤t); void SetTitle(int title); @@ -54,7 +70,10 @@ class cPlayback void GetMetadata(std::vector &keys, std::vector &values); // ~cPlayback(); - AVFormatContext *GetAVFormatContext(){ return NULL; } + AVFormatContext *GetAVFormatContext() + { + return NULL; + } void ReleaseAVFormatContext() {} }; diff --git a/libgeneric-pc/video.cpp b/libgeneric-pc/video.cpp index 9d7ec99..db9af04 100644 --- a/libgeneric-pc/video.cpp +++ b/libgeneric-pc/video.cpp @@ -65,13 +65,14 @@ extern bool HAL_nodec; static uint8_t *dmxbuf; static int bufpos; -static const AVRational aspect_ratios[6] = { +static const AVRational aspect_ratios[6] = +{ { 1, 1 }, { 4, 3 }, { 14, 9 }, { 16, 9 }, { 20, 9 }, - { -1,-1 } + { -1, -1 } }; cVideo::cVideo(int, void *, void *, unsigned int) @@ -133,15 +134,15 @@ int cVideo::getAspectRatio(void) ar = w * 100 * a.num / h / a.den; if (ar < 100 || ar > 225) /* < 4:3, > 20:9 */ ; /* ret = 0: N/A */ - else if (ar < 140) /* 4:3 */ + else if (ar < 140) /* 4:3 */ ret = 1; - else if (ar < 165) /* 14:9 */ + else if (ar < 165) /* 14:9 */ ret = 2; - else if (ar < 200) /* 16:9 */ + else if (ar < 200) /* 16:9 */ ret = 3; else - ret = 4; /* 20:9 */ - out: + ret = 4; /* 20:9 */ +out: buf_m.unlock(); return ret; } @@ -163,7 +164,8 @@ int cVideo::Start(void *, unsigned short, unsigned short, void *) int cVideo::Stop(bool) { hal_debug("%s running %d >\n", __func__, thread_running); - if (thread_running) { + if (thread_running) + { thread_running = false; OpenThreads::Thread::join(); } @@ -180,9 +182,9 @@ int cVideo::GetVideoSystem() { int current_video_system = VIDEO_STD_1080I50; - if(dec_w < 720) + if (dec_w < 720) current_video_system = VIDEO_STD_PAL; - else if(dec_w > 720 && dec_w <= 1280) + else if (dec_w > 720 && dec_w <= 1280) current_video_system = VIDEO_STD_720P50; return current_video_system; @@ -191,7 +193,7 @@ int cVideo::GetVideoSystem() int cVideo::SetVideoSystem(int system, bool) { int h; - switch(system) + switch (system) { case VIDEO_STD_NTSC: case VIDEO_STD_480P: @@ -211,7 +213,7 @@ int cVideo::SetVideoSystem(int system, bool) break; case VIDEO_STD_AUTO: hal_info("%s: VIDEO_STD_AUTO not implemented\n", __func__); - // fallthrough + // fallthrough case VIDEO_STD_SECAM: case VIDEO_STD_PAL: case VIDEO_STD_576P: @@ -261,17 +263,21 @@ bool cVideo::ShowPicture(const char *fname) AVFrame *frame, *rgbframe; AVPacket avpkt; - if (avformat_open_input(&avfc, fname, NULL, NULL) < 0) { + if (avformat_open_input(&avfc, fname, NULL, NULL) < 0) + { hal_info("%s: Could not open file %s\n", __func__, fname); return ret; } - if (avformat_find_stream_info(avfc, NULL) < 0) { + if (avformat_find_stream_info(avfc, NULL) < 0) + { hal_info("%s: Could not find file info %s\n", __func__, fname); goto out_close; } - for (i = 0; i < avfc->nb_streams; i++) { - if (avfc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + for (i = 0; i < avfc->nb_streams; i++) + { + if (avfc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + { stream_id = i; break; } @@ -281,24 +287,28 @@ bool cVideo::ShowPicture(const char *fname) p = avfc->streams[stream_id]->codecpar; codec = avcodec_find_decoder(p->codec_id); c = avcodec_alloc_context3(codec); - if (avcodec_open2(c, codec, NULL) < 0) { + if (avcodec_open2(c, codec, NULL) < 0) + { hal_info("%s: Could not find/open the codec, id 0x%x\n", __func__, p->codec_id); goto out_close; } frame = av_frame_alloc(); rgbframe = av_frame_alloc(); - if (!frame || !rgbframe) { + if (!frame || !rgbframe) + { hal_info("%s: Could not allocate video frame\n", __func__); goto out_free; } av_init_packet(&avpkt); - if (av_read_frame(avfc, &avpkt) < 0) { + if (av_read_frame(avfc, &avpkt) < 0) + { hal_info("%s: av_read_frame < 0\n", __func__); goto out_free; } #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) av_ret = avcodec_decode_video2(c, frame, &got_frame, &avpkt); - if (av_ret < 0) { + if (av_ret < 0) + { hal_info("%s: avcodec_decode_video2 %d\n", __func__, av_ret); av_packet_unref(&avpkt); goto out_free; @@ -307,7 +317,8 @@ bool cVideo::ShowPicture(const char *fname) hal_info("%s: WARN: pkt->size %d != len %d\n", __func__, avpkt.size, av_ret); #else av_ret = avcodec_send_packet(c, &avpkt); - if (av_ret != 0 && av_ret != AVERROR(EAGAIN)) { + if (av_ret != 0 && av_ret != AVERROR(EAGAIN)) + { hal_info("%s: avcodec_send_packet %d\n", __func__, av_ret); av_packet_unref(&avpkt); goto out_free; @@ -319,22 +330,24 @@ bool cVideo::ShowPicture(const char *fname) got_frame = 1; #endif - if (got_frame) { + if (got_frame) + { unsigned int need = av_image_get_buffer_size(VDEC_PIXFMT, c->width, c->height, 1); struct SwsContext *convert = sws_getContext(c->width, c->height, c->pix_fmt, - c->width, c->height, VDEC_PIXFMT, - SWS_BICUBIC, 0, 0, 0); + c->width, c->height, VDEC_PIXFMT, + SWS_BICUBIC, 0, 0, 0); if (!convert) hal_info("%s: ERROR setting up SWS context\n", __func__); - else { + else + { buf_m.lock(); SWFramebuffer *f = &buffers[buf_in]; if (f->size() < need) f->resize(need); av_image_fill_arrays(rgbframe->data, rgbframe->linesize, &(*f)[0], VDEC_PIXFMT, - c->width, c->height, 1); + c->width, c->height, 1); sws_scale(convert, frame->data, frame->linesize, 0, c->height, - rgbframe->data, rgbframe->linesize); + rgbframe->data, rgbframe->linesize); sws_freeContext(convert); f->width(c->width); f->height(c->height); @@ -344,7 +357,8 @@ bool cVideo::ShowPicture(const char *fname) buf_in++; buf_in %= VDEC_MAXBUFS; buf_num++; - if (buf_num > (VDEC_MAXBUFS - 1)) { + if (buf_num > (VDEC_MAXBUFS - 1)) + { hal_debug("%s: buf_num overflow\n", __func__); buf_out++; buf_out %= VDEC_MAXBUFS; @@ -355,12 +369,12 @@ bool cVideo::ShowPicture(const char *fname) } } av_packet_unref(&avpkt); - out_free: +out_free: avcodec_close(c); av_free(c); av_frame_free(&frame); av_frame_free(&rgbframe); - out_close: +out_close: avformat_close_input(&avfc); hal_debug("%s(%s) end\n", __func__, fname); return ret; @@ -396,7 +410,8 @@ void cVideo::getPictureInfo(int &width, int &height, int &rate) { width = dec_w; height = dec_h; - switch (dec_r) { + switch (dec_r) + { case 23://23.976fps rate = VIDEO_FRAME_RATE_23_976; break; @@ -437,7 +452,8 @@ int cVideo::SetStreamType(VIDEO_FORMAT v) cVideo::SWFramebuffer *cVideo::getDecBuf(void) { buf_m.lock(); - if (buf_num == 0) { + if (buf_num == 0) + { buf_m.unlock(); return NULL; } @@ -452,8 +468,10 @@ cVideo::SWFramebuffer *cVideo::getDecBuf(void) static int my_read(void *, uint8_t *buf, int buf_size) { int tmp = 0; - if (videoDecoder && bufpos < DMX_BUF_SZ - 4096) { - while (bufpos < buf_size && ++tmp < 20) { /* retry max 20 times */ + if (videoDecoder && bufpos < DMX_BUF_SZ - 4096) + { + while (bufpos < buf_size && ++tmp < 20) /* retry max 20 times */ + { int ret = videoDemux->Read(dmxbuf + bufpos, DMX_BUF_SZ - bufpos, 20); if (ret > 0) bufpos += ret; @@ -461,7 +479,8 @@ static int my_read(void *, uint8_t *buf, int buf_size) } if (bufpos == 0) return 0; - if (bufpos > buf_size) { + if (bufpos > buf_size) + { memcpy(buf, dmxbuf, buf_size); memmove(dmxbuf, dmxbuf + buf_size, bufpos - buf_size); bufpos -= buf_size; @@ -478,7 +497,7 @@ void cVideo::run(void) hal_info("====================== start decoder thread ================================\n"); AVCodec *codec; AVCodecParameters *p = NULL; - AVCodecContext *c= NULL; + AVCodecContext *c = NULL; AVFormatContext *avfc = NULL; AVInputFormat *inp; AVFrame *frame, *rgbframe; @@ -499,18 +518,19 @@ void cVideo::run(void) av_init_packet(&avpkt); inp = av_find_input_format("mpegts"); AVIOContext *pIOCtx = avio_alloc_context(inbuf, INBUF_SIZE, // internal Buffer and its size - 0, // bWriteable (1=true,0=false) - NULL, // user data; will be passed to our callback functions - my_read, // read callback - NULL, // write callback - NULL); // seek callback + 0, // bWriteable (1=true,0=false) + NULL, // user data; will be passed to our callback functions + my_read, // read callback + NULL, // write callback + NULL); // seek callback avfc = avformat_alloc_context(); avfc->pb = pIOCtx; avfc->iformat = inp; - avfc->probesize = 188*5; + avfc->probesize = 188 * 5; thread_running = true; - if (avformat_open_input(&avfc, NULL, inp, NULL) < 0) { + if (avformat_open_input(&avfc, NULL, inp, NULL) < 0) + { hal_info("%s: Could not open input\n", __func__); goto out; } @@ -529,25 +549,31 @@ void cVideo::run(void) hal_info("%s: no video codec? 0x%x\n", __func__, p->codec_type); codec = avcodec_find_decoder(p->codec_id); - if (!codec) { + if (!codec) + { hal_info("%s: Codec for %s not found\n", __func__, avcodec_get_name(p->codec_id)); goto out; } c = avcodec_alloc_context3(codec); - if (avcodec_open2(c, codec, NULL) < 0) { + if (avcodec_open2(c, codec, NULL) < 0) + { hal_info("%s: Could not open codec\n", __func__); goto out; } frame = av_frame_alloc(); rgbframe = av_frame_alloc(); - if (!frame || !rgbframe) { + if (!frame || !rgbframe) + { hal_info("%s: Could not allocate video frame\n", __func__); goto out2; } hal_info("decoding %s\n", avcodec_get_name(c->codec_id)); - while (thread_running) { - if (av_read_frame(avfc, &avpkt) < 0) { - if (warn_r - time(NULL) > 4) { + while (thread_running) + { + if (av_read_frame(avfc, &avpkt) < 0) + { + if (warn_r - time(NULL) > 4) + { hal_info("%s: av_read_frame < 0\n", __func__); warn_r = time(NULL); } @@ -557,8 +583,10 @@ void cVideo::run(void) int got_frame = 0; #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) av_ret = avcodec_decode_video2(c, frame, &got_frame, &avpkt); - if (av_ret < 0) { - if (warn_d - time(NULL) > 4) { + if (av_ret < 0) + { + if (warn_d - time(NULL) > 4) + { hal_info("%s: avcodec_decode_video2 %d\n", __func__, av_ret); warn_d = time(NULL); } @@ -569,8 +597,10 @@ void cVideo::run(void) hal_info("%s: WARN: pkt->size %d != len %d\n", __func__, avpkt.size, av_ret); #else av_ret = avcodec_send_packet(c, &avpkt); - if (av_ret != 0 && av_ret != AVERROR(EAGAIN)) { - if (warn_d - time(NULL) > 4) { + if (av_ret != 0 && av_ret != AVERROR(EAGAIN)) + { + if (warn_d - time(NULL) > 4) + { hal_info("%s: avcodec_send_packet %d\n", __func__, av_ret); warn_d = time(NULL); } @@ -582,26 +612,29 @@ void cVideo::run(void) got_frame = 1; #endif still_m.lock(); - if (got_frame && ! stillpicture) { + if (got_frame && ! stillpicture) + { unsigned int need = av_image_get_buffer_size(VDEC_PIXFMT, c->width, c->height, 1); convert = sws_getCachedContext(convert, - c->width, c->height, c->pix_fmt, - c->width, c->height, VDEC_PIXFMT, - SWS_BICUBIC, 0, 0, 0); + c->width, c->height, c->pix_fmt, + c->width, c->height, VDEC_PIXFMT, + SWS_BICUBIC, 0, 0, 0); if (!convert) hal_info("%s: ERROR setting up SWS context\n", __func__); - else { + else + { buf_m.lock(); SWFramebuffer *f = &buffers[buf_in]; if (f->size() < need) f->resize(need); av_image_fill_arrays(rgbframe->data, rgbframe->linesize, &(*f)[0], VDEC_PIXFMT, - c->width, c->height, 1); + c->width, c->height, 1); sws_scale(convert, frame->data, frame->linesize, 0, c->height, - rgbframe->data, rgbframe->linesize); - if (dec_w != c->width || dec_h != c->height) { + rgbframe->data, rgbframe->linesize); + if (dec_w != c->width || dec_h != c->height) + { hal_info("%s: pic changed %dx%d -> %dx%d\n", __func__, - dec_w, dec_h, c->width, c->height); + dec_w, dec_h, c->width, c->height); dec_w = c->width; dec_h = c->height; w_h_changed = true; @@ -616,14 +649,14 @@ void cVideo::run(void) /* a/v delay determined experimentally :-) */ #if USE_OPENGL if (v_format == VIDEO_FORMAT_MPEG2) - vpts += 90000*4/10; /* 400ms */ + vpts += 90000 * 4 / 10; /* 400ms */ else - vpts += 90000*3/10; /* 300ms */ + vpts += 90000 * 3 / 10; /* 300ms */ #endif #if USE_CLUTTER /* no idea why there's a difference between OpenGL and clutter rendering... */ if (v_format == VIDEO_FORMAT_MPEG2) - vpts += 90000*3/10; /* 300ms */ + vpts += 90000 * 3 / 10; /* 300ms */ #endif f->pts(vpts); AVRational a = av_guess_sample_aspect_ratio(avfc, avfc->streams[0], frame); @@ -631,41 +664,44 @@ void cVideo::run(void) buf_in++; buf_in %= VDEC_MAXBUFS; buf_num++; - if (buf_num > (VDEC_MAXBUFS - 1)) { + if (buf_num > (VDEC_MAXBUFS - 1)) + { hal_debug("%s: buf_num overflow\n", __func__); buf_out++; buf_out %= VDEC_MAXBUFS; buf_num--; } - dec_r = c->time_base.den/(c->time_base.num * c->ticks_per_frame); + dec_r = c->time_base.den / (c->time_base.num * c->ticks_per_frame); buf_m.unlock(); } hal_debug("%s: time_base: %d/%d, ticks: %d rate: %d pts 0x%" PRIx64 "\n", __func__, - c->time_base.num, c->time_base.den, c->ticks_per_frame, dec_r, + c->time_base.num, c->time_base.den, c->ticks_per_frame, dec_r, #if (LIBAVUTIL_VERSION_MAJOR < 54) - av_frame_get_best_effort_timestamp(frame)); + av_frame_get_best_effort_timestamp(frame)); #else - frame->best_effort_timestamp); + frame->best_effort_timestamp); #endif - } else + } + else hal_debug("%s: got_frame: %d stillpicture: %d\n", __func__, got_frame, stillpicture); still_m.unlock(); av_packet_unref(&avpkt); } sws_freeContext(convert); - out2: +out2: avcodec_close(c); av_free(c); av_frame_free(&frame); av_frame_free(&rgbframe); - out: +out: avformat_close_input(&avfc); av_free(pIOCtx->buffer); av_free(pIOCtx); /* reset output buffers */ bufpos = 0; still_m.lock(); - if (!stillpicture) { + if (!stillpicture) + { buf_num = 0; buf_in = 0; buf_out = 0; @@ -680,50 +716,57 @@ static bool swscale(unsigned char *src, unsigned char *dst, int sw, int sh, int int len = 0; struct SwsContext *scale = NULL; scale = sws_getCachedContext(scale, sw, sh, sfmt, dw, dh, AV_PIX_FMT_RGB32, SWS_BICUBIC, 0, 0, 0); - if (!scale) { + if (!scale) + { hal_info_c("%s: ERROR setting up SWS context\n", __func__); return ret; } AVFrame *sframe = av_frame_alloc(); AVFrame *dframe = av_frame_alloc(); - if (sframe && dframe) { + if (sframe && dframe) + { len = av_image_fill_arrays(sframe->data, sframe->linesize, &(src)[0], sfmt, sw, sh, 1); - if(len>-1) + if (len > -1) ret = true; - if(ret && (len = av_image_fill_arrays(dframe->data, dframe->linesize, &(dst)[0], AV_PIX_FMT_RGB32, dw, dh, 1)<0)) + if (ret && (len = av_image_fill_arrays(dframe->data, dframe->linesize, &(dst)[0], AV_PIX_FMT_RGB32, dw, dh, 1) < 0)) ret = false; - if(ret && (len = sws_scale(scale, sframe->data, sframe->linesize, 0, sh, dframe->data, dframe->linesize)<0)) + if (ret && (len = sws_scale(scale, sframe->data, sframe->linesize, 0, sh, dframe->data, dframe->linesize) < 0)) ret = false; else ret = true; - }else{ + } + else + { hal_info_c("%s: could not alloc sframe (%p) or dframe (%p)\n", __func__, sframe, dframe); ret = false; } - if(sframe){ + if (sframe) + { av_frame_free(&sframe); sframe = NULL; } - if(dframe){ + if (dframe) + { av_frame_free(&dframe); dframe = NULL; } - if(scale){ + if (scale) + { sws_freeContext(scale); scale = NULL; } - hal_info_c("%s: %s scale %ix%i to %ix%i ,len %i\n",ret?" ":"ERROR",__func__, sw, sh, dw, dh,len); + hal_info_c("%s: %s scale %ix%i to %ix%i ,len %i\n", ret ? " " : "ERROR", __func__, sw, sh, dw, dh, len); return ret; } -bool cVideo::GetScreenImage(unsigned char * &data, int &xres, int &yres, bool get_video, bool get_osd, bool scale_to_video) +bool cVideo::GetScreenImage(unsigned char *&data, int &xres, int &yres, bool get_video, bool get_osd, bool scale_to_video) { hal_info("%s: data 0x%p xres %d yres %d vid %d osd %d scale %d\n", - __func__, data, xres, yres, get_video, get_osd, scale_to_video); + __func__, data, xres, yres, get_video, get_osd, scale_to_video); SWFramebuffer video; std::vector *osd = NULL; std::vector s_osd; /* scaled OSD */ @@ -732,13 +775,15 @@ bool cVideo::GetScreenImage(unsigned char * &data, int &xres, int &yres, bool ge int osd_h = glfb_priv->getOSDHeight(); xres = osd_w; yres = osd_h; - if (get_video) { + if (get_video) + { buf_m.lock(); video = buffers[buf_out]; buf_m.unlock(); vid_w = video.width(); vid_h = video.height(); - if (scale_to_video || !get_osd) { + if (scale_to_video || !get_osd) + { xres = vid_w; yres = vid_h; AVRational a = video.AR(); @@ -747,8 +792,9 @@ bool cVideo::GetScreenImage(unsigned char * &data, int &xres, int &yres, bool ge xres = vid_w * a.num / a.den; } } - if(video.empty()){ - get_video=false; + if (video.empty()) + { + get_video = false; xres = osd_w; yres = osd_h; } @@ -756,53 +802,66 @@ bool cVideo::GetScreenImage(unsigned char * &data, int &xres, int &yres, bool ge osd = glfb_priv->getOSDBuffer(); unsigned int need = av_image_get_buffer_size(AV_PIX_FMT_RGB32, xres, yres, 1); data = (unsigned char *)realloc(data, need); /* will be freed by caller */ - if (data == NULL) /* out of memory? */ + if (data == NULL) /* out of memory? */ return false; - if (get_video) { + if (get_video) + { #if USE_OPENGL //memcpy dont work with copy BGR24 to RGB32 - if (vid_w != xres || vid_h != yres){ /* scale video into data... */ + if (vid_w != xres || vid_h != yres) /* scale video into data... */ + { #endif - bool ret = swscale(&video[0], data, vid_w, vid_h, xres, yres,VDEC_PIXFMT); - if(!ret){ + bool ret = swscale(&video[0], data, vid_w, vid_h, xres, yres, VDEC_PIXFMT); + if (!ret) + { free(data); return false; } #if USE_OPENGL //memcpy dont work with copy BGR24 to RGB32 - }else{ /* get_video and no fancy scaling needed */ + } + else /* get_video and no fancy scaling needed */ + { memcpy(data, &video[0], xres * yres * sizeof(uint32_t)); } #endif } - if (get_osd && (osd_w != xres || osd_h != yres)) { + if (get_osd && (osd_w != xres || osd_h != yres)) + { /* rescale osd */ s_osd.resize(need); - bool ret = swscale(&(*osd)[0], &s_osd[0], osd_w, osd_h, xres, yres,AV_PIX_FMT_RGB32); - if(!ret){ + bool ret = swscale(&(*osd)[0], &s_osd[0], osd_w, osd_h, xres, yres, AV_PIX_FMT_RGB32); + if (!ret) + { free(data); return false; } osd = &s_osd; } - if (get_video && get_osd) { + if (get_video && get_osd) + { /* alpha blend osd onto data (video). TODO: maybe libavcodec can do this? */ uint32_t *d = (uint32_t *)data; - uint32_t *pixpos = (uint32_t *)&(*osd)[0]; - for (int count = 0; count < yres; count++) { - for (int count2 = 0; count2 < xres; count2++ ) { + uint32_t *pixpos = (uint32_t *) & (*osd)[0]; + for (int count = 0; count < yres; count++) + { + for (int count2 = 0; count2 < xres; count2++) + { uint32_t pix = *pixpos; if ((pix & 0xff000000) == 0xff000000) *d = pix; - else { + else + { uint8_t *in = (uint8_t *)(pixpos); uint8_t *out = (uint8_t *)d; - int a = in[3]; /* TODO: big/little endian? */ + int a = in[3]; /* TODO: big/little endian? */ *out = (*out + ((*in - *out) * a) / 256); - in++; out++; + in++; + out++; *out = (*out + ((*in - *out) * a) / 256); - in++; out++; + in++; + out++; *out = (*out + ((*in - *out) * a) / 256); } d++; diff --git a/libgeneric-pc/video_lib.h b/libgeneric-pc/video_lib.h index c4b903b..a30f976 100644 --- a/libgeneric-pc/video_lib.h +++ b/libgeneric-pc/video_lib.h @@ -11,7 +11,8 @@ extern "C" { #include } -typedef enum { +typedef enum +{ ANALOG_SD_RGB_CINCH = 0x00, ANALOG_SD_YPRPB_CINCH, ANALOG_HD_RGB_CINCH, @@ -23,7 +24,8 @@ typedef enum { ANALOG_SCART_MASK = 0x10 } analog_mode_t; -typedef enum { +typedef enum +{ VIDEO_FORMAT_MPEG2 = 0, VIDEO_FORMAT_MPEG4_H264, VIDEO_FORMAT_VC1, @@ -34,7 +36,8 @@ typedef enum { VIDEO_FORMAT_AVS = 16 } VIDEO_FORMAT; -typedef enum { +typedef enum +{ VIDEO_SD = 0, VIDEO_HD, VIDEO_120x60i, @@ -43,7 +46,8 @@ typedef enum { VIDEO_360x288i } VIDEO_DEFINITION; -typedef enum { +typedef enum +{ VIDEO_FRAME_RATE_23_976 = 0, VIDEO_FRAME_RATE_24, VIDEO_FRAME_RATE_25, @@ -54,7 +58,8 @@ typedef enum { VIDEO_FRAME_RATE_60 } VIDEO_FRAME_RATE; -typedef enum { +typedef enum +{ DISPLAY_AR_1_1, DISPLAY_AR_4_3, DISPLAY_AR_14_9, @@ -63,20 +68,23 @@ typedef enum { DISPLAY_AR_RAW } DISPLAY_AR; -typedef enum { +typedef enum +{ DISPLAY_AR_MODE_PANSCAN = 0, DISPLAY_AR_MODE_LETTERBOX, DISPLAY_AR_MODE_NONE, DISPLAY_AR_MODE_PANSCAN2 } DISPLAY_AR_MODE; -typedef enum { +typedef enum +{ VIDEO_DB_DR_NEITHER = 0, VIDEO_DB_ON, VIDEO_DB_DR_BOTH } VIDEO_DB_DR; -typedef enum { +typedef enum +{ VIDEO_PLAY_STILL = 0, VIDEO_PLAY_CLIP, VIDEO_PLAY_TRICK, @@ -84,7 +92,8 @@ typedef enum { VIDEO_PLAY_MOTION_NO_SYNC } VIDEO_PLAY_MODE; -typedef enum { +typedef enum +{ VIDEO_STD_NTSC, VIDEO_STD_SECAM, VIDEO_STD_PAL, @@ -98,7 +107,7 @@ typedef enum { VIDEO_STD_1080P24, VIDEO_STD_1080P25, VIDEO_STD_AUTO, - VIDEO_STD_1080P50, /* SPARK only */ + VIDEO_STD_1080P50, /* SPARK only */ VIDEO_STD_1080P60, VIDEO_STD_1080P2397, VIDEO_STD_1080P2997, @@ -110,13 +119,15 @@ typedef enum { } VIDEO_STD; /* not used, for dummy functions */ -typedef enum { +typedef enum +{ VIDEO_HDMI_CEC_MODE_OFF = 0, VIDEO_HDMI_CEC_MODE_TUNER, VIDEO_HDMI_CEC_MODE_RECORDER } VIDEO_HDMI_CEC_MODE; -typedef enum { +typedef enum +{ VIDEO_HDMI_CEC_VOL_OFF = 0, VIDEO_HDMI_CEC_VOL_AUDIOSYSTEM = 1, VIDEO_HDMI_CEC_VOL_TV = 2 @@ -136,27 +147,51 @@ typedef enum #define VDEC_MAXBUFS 0x40 class cVideo : public OpenThreads::Thread { - friend class GLFbPC; - friend class cDemux; + friend class GLFbPC; + friend class cDemux; private: /* called from GL thread */ class SWFramebuffer : public std::vector { - public: - SWFramebuffer() : mWidth(0), mHeight(0) {} - void width(int w) { mWidth = w; } - void height(int h) { mHeight = h; } - void pts(uint64_t p) { mPts = p; } - void AR(AVRational a) { mAR = a; } - int width() const { return mWidth; } - int height() const { return mHeight; } - int64_t pts() const { return mPts; } - AVRational AR() const { return mAR; } - private: - int mWidth; - int mHeight; - int64_t mPts; - AVRational mAR; + public: + SWFramebuffer() : mWidth(0), mHeight(0) {} + void width(int w) + { + mWidth = w; + } + void height(int h) + { + mHeight = h; + } + void pts(uint64_t p) + { + mPts = p; + } + void AR(AVRational a) + { + mAR = a; + } + int width() const + { + return mWidth; + } + int height() const + { + return mHeight; + } + int64_t pts() const + { + return mPts; + } + AVRational AR() const + { + return mAR; + } + private: + int mWidth; + int mHeight; + int64_t mPts; + AVRational mAR; }; int buf_in, buf_out, buf_num; int64_t GetPTS(void); @@ -165,8 +200,14 @@ class cVideo : public OpenThreads::Thread cVideo(int mode, void *, void *, unsigned int unit = 0); ~cVideo(void); - void * GetTVEnc() { return NULL; }; - void * GetTVEncSD() { return NULL; }; + void *GetTVEnc() + { + return NULL; + }; + void *GetTVEncSD() + { + return NULL; + }; /* aspect ratio */ int getAspectRatio(void); @@ -193,29 +234,68 @@ class cVideo : public OpenThreads::Thread bool Pause(void); int SetStreamType(VIDEO_FORMAT type); - bool ShowPicture(const char * fname); + bool ShowPicture(const char *fname); void SetSyncMode(AVSYNC_TYPE mode); - bool SetCECMode(VIDEO_HDMI_CEC_MODE) { return true; }; - void SetCECAutoView(bool) { return; }; - void SetCECAutoStandby(bool) { return; }; - int GetAudioDestination() { return 0; }; - void SetAudioDestination(int audio_dest) { return; }; + bool SetCECMode(VIDEO_HDMI_CEC_MODE) + { + return true; + }; + void SetCECAutoView(bool) + { + return; + }; + void SetCECAutoStandby(bool) + { + return; + }; + int GetAudioDestination() + { + return 0; + }; + void SetAudioDestination(int audio_dest) + { + return; + }; void StopPicture(); void Standby(unsigned int bOn); void Pig(int x, int y, int w, int h, int osd_w = 1064, int osd_h = 600, int startx = 0, int starty = 0, int endx = 1279, int endy = 719); - void SetControl(int, int) { return; }; + void SetControl(int, int) + { + return; + }; void setContrast(int val); void SetVideoMode(analog_mode_t mode); - void SetDBDR(int) { return; }; - void SetAudioHandle(void *) { return; }; - void SetAutoModes(int [VIDEO_STD_MAX]) { return; }; - int OpenVBI(int) { return 0; }; - int CloseVBI(void) { return 0; }; - int StartVBI(unsigned short) { return 0; }; - int StopVBI(void) { return 0; }; + void SetDBDR(int) + { + return; + }; + void SetAudioHandle(void *) + { + return; + }; + void SetAutoModes(int [VIDEO_STD_MAX]) + { + return; + }; + int OpenVBI(int) + { + return 0; + }; + int CloseVBI(void) + { + return 0; + }; + int StartVBI(unsigned short) + { + return 0; + }; + int StopVBI(void) + { + return 0; + }; void SetDemux(cDemux *dmx); - bool GetScreenImage(unsigned char * &data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); + bool GetScreenImage(unsigned char *&data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); SWFramebuffer *getDecBuf(void); private: void run(); diff --git a/libmipsbox/hardware_caps.c b/libmipsbox/hardware_caps.c index f6f3354..14917fd 100644 --- a/libmipsbox/hardware_caps.c +++ b/libmipsbox/hardware_caps.c @@ -39,7 +39,7 @@ hw_caps_t *get_hwcaps(void) caps.display_type = HW_DISPLAY_LINE_TEXT; caps.display_can_deepstandby = 1; caps.display_can_set_brightness = 1; - caps.display_can_umlauts = 0; /* need test */ + caps.display_can_umlauts = 0; /* need test */ caps.display_has_statusline = 0; caps.display_has_colon = 0; caps.has_button_timer = 1; diff --git a/libraspi/audio.cpp b/libraspi/audio.cpp index e3af057..110b7b7 100644 --- a/libraspi/audio.cpp +++ b/libraspi/audio.cpp @@ -27,7 +27,7 @@ #define hal_debug(args...) _hal_debug(HAL_DEBUG_AUDIO, this, args) #define hal_info(args...) _hal_info(HAL_DEBUG_AUDIO, this, args) -cAudio * audioDecoder = NULL; +cAudio *audioDecoder = NULL; cAudio::cAudio(void *, void *, void *) { @@ -114,12 +114,12 @@ int cAudio::StopClip() void cAudio::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode) { type = 0; - layer = 0; /* not used */ + layer = 0; /* not used */ freq = 0; - bitrate = 0; /* not used, but easy to get :-) */ - mode = 0; /* default: stereo */ + bitrate = 0; /* not used, but easy to get :-) */ + mode = 0; /* default: stereo */ hal_debug("%s t: %d l: %d f: %d b: %d m: %d\n", - __func__, type, layer, freq, bitrate, mode); + __func__, type, layer, freq, bitrate, mode); }; void cAudio::SetSRS(int /*iq_enable*/, int /*nmgr_enable*/, int /*iq_mode*/, int /*iq_level*/) diff --git a/libraspi/audio_lib.h b/libraspi/audio_lib.h index c039853..cbe0278 100644 --- a/libraspi/audio_lib.h +++ b/libraspi/audio_lib.h @@ -13,7 +13,8 @@ typedef enum AUDIO_SYNC_AUDIO_MASTER } AUDIO_SYNC_MODE; -typedef enum { +typedef enum +{ HDMI_ENCODED_OFF, HDMI_ENCODED_AUTO, HDMI_ENCODED_FORCED @@ -39,7 +40,7 @@ typedef enum class cAudio { - friend class cPlayback; + friend class cPlayback; private: int fd; bool Muted; @@ -48,7 +49,7 @@ class cAudio int mixer_fd; /* if we are using the OSS mixer */ int mixer_num; /* oss mixer to use, if any */ - AUDIO_FORMAT StreamType; + AUDIO_FORMAT StreamType; AUDIO_SYNC_MODE SyncMode; bool started; bool thread_started; @@ -66,17 +67,35 @@ class cAudio /* construct & destruct */ cAudio(void *, void *, void *); ~cAudio(void); - int64_t getPts() { return curr_pts; } + int64_t getPts() + { + return curr_pts; + } - void *GetHandle() { return NULL; }; + void *GetHandle() + { + return NULL; + }; /* shut up */ - int mute(bool remember = true) { return do_mute(true, remember); }; - int unmute(bool remember = true) { return do_mute(false, remember); }; + int mute(bool remember = true) + { + return do_mute(true, remember); + }; + int unmute(bool remember = true) + { + return do_mute(false, remember); + }; /* volume, min = 0, max = 255 */ int setVolume(unsigned int left, unsigned int right); - int getVolume(void) { return volume;} - bool getMuteStatus(void) { return Muted; }; + int getVolume(void) + { + return volume; + } + bool getMuteStatus(void) + { + return Muted; + }; /* start and stop audio */ int Start(void); @@ -88,9 +107,9 @@ class cAudio /* select channels */ int setChannel(int channel); int PrepareClipPlay(int uNoOfChannels, int uSampleRate, int uBitsPerSample, int bLittleEndian); - int WriteClip(unsigned char * buffer, int size); + int WriteClip(unsigned char *buffer, int size); int StopClip(); - void getAudioInfo(int &type, int &layer, int& freq, int &bitrate, int &mode); + void getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode); void SetSRS(int iq_enable, int nmgr_enable, int iq_mode, int iq_level); bool IsHdmiDDSupported(); void SetHdmiDD(bool enable); diff --git a/libraspi/dmx.cpp b/libraspi/dmx.cpp index 76dcd0c..48c86fd 100644 --- a/libraspi/dmx.cpp +++ b/libraspi/dmx.cpp @@ -44,15 +44,16 @@ extern cVideo *videoDecoder; #define hal_info_c(args...) _hal_info(HAL_DEBUG_DEMUX, NULL, args) #define dmx_err(_errfmt, _errstr, _revents) do { \ - hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ -} while(0); + hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ + __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ + } while(0); cDemux *videoDemux = NULL; cDemux *audioDemux = NULL; //cDemux *pcrDemux = NULL; -static const char *DMX_T[] = { +static const char *DMX_T[] = +{ "DMX_INVALID", "DMX_VIDEO", "DMX_AUDIO", @@ -64,7 +65,8 @@ static const char *DMX_T[] = { }; /* map the device numbers. for now only demux0 is used */ -static const char *devname[] = { +static const char *devname[] = +{ "/dev/dvb/adapter0/demux0", "/dev/dvb/adapter0/demux0", "/dev/dvb/adapter0/demux0" @@ -95,7 +97,7 @@ cDemux::~cDemux() bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBufferSize) { int devnum = num; - int flags = O_RDWR|O_CLOEXEC; + int flags = O_RDWR | O_CLOEXEC; if (fd > -1) hal_info("%s FD ALREADY OPENED? fd = %d\n", __FUNCTION__, fd); @@ -110,12 +112,12 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe return false; } hal_debug("%s #%d pes_type: %s(%d), uBufferSize: %d fd: %d\n", __func__, - num, DMX_T[pes_type], pes_type, uBufferSize, fd); + num, DMX_T[pes_type], pes_type, uBufferSize, fd); if (dmx_type == DMX_VIDEO_CHANNEL) - uBufferSize = 0x100000; /* 1MB */ + uBufferSize = 0x100000; /* 1MB */ if (dmx_type == DMX_AUDIO_CHANNEL) - uBufferSize = 0x10000; /* 64k */ + uBufferSize = 0x10000; /* 64k */ #if 0 if (!pesfds.empty()) { @@ -190,17 +192,17 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) #if 0 if (len != 4095 && timeout != 100) fprintf(stderr, "cDemux::%s #%d fd: %d type: %s len: %d timeout: %d\n", - __FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout); + __FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout); #endif int rc; struct pollfd ufds; ufds.fd = fd; - ufds.events = POLLIN|POLLPRI|POLLERR; + ufds.events = POLLIN | POLLPRI | POLLERR; ufds.revents = 0; if (timeout > 0) { - retry: +retry: rc = ::poll(&ufds, 1, timeout); if (!rc) return 0; // timeout @@ -241,9 +243,9 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return rc; } -bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, - const unsigned char * const mask, int len, int timeout, - const unsigned char * const negmask) +bool cDemux::sectionFilter(unsigned short _pid, const unsigned char *const filter, + const unsigned char *const mask, int len, int timeout, + const unsigned char *const negmask) { struct dmx_sct_filter_params s_flt; memset(&s_flt, 0, sizeof(s_flt)); @@ -262,79 +264,80 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt if (negmask != NULL) memcpy(s_flt.filter.mode, negmask, len); - s_flt.flags = DMX_IMMEDIATE_START|DMX_CHECK_CRC; + s_flt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; int to = 0; - switch (filter[0]) { - case 0x00: /* program_association_section */ - to = 2000; - break; - case 0x01: /* conditional_access_section */ - to = 6000; - break; - case 0x02: /* program_map_section */ - to = 1500; - break; - case 0x03: /* transport_stream_description_section */ - to = 10000; - break; - /* 0x04 - 0x3F: reserved */ - case 0x40: /* network_information_section - actual_network */ - to = 10000; - break; - case 0x41: /* network_information_section - other_network */ - to = 15000; - break; - case 0x42: /* service_description_section - actual_transport_stream */ - to = 10000; - break; - /* 0x43 - 0x45: reserved for future use */ - case 0x46: /* service_description_section - other_transport_stream */ - to = 10000; - break; - /* 0x47 - 0x49: reserved for future use */ - case 0x4A: /* bouquet_association_section */ - to = 11000; - break; - /* 0x4B - 0x4D: reserved for future use */ - case 0x4E: /* event_information_section - actual_transport_stream, present/following */ - to = 2000; - break; - case 0x4F: /* event_information_section - other_transport_stream, present/following */ - to = 10000; - break; - /* 0x50 - 0x5F: event_information_section - actual_transport_stream, schedule */ - /* 0x60 - 0x6F: event_information_section - other_transport_stream, schedule */ - case 0x70: /* time_date_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - //s_flt.pid = 0x0014; - to = 30000; - break; - case 0x71: /* running_status_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - to = 0; - break; - case 0x72: /* stuffing_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - to = 0; - break; - case 0x73: /* time_offset_section */ - //s_flt.pid = 0x0014; - to = 30000; - break; - /* 0x74 - 0x7D: reserved for future use */ - case 0x7E: /* discontinuity_information_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - to = 0; - break; - case 0x7F: /* selection_information_section */ - to = 0; - break; - /* 0x80 - 0x8F: ca_message_section */ - /* 0x90 - 0xFE: user defined */ - /* 0xFF: reserved */ - default: - break; + switch (filter[0]) + { + case 0x00: /* program_association_section */ + to = 2000; + break; + case 0x01: /* conditional_access_section */ + to = 6000; + break; + case 0x02: /* program_map_section */ + to = 1500; + break; + case 0x03: /* transport_stream_description_section */ + to = 10000; + break; + /* 0x04 - 0x3F: reserved */ + case 0x40: /* network_information_section - actual_network */ + to = 10000; + break; + case 0x41: /* network_information_section - other_network */ + to = 15000; + break; + case 0x42: /* service_description_section - actual_transport_stream */ + to = 10000; + break; + /* 0x43 - 0x45: reserved for future use */ + case 0x46: /* service_description_section - other_transport_stream */ + to = 10000; + break; + /* 0x47 - 0x49: reserved for future use */ + case 0x4A: /* bouquet_association_section */ + to = 11000; + break; + /* 0x4B - 0x4D: reserved for future use */ + case 0x4E: /* event_information_section - actual_transport_stream, present/following */ + to = 2000; + break; + case 0x4F: /* event_information_section - other_transport_stream, present/following */ + to = 10000; + break; + /* 0x50 - 0x5F: event_information_section - actual_transport_stream, schedule */ + /* 0x60 - 0x6F: event_information_section - other_transport_stream, schedule */ + case 0x70: /* time_date_section */ + s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ + //s_flt.pid = 0x0014; + to = 30000; + break; + case 0x71: /* running_status_section */ + s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ + to = 0; + break; + case 0x72: /* stuffing_section */ + s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ + to = 0; + break; + case 0x73: /* time_offset_section */ + //s_flt.pid = 0x0014; + to = 30000; + break; + /* 0x74 - 0x7D: reserved for future use */ + case 0x7E: /* discontinuity_information_section */ + s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ + to = 0; + break; + case 0x7F: /* selection_information_section */ + to = 0; + break; + /* 0x80 - 0x8F: ca_message_section */ + /* 0x90 - 0xFE: user defined */ + /* 0xFF: reserved */ + default: + break; // return -1; } /* the negmask == NULL is a hack: the users of negmask are PMT-update @@ -344,15 +347,22 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt s_flt.timeout = to; hal_debug("%s #%d pid:0x%04hx fd:%d type:%s len:%d to:%d flags:%x flt[0]:%02x\n", __func__, num, - pid, fd, DMX_T[dmx_type], len, s_flt.timeout,s_flt.flags, s_flt.filter.filter[0]); + pid, fd, DMX_T[dmx_type], len, s_flt.timeout, s_flt.flags, s_flt.filter.filter[0]); - if (debuglevel == 2) { - fprintf(stderr,"filt: ");for(int i=0;i= 0x0002 && pid <= 0x000f) || pid >= 0x1fff) return false; @@ -380,31 +390,32 @@ bool cDemux::pesFilter(const unsigned short _pid) p_flt.output = DMX_OUT_DECODER; p_flt.input = DMX_IN_FRONTEND; - switch (dmx_type) { - case DMX_PCR_ONLY_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TAP; - return true; - break; - case DMX_AUDIO_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TSDEMUX_TAP; - break; - case DMX_VIDEO_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TSDEMUX_TAP; - break; - case DMX_PES_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TAP; - break; - case DMX_TP_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TSDEMUX_TAP; - break; - default: - hal_info("%s #%d invalid dmx_type %d!\n", __func__, num, dmx_type); - return false; + switch (dmx_type) + { + case DMX_PCR_ONLY_CHANNEL: + p_flt.pes_type = DMX_PES_OTHER; + p_flt.output = DMX_OUT_TAP; + return true; + break; + case DMX_AUDIO_CHANNEL: + p_flt.pes_type = DMX_PES_OTHER; + p_flt.output = DMX_OUT_TSDEMUX_TAP; + break; + case DMX_VIDEO_CHANNEL: + p_flt.pes_type = DMX_PES_OTHER; + p_flt.output = DMX_OUT_TSDEMUX_TAP; + break; + case DMX_PES_CHANNEL: + p_flt.pes_type = DMX_PES_OTHER; + p_flt.output = DMX_OUT_TAP; + break; + case DMX_TP_CHANNEL: + p_flt.pes_type = DMX_PES_OTHER; + p_flt.output = DMX_OUT_TSDEMUX_TAP; + break; + default: + hal_info("%s #%d invalid dmx_type %d!\n", __func__, num, dmx_type); + return false; } return (ioctl(fd, DMX_SET_PES_FILTER, &p_flt) >= 0); } @@ -456,7 +467,8 @@ void cDemux::removePid(unsigned short Pid) } for (std::vector::iterator i = pesfds.begin(); i != pesfds.end(); ++i) { - if ((*i).pid == Pid) { + if ((*i).pid == Pid) + { hal_debug("removePid: removing demux fd %d pid 0x%04x\n", fd, Pid); if (ioctl(fd, DMX_REMOVE_PID, Pid) < 0) hal_info("%s: (DMX_REMOVE_PID, 0x%04hx): %m\n", __func__, Pid); @@ -467,7 +479,7 @@ void cDemux::removePid(unsigned short Pid) hal_info("%s pid 0x%04x not found\n", __FUNCTION__, Pid); } -void cDemux::getSTC(int64_t * STC) +void cDemux::getSTC(int64_t *STC) { int64_t pts = 0; if (videoDecoder) diff --git a/libraspi/dmx_lib.h b/libraspi/dmx_lib.h index 86eabf3..8f6981a 100644 --- a/libraspi/dmx_lib.h +++ b/libraspi/dmx_lib.h @@ -31,31 +31,37 @@ class cRecord; class cPlayback; class cDemux { - friend class cRecord; - friend class cPlayback; + friend class cRecord; + friend class cPlayback; public: - bool Open(DMX_CHANNEL_TYPE pes_type, void * x = NULL, int y = 0); + bool Open(DMX_CHANNEL_TYPE pes_type, void *x = NULL, int y = 0); void Close(void); bool Start(bool record = false); bool Stop(void); int Read(unsigned char *buff, int len, int Timeout = 0); - bool sectionFilter(unsigned short pid, const unsigned char * const filter, const unsigned char * const mask, int len, int Timeout = 0, const unsigned char * const negmask = NULL); + bool sectionFilter(unsigned short pid, const unsigned char *const filter, const unsigned char *const mask, int len, int Timeout = 0, const unsigned char *const negmask = NULL); bool pesFilter(const unsigned short pid); void SetSyncMode(AVSYNC_TYPE mode); - void * getBuffer(); - void * getChannel(); - DMX_CHANNEL_TYPE getChannelType(void) { return dmx_type; }; + void *getBuffer(); + void *getChannel(); + DMX_CHANNEL_TYPE getChannelType(void) + { + return dmx_type; + }; bool addPid(unsigned short pid); - void getSTC(int64_t * STC); + void getSTC(int64_t *STC); int getUnit(void); static bool SetSource(int unit, int source); static int GetSource(int unit); - int getFD(void) { return fd; }; /* needed by cPlayback class */ + int getFD(void) + { + return fd; + }; /* needed by cPlayback class */ cDemux(int num = 0); ~cDemux(); private: - void removePid(unsigned short Pid); /* needed by cRecord class */ + void removePid(unsigned short Pid); /* needed by cRecord class */ int num; int fd; int buffersize; diff --git a/libraspi/glfb.cpp b/libraspi/glfb.cpp index 74c2dda..7040ad0 100644 --- a/libraspi/glfb.cpp +++ b/libraspi/glfb.cpp @@ -1,21 +1,21 @@ /* - Copyright 2013 Stefan Seyfried + Copyright 2013 Stefan Seyfried - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . - The GLFB namespace is just because it's already established by the - generic-pc implementation. + The GLFB namespace is just because it's already established by the + generic-pc implementation. */ #include @@ -50,10 +50,10 @@ static VC_IMAGE_TYPE_T type = VC_IMAGE_ARGB8888; static OpenThreads::Mutex blit_mutex; static OpenThreads::Condition blit_cond; -static bool goodbye = false; /* if set main loop is left */ -static bool ready = false; /* condition predicate */ +static bool goodbye = false; /* if set main loop is left */ +static bool ready = false; /* condition predicate */ -static int width; /* width and height, fixed for a framebuffer instance */ +static int width; /* width and height, fixed for a framebuffer instance */ static int height; GLFramebuffer::GLFramebuffer(int x, int y) @@ -126,11 +126,12 @@ void GLFramebuffer::setup() /* 32bit FB depth, *2 because tuxtxt uses a shadow buffer */ osd_buf.resize(pitch * height * 2); hal_info("GLFB: Display is %d x %d, FB is %d x %d, memory size %d\n", - info.width, info.height, width, height, osd_buf.size()); + info.width, info.height, width, height, osd_buf.size()); image = &osd_buf[0]; /* initialize to half-transparent grey */ memset(image, 0x7f, osd_buf.size()); - for (int i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) + { res[i] = vc_dispmanx_resource_create(type, width, height, &vc_img_ptr[i]); CHECK(res[i]); } @@ -142,15 +143,15 @@ void GLFramebuffer::setup() vc_dispmanx_rect_set(&src_rect, 0, 0, width << 16, height << 16); vc_dispmanx_rect_set(&dsp_rect, 0, 0, info.width, info.height); element = vc_dispmanx_element_add(update, - display, - 2000 /*layer*/, - &dsp_rect, - res[curr_res], - &src_rect, - DISPMANX_PROTECTION_NONE, - &alpha, - NULL, - DISPMANX_NO_ROTATE); + display, + 2000 /*layer*/, + &dsp_rect, + res[curr_res], + &src_rect, + DISPMANX_PROTECTION_NONE, + &alpha, + NULL, + DISPMANX_NO_ROTATE); ret = vc_dispmanx_update_submit_sync(update); CHECK(ret == 0); curr_res = !curr_res; diff --git a/libraspi/glfb.h b/libraspi/glfb.h index c5fcce6..c91393d 100644 --- a/libraspi/glfb.h +++ b/libraspi/glfb.h @@ -1,18 +1,18 @@ /* - Copyright 2013 Stefan Seyfried + Copyright 2013 Stefan Seyfried - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #ifndef __glthread__ @@ -23,20 +23,26 @@ class GLFramebuffer : public OpenThreads::Thread { -public: - GLFramebuffer(int x, int y); - ~GLFramebuffer(); - std::vector *getOSDBuffer() { return &osd_buf; } /* pointer to OSD bounce buffer */ - void blit(); - fb_var_screeninfo getScreenInfo() { return si; } + public: + GLFramebuffer(int x, int y); + ~GLFramebuffer(); + std::vector *getOSDBuffer() + { + return &osd_buf; /* pointer to OSD bounce buffer */ + } + void blit(); + fb_var_screeninfo getScreenInfo() + { + return si; + } -private: - void *pdata; /* not yet used */ - fb_var_screeninfo si; - std::vector osd_buf; /* silly bounce buffer */ - void run(); /* for OpenThreads::Thread */ + private: + void *pdata; /* not yet used */ + fb_var_screeninfo si; + std::vector osd_buf; /* silly bounce buffer */ + void run(); /* for OpenThreads::Thread */ - void setup(); - void blit_osd(); + void setup(); + void blit_osd(); }; #endif diff --git a/libraspi/hardware_caps.c b/libraspi/hardware_caps.c index 3ee29db..69d5be3 100644 --- a/libraspi/hardware_caps.c +++ b/libraspi/hardware_caps.c @@ -27,7 +27,7 @@ hw_caps_t *get_hwcaps(void) initialized = 1; caps.can_cpufreq = 0; - caps.can_shutdown = 1; /* for testing */ + caps.can_shutdown = 1; /* for testing */ caps.display_type = HW_DISPLAY_LINE_TEXT; caps.has_HDMI = 1; caps.display_xres = 8; diff --git a/libraspi/init.cpp b/libraspi/init.cpp index 070d525..7c084e9 100644 --- a/libraspi/init.cpp +++ b/libraspi/init.cpp @@ -49,24 +49,24 @@ static keymap_t kmap; static void init_keymap(void) { /* same as generic-pc/glfb.cpp */ - kmap[KEY_ENTER] = KEY_OK; - kmap[KEY_ESC] = KEY_EXIT; - kmap[KEY_E] = KEY_EPG; - kmap[KEY_I] = KEY_INFO; - kmap[KEY_M] = KEY_MENU; - kmap[KEY_F12] = KEY_VOLUMEUP; /* different than glfb, as we */ - kmap[KEY_F11] = KEY_VOLUMEDOWN; /* don't consider the keyboard */ - kmap[KEY_F10] = KEY_MUTE; /* layout... */ - kmap[KEY_H] = KEY_HELP; - kmap[KEY_P] = KEY_POWER; - kmap[KEY_F1] = KEY_RED; - kmap[KEY_F2] = KEY_GREEN; - kmap[KEY_F3] = KEY_YELLOW; - kmap[KEY_F4] = KEY_BLUE; - kmap[KEY_F5] = KEY_WWW; - kmap[KEY_F6] = KEY_SUBTITLE; - kmap[KEY_F7] = KEY_MOVE; - kmap[KEY_F8] = KEY_SLEEP; + kmap[KEY_ENTER] = KEY_OK; + kmap[KEY_ESC] = KEY_EXIT; + kmap[KEY_E] = KEY_EPG; + kmap[KEY_I] = KEY_INFO; + kmap[KEY_M] = KEY_MENU; + kmap[KEY_F12] = KEY_VOLUMEUP; /* different than glfb, as we */ + kmap[KEY_F11] = KEY_VOLUMEDOWN; /* don't consider the keyboard */ + kmap[KEY_F10] = KEY_MUTE; /* layout... */ + kmap[KEY_H] = KEY_HELP; + kmap[KEY_P] = KEY_POWER; + kmap[KEY_F1] = KEY_RED; + kmap[KEY_F2] = KEY_GREEN; + kmap[KEY_F3] = KEY_YELLOW; + kmap[KEY_F4] = KEY_BLUE; + kmap[KEY_F5] = KEY_WWW; + kmap[KEY_F6] = KEY_SUBTITLE; + kmap[KEY_F7] = KEY_MOVE; + kmap[KEY_F8] = KEY_SLEEP; } class Input: public OpenThreads::Thread @@ -111,7 +111,7 @@ void Input::run() init_keymap(); unlink("/tmp/neutrino.input"); mkfifo("/tmp/neutrino.input", 0600); - out_fd = open("/tmp/neutrino.input", O_RDWR|O_CLOEXEC|O_NONBLOCK); + out_fd = open("/tmp/neutrino.input", O_RDWR | O_CLOEXEC | O_NONBLOCK); if (out_fd < 0) hal_info("could not create /tmp/neutrino.input. good luck. error: %m\n"); @@ -120,16 +120,19 @@ void Input::run() hal_info("no input devices /dev/input/eventX??\n"); else { - while (n--) { + while (n--) + { strcpy(inputstr + strlen("/dev/input/"), namelist[n]->d_name); free(namelist[n]); - int fd = open(inputstr, O_RDWR|O_CLOEXEC|O_NONBLOCK); - if (fd < 0) { + int fd = open(inputstr, O_RDWR | O_CLOEXEC | O_NONBLOCK); + if (fd < 0) + { hal_info("could not open %s:%m\n", inputstr); continue; } ioctl(fd, EVIOCGBIT(0, EV_MAX), &bit); - if ((bit & (1 << EV_KEY)) == 0) { + if ((bit & (1 << EV_KEY)) == 0) + { close(fd); continue; } @@ -143,7 +146,8 @@ void Input::run() fd_max++; running = true; - while (running) { + while (running) + { FD_ZERO(&rfds); for (std::set::iterator i = in_fds.begin(); i != in_fds.end(); ++i) FD_SET((*i), &rfds); @@ -154,18 +158,22 @@ void Input::run() int ret = select(fd_max, &rfds, NULL, NULL, &timeout); if (ret == 0) /* timed out */ continue; - if (ret < 0) { + if (ret < 0) + { hal_info("input: select returned %d (%m)\n", ret); continue; } - for (std::set::iterator i = in_fds.begin(); i != in_fds.end(); ++i) { + for (std::set::iterator i = in_fds.begin(); i != in_fds.end(); ++i) + { if (!FD_ISSET((*i), &rfds)) continue; ret = read(*i, &in, sizeof(in)); - if (ret != sizeof(in)) { - if (errno == ENODEV) { + if (ret != sizeof(in)) + { + if (errno == ENODEV) + { close(*i); hal_info("input fd %d vanished?\n", *i); in_fds.erase(i); @@ -193,7 +201,8 @@ void hal_api_init() if (!initialized) hal_debug_init(); hal_info("%s begin, initialized=%d, debug=0x%02x\n", __func__, (int)initialized, debuglevel); - if (! glfb) { + if (! glfb) + { int x = 1280, y = 720; /* default OSD FB resolution */ /* * export GLFB_RESOLUTION=720,576 @@ -203,7 +212,8 @@ void hal_api_init() const char *p = NULL; if (tmp) p = strchr(tmp, ','); - if (p) { + if (p) + { x = atoi(tmp); y = atoi(p + 1); } diff --git a/libraspi/video.cpp b/libraspi/video.cpp index 0cda7dd..1706486 100644 --- a/libraspi/video.cpp +++ b/libraspi/video.cpp @@ -81,7 +81,7 @@ int cVideo::setBlank(int) int cVideo::SetVideoSystem(int system, bool) { int h; - switch(system) + switch (system) { case VIDEO_STD_NTSC: case VIDEO_STD_480P: @@ -101,7 +101,7 @@ int cVideo::SetVideoSystem(int system, bool) break; case VIDEO_STD_AUTO: hal_info("%s: VIDEO_STD_AUTO not implemented\n", __func__); - // fallthrough + // fallthrough case VIDEO_STD_SECAM: case VIDEO_STD_PAL: case VIDEO_STD_576P: @@ -170,10 +170,10 @@ int cVideo::SetStreamType(VIDEO_FORMAT v) return 0; } -bool cVideo::GetScreenImage(unsigned char * &data, int &xres, int &yres, bool get_video, bool get_osd, bool scale_to_video) +bool cVideo::GetScreenImage(unsigned char *&data, int &xres, int &yres, bool get_video, bool get_osd, bool scale_to_video) { hal_info("%s: data 0x%p xres %d yres %d vid %d osd %d scale %d\n", - __func__, data, xres, yres, get_video, get_osd, scale_to_video); + __func__, data, xres, yres, get_video, get_osd, scale_to_video); return false; } diff --git a/libraspi/video_lib.h b/libraspi/video_lib.h index cc23a06..869279b 100644 --- a/libraspi/video_lib.h +++ b/libraspi/video_lib.h @@ -10,7 +10,8 @@ extern "C" { #include } -typedef enum { +typedef enum +{ ANALOG_SD_RGB_CINCH = 0x00, ANALOG_SD_YPRPB_CINCH, ANALOG_HD_RGB_CINCH, @@ -23,7 +24,8 @@ typedef enum { } analog_mode_t; -typedef enum { +typedef enum +{ VIDEO_FORMAT_MPEG2 = 0, VIDEO_FORMAT_MPEG4, VIDEO_FORMAT_VC1, @@ -32,7 +34,8 @@ typedef enum { VIDEO_FORMAT_PNG } VIDEO_FORMAT; -typedef enum { +typedef enum +{ VIDEO_SD = 0, VIDEO_HD, VIDEO_120x60i, @@ -41,7 +44,8 @@ typedef enum { VIDEO_360x288i } VIDEO_DEFINITION; -typedef enum { +typedef enum +{ VIDEO_FRAME_RATE_23_976 = 0, VIDEO_FRAME_RATE_24, VIDEO_FRAME_RATE_25, @@ -52,7 +56,8 @@ typedef enum { VIDEO_FRAME_RATE_60 } VIDEO_FRAME_RATE; -typedef enum { +typedef enum +{ DISPLAY_AR_1_1, DISPLAY_AR_4_3, DISPLAY_AR_14_9, @@ -61,20 +66,23 @@ typedef enum { DISPLAY_AR_RAW } DISPLAY_AR; -typedef enum { +typedef enum +{ DISPLAY_AR_MODE_PANSCAN = 0, DISPLAY_AR_MODE_LETTERBOX, DISPLAY_AR_MODE_NONE, DISPLAY_AR_MODE_PANSCAN2 } DISPLAY_AR_MODE; -typedef enum { +typedef enum +{ VIDEO_DB_DR_NEITHER = 0, VIDEO_DB_ON, VIDEO_DB_DR_BOTH } VIDEO_DB_DR; -typedef enum { +typedef enum +{ VIDEO_PLAY_STILL = 0, VIDEO_PLAY_CLIP, VIDEO_PLAY_TRICK, @@ -82,7 +90,8 @@ typedef enum { VIDEO_PLAY_MOTION_NO_SYNC } VIDEO_PLAY_MODE; -typedef enum { +typedef enum +{ VIDEO_STD_NTSC, VIDEO_STD_SECAM, VIDEO_STD_PAL, @@ -96,12 +105,13 @@ typedef enum { VIDEO_STD_1080P24, VIDEO_STD_1080P25, VIDEO_STD_AUTO, - VIDEO_STD_1080P50, /* SPARK only */ + VIDEO_STD_1080P50, /* SPARK only */ VIDEO_STD_MAX } VIDEO_STD; /* not used, for dummy functions */ -typedef enum { +typedef enum +{ VIDEO_HDMI_CEC_MODE_OFF = 0, VIDEO_HDMI_CEC_MODE_TUNER, VIDEO_HDMI_CEC_MODE_RECORDER @@ -121,27 +131,51 @@ typedef enum #define VDEC_MAXBUFS 0x30 class cVideo { - friend class GLFramebuffer; - friend class cDemux; + friend class GLFramebuffer; + friend class cDemux; private: /* called from GL thread */ class SWFramebuffer : public std::vector { - public: - SWFramebuffer() : mWidth(0), mHeight(0) {} - void width(int w) { mWidth = w; } - void height(int h) { mHeight = h; } - void pts(uint64_t p) { mPts = p; } - void AR(AVRational a) { mAR = a; } - int width() const { return mWidth; } - int height() const { return mHeight; } - int64_t pts() const { return mPts; } - AVRational AR() const { return mAR; } - private: - int mWidth; - int mHeight; - int64_t mPts; - AVRational mAR; + public: + SWFramebuffer() : mWidth(0), mHeight(0) {} + void width(int w) + { + mWidth = w; + } + void height(int h) + { + mHeight = h; + } + void pts(uint64_t p) + { + mPts = p; + } + void AR(AVRational a) + { + mAR = a; + } + int width() const + { + return mWidth; + } + int height() const + { + return mHeight; + } + int64_t pts() const + { + return mPts; + } + AVRational AR() const + { + return mAR; + } + private: + int mWidth; + int mHeight; + int64_t mPts; + AVRational mAR; }; int buf_in, buf_out, buf_num; int64_t GetPTS(void); @@ -150,8 +184,14 @@ class cVideo cVideo(int mode, void *, void *, unsigned int unit = 0); ~cVideo(void); - void * GetTVEnc() { return NULL; }; - void * GetTVEncSD() { return NULL; }; + void *GetTVEnc() + { + return NULL; + }; + void *GetTVEncSD() + { + return NULL; + }; /* aspect ratio */ int getAspectRatio(void); @@ -177,25 +217,58 @@ class cVideo int SetVideoSystem(int video_system, bool remember = true); int SetStreamType(VIDEO_FORMAT type); void SetSyncMode(AVSYNC_TYPE mode); - bool SetCECMode(VIDEO_HDMI_CEC_MODE) { return true; }; - void SetCECAutoView(bool) { return; }; - void SetCECAutoStandby(bool) { return; }; - bool ShowPicture(const char * fname); + bool SetCECMode(VIDEO_HDMI_CEC_MODE) + { + return true; + }; + void SetCECAutoView(bool) + { + return; + }; + void SetCECAutoStandby(bool) + { + return; + }; + bool ShowPicture(const char *fname); void StopPicture(); void Standby(unsigned int bOn); void Pig(int x, int y, int w, int h, int osd_w = 1064, int osd_h = 600); - void SetControl(int, int) { return; }; + void SetControl(int, int) + { + return; + }; void setContrast(int val); void SetVideoMode(analog_mode_t mode); - void SetDBDR(int) { return; }; - void SetAudioHandle(void *) { return; }; - void SetAutoModes(int [VIDEO_STD_MAX]) { return; }; - int OpenVBI(int) { return 0; }; - int CloseVBI(void) { return 0; }; - int StartVBI(unsigned short) { return 0; }; - int StopVBI(void) { return 0; }; + void SetDBDR(int) + { + return; + }; + void SetAudioHandle(void *) + { + return; + }; + void SetAutoModes(int [VIDEO_STD_MAX]) + { + return; + }; + int OpenVBI(int) + { + return 0; + }; + int CloseVBI(void) + { + return 0; + }; + int StartVBI(unsigned short) + { + return 0; + }; + int StopVBI(void) + { + return 0; + }; void SetDemux(cDemux *dmx); - bool GetScreenImage(unsigned char * &data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); + bool GetScreenImage(unsigned char *&data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); private: SWFramebuffer buffers[VDEC_MAXBUFS]; int dec_w, dec_h; diff --git a/libspark/audio.cpp b/libspark/audio.cpp index 3c8f6b5..4cbcb95 100644 --- a/libspark/audio.cpp +++ b/libspark/audio.cpp @@ -14,18 +14,19 @@ #include "audio_mixer.h" #include "hal_debug.h" -#define AUDIO_DEVICE "/dev/dvb/adapter0/audio0" +#define AUDIO_DEVICE "/dev/dvb/adapter0/audio0" #define hal_debug(args...) _hal_debug(HAL_DEBUG_AUDIO, this, args) #define hal_info(args...) _hal_info(HAL_DEBUG_AUDIO, this, args) #include enum -{ ENCODER, +{ + ENCODER, AUX }; -cAudio * audioDecoder = NULL; +cAudio *audioDecoder = NULL; cAudio::cAudio(void *, void *, void *) { @@ -66,15 +67,18 @@ void cAudio::closeDevice(void) { closeMixers(); - if (fd > -1) { + if (fd > -1) + { close(fd); fd = -1; } - if (clipfd > -1) { + if (clipfd > -1) + { close(clipfd); clipfd = -1; } - if (mixer_fd > -1) { + if (mixer_fd > -1) + { close(mixer_fd); mixer_fd = -1; } @@ -124,7 +128,8 @@ int cAudio::setVolume(unsigned int left, unsigned int right) volume = (left + right) / 2; int v = map_volume(volume); #if 0 - if (clipfd != -1 && mixer_fd != -1) { + if (clipfd != -1 && mixer_fd != -1) + { int tmp = 0; /* not sure if left / right is correct here, but it is always the same anyways ;-) */ if (! Muted) @@ -190,7 +195,8 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) const char *dsp_dev = getenv("DSP_DEVICE"); const char *mix_dev = getenv("MIX_DEVICE"); hal_debug("%s ch %d srate %d bits %d le %d\n", __FUNCTION__, ch, srate, bits, little_endian); - if (clipfd > -1) { + if (clipfd > -1) + { hal_info("%s: clipfd already opened (%d)\n", __FUNCTION__, clipfd); return -1; } @@ -203,16 +209,18 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) * export MIX_DEVICE=/dev/sound/mixer2 * neutrino */ - if ((!dsp_dev) || (access(dsp_dev, W_OK))) { + if ((!dsp_dev) || (access(dsp_dev, W_OK))) + { if (dsp_dev) hal_info("%s: DSP_DEVICE is set (%s) but cannot be opened," - " fall back to /dev/dsp1\n", __func__, dsp_dev); + " fall back to /dev/dsp1\n", __func__, dsp_dev); dsp_dev = "/dev/dsp1"; } hal_info("%s: dsp_dev %s mix_dev %s\n", __func__, dsp_dev, mix_dev); /* NULL mix_dev is ok */ /* the tdoss dsp driver seems to work only on the second open(). really. */ clipfd = open(dsp_dev, O_WRONLY); - if (clipfd < 0) { + if (clipfd < 0) + { hal_info("%s open %s: %m\n", dsp_dev, __FUNCTION__); return -1; } @@ -235,42 +243,50 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) return 0; mixer_fd = open(mix_dev, O_RDWR); - if (mixer_fd < 0) { + if (mixer_fd < 0) + { hal_info("%s: open mixer %s failed (%m)\n", __func__, mix_dev); /* not a real error */ return 0; } - if (ioctl(mixer_fd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) { + if (ioctl(mixer_fd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) + { hal_info("%s: SOUND_MIXER_READ_DEVMASK %m\n", __func__); devmask = 0; } - if (ioctl(mixer_fd, SOUND_MIXER_READ_STEREODEVS, &stereo) == -1) { + if (ioctl(mixer_fd, SOUND_MIXER_READ_STEREODEVS, &stereo) == -1) + { hal_info("%s: SOUND_MIXER_READ_STEREODEVS %m\n", __func__); stereo = 0; } usable = devmask & stereo; - if (usable == 0) { + if (usable == 0) + { hal_info("%s: devmask: %08x stereo: %08x, no usable dev :-(\n", - __func__, devmask, stereo); + __func__, devmask, stereo); close(mixer_fd); mixer_fd = -1; return 0; /* TODO: should we treat this as error? */ } /* __builtin_popcount needs GCC, it counts the set bits... */ - if (__builtin_popcount (usable) != 1) { + if (__builtin_popcount(usable) != 1) + { /* TODO: this code is not yet tested as I have only single-mixer devices... */ hal_info("%s: more than one mixer control: devmask %08x stereo %08x\n" - "%s: querying MIX_NUMBER environment variable...\n", - __func__, devmask, stereo, __func__); + "%s: querying MIX_NUMBER environment variable...\n", + __func__, devmask, stereo, __func__); const char *tmp = getenv("MIX_NUMBER"); if (tmp) mixer_num = atoi(tmp); hal_info("%s: mixer_num is %d -> device %08x\n", - __func__, mixer_num, (mixer_num >= 0) ? (1 << mixer_num) : 0); + __func__, mixer_num, (mixer_num >= 0) ? (1 << mixer_num) : 0); /* no error checking, you'd better know what you are doing... */ - } else { + } + else + { mixer_num = 0; - while (!(usable & 0x01)) { + while (!(usable & 0x01)) + { mixer_num++; usable >>= 1; } @@ -284,7 +300,8 @@ int cAudio::WriteClip(unsigned char *buffer, int size) { int ret; // hal_debug("cAudio::%s\n", __FUNCTION__); - if (clipfd < 0) { + if (clipfd < 0) + { hal_info("%s: clipfd not yet opened\n", __FUNCTION__); return -1; } @@ -297,13 +314,15 @@ int cAudio::WriteClip(unsigned char *buffer, int size) int cAudio::StopClip() { hal_debug("%s\n", __FUNCTION__); - if (clipfd < 0) { + if (clipfd < 0) + { hal_info("%s: clipfd not yet opened\n", __FUNCTION__); return -1; } close(clipfd); clipfd = -1; - if (mixer_fd > -1) { + if (mixer_fd > -1) + { close(mixer_fd); mixer_fd = -1; } @@ -331,24 +350,24 @@ void cAudio::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &m type = atype; #if 0 -/* this does not work, some of the values are negative?? */ + /* this does not work, some of the values are negative?? */ AMPEGStatus A; memcpy(&A, &i.word00, sizeof(i.word00)); layer = A.audio_mpeg_layer; mode = A.audio_mpeg_mode; bitrate = A.audio_mpeg_bitrate; - switch(A.audio_mpeg_frequency) + switch (A.audio_mpeg_frequency) #endif - /* layer and bitrate are not used anyway... */ - layer = 0; //(i.word00 >> 17) & 3; + /* layer and bitrate are not used anyway... */ + layer = 0; //(i.word00 >> 17) & 3; bitrate = 0; //(i.word00 >> 12) & 3; switch (type) { - case 0: /* MPEG */ + case 0: /* MPEG */ mode = (i.word00 >> 6) & 3; freq = freq_mpg[(i.word00 >> 10) & 3]; break; - case 1: /* AC3 */ + case 1: /* AC3 */ mode = (i.word00 >> 28) & 7; freq = freq_ac3[(i.word00 >> 16) & 3]; break; @@ -417,17 +436,20 @@ void cAudio::closeMixers(void) void cAudio::setMixerVolume(const char *name, long value, bool remember) { - if (!strcmp(name, "Analog")) { + if (!strcmp(name, "Analog")) + { mixerAnalog->setVolume(value); if (remember) volumeAnalog = value; } - if (!strcmp(name, "HDMI")) { + if (!strcmp(name, "HDMI")) + { mixerHDMI->setVolume(value); if (remember) volumeHDMI = value; } - if (!strcmp(name, "SPDIF")) { + if (!strcmp(name, "SPDIF")) + { mixerSPDIF->setVolume(value); if (remember) volumeSPDIF = value; @@ -436,12 +458,15 @@ void cAudio::setMixerVolume(const char *name, long value, bool remember) void cAudio::muteMixers(bool m) { - if (m && !mixersMuted) { + if (m && !mixersMuted) + { mixersMuted = true; setMixerVolume("Analog", 0, false); setMixerVolume("HDMI", 0, false); setMixerVolume("SPDIF", 0, false); - } else if (!m && mixersMuted) { + } + else if (!m && mixersMuted) + { mixersMuted = false; setMixerVolume("Analog", volumeAnalog, false); setMixerVolume("HDMI", volumeHDMI, false); diff --git a/libspark/audio_lib.h b/libspark/audio_lib.h index 57787f6..d52c634 100644 --- a/libspark/audio_lib.h +++ b/libspark/audio_lib.h @@ -12,7 +12,8 @@ typedef enum AUDIO_SYNC_AUDIO_MASTER } AUDIO_SYNC_MODE; -typedef enum { +typedef enum +{ HDMI_ENCODED_OFF, HDMI_ENCODED_AUTO, HDMI_ENCODED_FORCED @@ -22,7 +23,7 @@ class mixerVolume; class cAudio { - friend class cPlayback; + friend class cPlayback; private: int fd; bool Muted; @@ -31,7 +32,7 @@ class cAudio int mixer_fd; /* if we are using the OSS mixer */ int mixer_num; /* oss mixer to use, if any */ - int StreamType; + int StreamType; AUDIO_SYNC_MODE SyncMode; bool started; @@ -52,37 +53,64 @@ class cAudio cAudio(void *, void *, void *); ~cAudio(void); - void open_AVInput_Device(void) { return; }; - void close_AVInput_Device(void) { return; }; + void open_AVInput_Device(void) + { + return; + }; + void close_AVInput_Device(void) + { + return; + }; void setAVInput(int val); - void *GetHandle() { return NULL; }; + void *GetHandle() + { + return NULL; + }; /* shut up */ - int mute(bool remember = true) { return do_mute(true, remember); }; - int unmute(bool remember = true) { return do_mute(false, remember); }; + int mute(bool remember = true) + { + return do_mute(true, remember); + }; + int unmute(bool remember = true) + { + return do_mute(false, remember); + }; /* volume, min = 0, max = 255 */ int setVolume(unsigned int left, unsigned int right); - int getVolume(void) { return volume;} - bool getMuteStatus(void) { return Muted; }; + int getVolume(void) + { + return volume; + } + bool getMuteStatus(void) + { + return Muted; + }; /* start and stop audio */ int Start(void); int Stop(void); bool Pause(bool Pcm = true); void SetStreamType(int bypass); - int GetStreamType(void) { return StreamType; } + int GetStreamType(void) + { + return StreamType; + } void SetSyncMode(AVSYNC_TYPE Mode); /* select channels */ int setChannel(int channel); int PrepareClipPlay(int uNoOfChannels, int uSampleRate, int uBitsPerSample, int bLittleEndian); - int WriteClip(unsigned char * buffer, int size); + int WriteClip(unsigned char *buffer, int size); int StopClip(); - void getAudioInfo(int &type, int &layer, int& freq, int &bitrate, int &mode); + void getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode); void SetSRS(int iq_enable, int nmgr_enable, int iq_mode, int iq_level); - bool IsHdmiDDSupported() { return true; }; + bool IsHdmiDDSupported() + { + return true; + }; void SetHdmiDD(bool enable); void SetSpdifDD(bool enable); void ScheduleMute(bool On); diff --git a/libspark/audio_mixer.cpp b/libspark/audio_mixer.cpp index f361209..3f8bac0 100644 --- a/libspark/audio_mixer.cpp +++ b/libspark/audio_mixer.cpp @@ -19,7 +19,8 @@ #include -mixerVolume::mixerVolume(const char *name, const char *card, long volume) { +mixerVolume::mixerVolume(const char *name, const char *card, long volume) +{ snd_mixer_selem_id_t *sid = NULL; elem = NULL; handle = NULL; @@ -49,7 +50,8 @@ mixerVolume::mixerVolume(const char *name, const char *card, long volume) { snd_mixer_selem_id_set_index(sid, 0); snd_mixer_selem_id_set_name(sid, name); elem = snd_mixer_find_selem(handle, sid); - if (elem) { + if (elem) + { snd_mixer_selem_get_playback_volume_range(elem, &min, &max); setVolume(volume); } @@ -60,9 +62,10 @@ mixerVolume::~mixerVolume() snd_mixer_close(handle); } -bool mixerVolume::setVolume(long volume) { +bool mixerVolume::setVolume(long volume) +{ return elem - && (volume > -1) - && (volume < 101) - && !snd_mixer_selem_set_playback_volume_all(elem, min + volume * (max - min)/100); + && (volume > -1) + && (volume < 101) + && !snd_mixer_selem_set_playback_volume_all(elem, min + volume * (max - min) / 100); } diff --git a/libspark/audio_mixer.h b/libspark/audio_mixer.h index d8e6d35..d3aad79 100644 --- a/libspark/audio_mixer.h +++ b/libspark/audio_mixer.h @@ -27,7 +27,7 @@ class mixerVolume private: long min, max; snd_mixer_t *handle; - snd_mixer_elem_t* elem; + snd_mixer_elem_t *elem; public: mixerVolume(const char *selem_name, const char *Card, long volume = -1); ~mixerVolume(void); diff --git a/libspark/dmx.cpp b/libspark/dmx.cpp index 5dd2834..3f95935 100644 --- a/libspark/dmx.cpp +++ b/libspark/dmx.cpp @@ -26,19 +26,19 @@ * * the sh4 pti driver, driving the /dev/dvb/adapter0/dmxN devices, can * apparently only map one input to on demux device at a time, so e.g. - * DMX_SOURCE_FRONT1 -> demux0 - * DMX_SOURCE_FRONT2 -> demux0 - * DMX_SOURCE_FRONT1 -> demux1 + * DMX_SOURCE_FRONT1 -> demux0 + * DMX_SOURCE_FRONT2 -> demux0 + * DMX_SOURCE_FRONT1 -> demux1 * does not work. The driver makes sure that a one-to-one mapping of * DMX_SOURCE_FRONTn to demuxM is maintained, and it does by e.g changing * the default of - * FRONT0 -> demux0 - * FRONT1 -> demux1 - * FRONT2 -> demux2 + * FRONT0 -> demux0 + * FRONT1 -> demux1 + * FRONT2 -> demux2 * to - * FRONT1 -> demux0 - * FRONT0 -> demux1 - * FRONT2 -> demux2 + * FRONT1 -> demux0 + * FRONT0 -> demux1 + * FRONT2 -> demux2 * if you do a DMX_SET_SOURCE(FRONT1) ioctl on demux0. * This means, it also changes demux1's source on the SET_SOURCE ioctl on * demux0, potentially disturbing any operation on demux1 (e.g. recording). @@ -84,15 +84,16 @@ extern cVideo *videoDecoder; #define hal_debug_z(args...) _hal_debug(HAL_DEBUG_DEMUX, thiz, args) #define dmx_err(_errfmt, _errstr, _revents) do { \ - hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ -} while(0); + hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ + __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ + } while(0); cDemux *videoDemux = NULL; cDemux *audioDemux = NULL; //cDemux *pcrDemux = NULL; -static const char *DMX_T[] = { +static const char *DMX_T[] = +{ "DMX_INVALID", "DMX_VIDEO", "DMX_AUDIO", @@ -110,7 +111,8 @@ static const char *DMX_T[] = { static int dmx_source[NUM_DEMUX] = { 0, 0, 0, 0 }; char dmxdev[32]; -static char* devname(int adapter, int demux) { +static char *devname(int adapter, int demux) +{ snprintf(dmxdev, sizeof(dmxdev), "/dev/dvb/adapter%d/demux%d", adapter, demux); return dmxdev; } @@ -121,7 +123,8 @@ static char* devname(int adapter, int demux) { /* did we already DMX_SET_SOURCE on that demux device? */ static bool init[NUM_DEMUXDEV] = { false, false, false }; -typedef struct dmx_pdata { +typedef struct dmx_pdata +{ int last_source; OpenThreads::Mutex *mutex; } dmx_pdata; @@ -169,17 +172,19 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe static bool _open(cDemux *thiz, int num, int &fd, int &last_source, DMX_CHANNEL_TYPE dmx_type, int buffersize) { - int flags = O_RDWR|O_CLOEXEC; + int flags = O_RDWR | O_CLOEXEC; int devnum = dmx_source[num]; - if (last_source == devnum) { + if (last_source == devnum) + { hal_debug_z("%s #%d: source (%d) did not change\n", __func__, num, last_source); if (fd > -1) return true; } - if (fd > -1) { + if (fd > -1) + { /* we changed source -> close and reopen the fd */ hal_debug_z("%s #%d: FD ALREADY OPENED fd = %d lastsource %d devnum %d\n", - __func__, num, fd, last_source, devnum); + __func__, num, fd, last_source, devnum); close(fd); } @@ -193,7 +198,7 @@ static bool _open(cDemux *thiz, int num, int &fd, int &last_source, DMX_CHANNEL_ return false; } hal_debug_z("%s #%d pes_type: %s(%d), uBufferSize: %d fd: %d\n", __func__, - num, DMX_T[dmx_type], dmx_type, buffersize, fd); + num, DMX_T[dmx_type], dmx_type, buffersize, fd); /* this would actually need locking, but the worst that weill happen is, that * we'll DMX_SET_SOURCE twice per device, so don't bother... */ @@ -264,7 +269,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) #if 0 if (len != 4095 && timeout != 10) fprintf(stderr, "cDemux::%s #%d fd: %d type: %s len: %d timeout: %d\n", - __FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout); + __FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout); #endif if (fd < 0) { @@ -277,7 +282,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) int to = timeout; struct pollfd ufds; ufds.fd = fd; - ufds.events = POLLIN|POLLPRI|POLLERR; + ufds.events = POLLIN | POLLPRI | POLLERR; ufds.revents = 0; /* hack: if the frontend loses and regains lock, the demuxer often will not @@ -288,7 +293,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) if (to > 0) { - retry: +retry: rc = ::poll(&ufds, 1, to); if (ufds.fd != fd) { @@ -333,8 +338,9 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return 0; } } - if (ufds.fd != fd) /* does this ever happen? and if, is it harmful? */ - { /* read(-1,...) will just return EBADF anyway... */ + if (ufds.fd != fd) /* does this ever happen? and if, is it harmful? */ + { + /* read(-1,...) will just return EBADF anyway... */ hal_info("%s:2 ========== fd has changed, %d->%d ==========\n", __func__, ufds.fd, fd); return -1; } @@ -347,9 +353,9 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return rc; } -bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, - const unsigned char * const mask, int len, int timeout, - const unsigned char * const negmask) +bool cDemux::sectionFilter(unsigned short _pid, const unsigned char *const filter, + const unsigned char *const mask, int len, int timeout, + const unsigned char *const negmask) { struct dmx_sct_filter_params s_flt; memset(&s_flt, 0, sizeof(s_flt)); @@ -370,7 +376,7 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt if (negmask != NULL) memcpy(s_flt.filter.mode, negmask, len); - s_flt.flags = DMX_IMMEDIATE_START|DMX_CHECK_CRC; + s_flt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; int to = 0; switch (filter[0]) @@ -455,15 +461,22 @@ bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filt s_flt.timeout = to; hal_debug("%s #%d pid:0x%04hx fd:%d type:%s len:%d to:%d flags:%x flt[0]:%02x\n", __func__, num, - pid, fd, DMX_T[dmx_type], len, s_flt.timeout, s_flt.flags, s_flt.filter.filter[0]); + pid, fd, DMX_T[dmx_type], len, s_flt.timeout, s_flt.flags, s_flt.filter.filter[0]); - if (debuglevel == 2) { - fprintf(stderr,"filt: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.filter[i]); fprintf(stderr, "\n"); - fprintf(stderr,"mask: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mask [i]); fprintf(stderr, "\n"); - fprintf(stderr,"mode: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mode [i]); fprintf(stderr, "\n"); + if (debuglevel == 2) + { + fprintf(stderr, "filt: "); + for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.filter[i]); + fprintf(stderr, "\n"); + fprintf(stderr, "mask: "); + for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mask [i]); + fprintf(stderr, "\n"); + fprintf(stderr, "mode: "); + for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mode [i]); + fprintf(stderr, "\n"); } - ioctl (fd, DMX_STOP); + ioctl(fd, DMX_STOP); if (ioctl(fd, DMX_SET_FILTER, &s_flt) < 0) return false; @@ -479,7 +492,7 @@ bool cDemux::pesFilter(const unsigned short _pid) * this check originally is from tuxbox cvs but I'm not sure * what it is good for... if (pid <= 0x0001 && dmx_type != DMX_PCR_ONLY_CHANNEL) - return false; + return false; */ if ((pid >= 0x0002 && pid <= 0x000f) || pid >= 0x1fff) return false; @@ -571,7 +584,8 @@ void cDemux::removePid(unsigned short Pid) } for (std::vector::iterator i = pesfds.begin(); i != pesfds.end(); ++i) { - if ((*i).pid == Pid) { + if ((*i).pid == Pid) + { hal_debug("removePid: removing demux fd %d pid 0x%04x\n", fd, Pid); if (ioctl(fd, DMX_REMOVE_PID, Pid) < 0) hal_info("%s: (DMX_REMOVE_PID, 0x%04hx): %m\n", __func__, Pid); @@ -582,7 +596,7 @@ void cDemux::removePid(unsigned short Pid) hal_info("%s pid 0x%04x not found\n", __FUNCTION__, Pid); } -void cDemux::getSTC(int64_t * STC) +void cDemux::getSTC(int64_t *STC) { /* apparently I can only get the PTS of the video decoder, * but that's good enough for dvbsub */ @@ -604,7 +618,8 @@ int cDemux::getUnit(void) bool cDemux::SetSource(int unit, int source) { - if (unit >= NUM_DEMUX || unit < 0) { + if (unit >= NUM_DEMUX || unit < 0) + { hal_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX); return false; } @@ -618,7 +633,8 @@ bool cDemux::SetSource(int unit, int source) int cDemux::GetSource(int unit) { - if (unit >= NUM_DEMUX || unit < 0) { + if (unit >= NUM_DEMUX || unit < 0) + { hal_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX); return -1; } diff --git a/libspark/hardware_caps.c b/libspark/hardware_caps.c index 83b05e4..f2190ec 100644 --- a/libspark/hardware_caps.c +++ b/libspark/hardware_caps.c @@ -47,12 +47,14 @@ hw_caps_t *get_hwcaps(void) const char *tmp; char buf[1024]; int len = -1, ret, val; - int fd = open (FP_DEV, O_RDWR); - if (fd != -1) { + int fd = open(FP_DEV, O_RDWR); + if (fd != -1) + { ret = ioctl(fd, VFDGETVERSION, &val); if (ret < 0) fprintf(stderr, "[hardware_caps] %s: VFDGETVERSION %m\n", __func__); - else if (val & 1) { /* VFD = 1, DVFD = 3 */ + else if (val & 1) /* VFD = 1, DVFD = 3 */ + { caps.display_type = HW_DISPLAY_LINE_TEXT; caps.display_can_umlauts = 0; /* need test */ caps.display_xres = 8; @@ -61,17 +63,21 @@ hw_caps_t *get_hwcaps(void) close(fd); } fd = open("/proc/cmdline", O_RDONLY); - if (fd != -1) { + if (fd != -1) + { len = read(fd, buf, sizeof(buf) - 1); close(fd); } - if (len > 0) { + if (len > 0) + { buf[len] = 0; char *p = strstr(buf, "STB_ID="); int h0, h1, h2; - if (p && sscanf(p, "STB_ID=%x:%x:%x:", &h0, &h1, &h2) == 3) { + if (p && sscanf(p, "STB_ID=%x:%x:%x:", &h0, &h1, &h2) == 3) + { int sys_id = (h0 << 16) | (h1 << 8) | h2; - switch (sys_id) { + switch (sys_id) + { case 0x090003: tmp = "Truman Premier 1+"; break; @@ -159,10 +165,11 @@ hw_caps_t *get_hwcaps(void) caps.boxtype = 7111; else caps.boxtype = 7162; - } else + } + else tmp = "(NO STB_ID FOUND)"; strcpy(caps.boxname, tmp); } - strcpy(caps.boxarch,caps.boxname); + strcpy(caps.boxarch, caps.boxname); return ∩︀ } diff --git a/libspark/init.cpp b/libspark/init.cpp index 3730a93..c4ad18b 100644 --- a/libspark/init.cpp +++ b/libspark/init.cpp @@ -36,7 +36,8 @@ #define VIRTUALINPUT "/sys/devices/virtual/input" #define DEVINPUT "/dev/input" -typedef struct { +typedef struct +{ const char *name; const char *desc; int fd; @@ -45,68 +46,80 @@ typedef struct { time_t next_discovery; } input_device_t; -static input_device_t input_device[] = { - { "/dev/input/nevis_ir", "lircd", -1, 0, 0, 0 }, - { "/dev/input/tdt_rc", "TDT RC event driver", -1, 0, 0, 0 }, - { "/dev/input/fulan_fp", "fulan front panel buttons", -1, 0, 0, 0 }, - { "/dev/input/event0", NULL, -1, 0, 0, 0 }, - { "/dev/input/event1", NULL, -1, 0, 0, 0 }, - { "/dev/input/event2", NULL, -1, 0, 0, 0 }, - { "/dev/input/event3", NULL, -1, 0, 0, 0 }, - { "/dev/input/event4", NULL, -1, 0, 0, 0 }, - { "/dev/input/event5", NULL, -1, 0, 0, 0 }, - { "/dev/input/event6", NULL, -1, 0, 0, 0 }, - { "/dev/input/event7", NULL, -1, 0, 0, 0 }, - { NULL, NULL, -1, 0, 0, 0 } +static input_device_t input_device[] = +{ + { "/dev/input/nevis_ir", "lircd", -1, 0, 0, 0 }, + { "/dev/input/tdt_rc", "TDT RC event driver", -1, 0, 0, 0 }, + { "/dev/input/fulan_fp", "fulan front panel buttons", -1, 0, 0, 0 }, + { "/dev/input/event0", NULL, -1, 0, 0, 0 }, + { "/dev/input/event1", NULL, -1, 0, 0, 0 }, + { "/dev/input/event2", NULL, -1, 0, 0, 0 }, + { "/dev/input/event3", NULL, -1, 0, 0, 0 }, + { "/dev/input/event4", NULL, -1, 0, 0, 0 }, + { "/dev/input/event5", NULL, -1, 0, 0, 0 }, + { "/dev/input/event6", NULL, -1, 0, 0, 0 }, + { "/dev/input/event7", NULL, -1, 0, 0, 0 }, + { NULL, NULL, -1, 0, 0, 0 } }; #define number_of_input_devices (sizeof(input_device)/sizeof(input_device_t) - 1) -static void do_mknod(int i, char *d_name) { +static void do_mknod(int i, char *d_name) +{ char name[255]; int dev = -1; // I've no idea how the event device number is actually calculated. Just loop. --martii - for (int j = 0; j < 99 && dev < 0; j++) { + for (int j = 0; j < 99 && dev < 0; j++) + { snprintf(name, sizeof(name), VIRTUALINPUT "/%s/event%d/dev", d_name, j); - dev = open (name, O_RDONLY); + dev = open(name, O_RDONLY); } - if (dev > -1) { + if (dev > -1) + { char buf[255]; int l = read(dev, buf, sizeof(buf) - 1); close(dev); - if (l > -1) { + if (l > -1) + { buf[l] = 0; - if (2 == sscanf(buf, "%d:%d", &input_device[i].major, &input_device[i].minor)) { + if (2 == sscanf(buf, "%d:%d", &input_device[i].major, &input_device[i].minor)) + { mknod(input_device[i].name, 0666 | S_IFCHR, - gnu_dev_makedev(input_device[i].major, input_device[i].minor)); + gnu_dev_makedev(input_device[i].major, input_device[i].minor)); } } } } -static void create_input_devices (void) { - DIR *d = opendir (VIRTUALINPUT); - if (d) { +static void create_input_devices(void) +{ + DIR *d = opendir(VIRTUALINPUT); + if (d) + { struct dirent *e; - while ((e = readdir(d))) { + while ((e = readdir(d))) + { char name[255]; if (e->d_name[0] == '.') continue; snprintf(name, sizeof(name), VIRTUALINPUT "/%s/name", e->d_name); int n = open(name, O_RDONLY); - if (n > -1) { + if (n > -1) + { char buf[255]; int l = read(n, buf, sizeof(buf) - 1); close(n); - if (l > 1) { + if (l > 1) + { do buf[l--] = 0; while (l > 1 && buf[l] == '\n'); for (unsigned int i = 0; i < number_of_input_devices; i++) - if (input_device[i].desc && !strcmp(buf, input_device[i].desc)) { + if (input_device[i].desc && !strcmp(buf, input_device[i].desc)) + { do_mknod(i, e->d_name); break; } @@ -116,10 +129,12 @@ static void create_input_devices (void) { closedir(d); } // remove any event* files left that point to our "well-known" inputs - d = opendir (DEVINPUT); - if (d) { + d = opendir(DEVINPUT); + if (d) + { struct dirent *e; - while ((e = readdir(d))) { + while ((e = readdir(d))) + { char name[255]; if (strncmp(e->d_name, "event", 5)) continue; @@ -140,49 +155,63 @@ static void create_input_devices (void) { static pthread_t inmux_task = 0; static int inmux_thread_running = 0; -static void open_input_devices(void) { +static void open_input_devices(void) +{ time_t now = time(NULL); for (unsigned int i = 0; i < number_of_input_devices; i++) - if ((input_device[i].fd < 0) && (input_device[i].next_discovery <= now)) { + if ((input_device[i].fd < 0) && (input_device[i].next_discovery <= now)) + { input_device[i].next_discovery = now + 60; input_device[i].fd = open(input_device[i].name, O_RDWR | O_NONBLOCK); } } -static void reopen_input_devices(void) { +static void reopen_input_devices(void) +{ create_input_devices(); time_t now = time(NULL); - for (unsigned int i = 0; i < number_of_input_devices; i++) { + for (unsigned int i = 0; i < number_of_input_devices; i++) + { input_device[i].next_discovery = now + 60; int fd = open(input_device[i].name, O_RDWR | O_NONBLOCK); - if (fd > -1) { - if (input_device[i].fd > -1) { + if (fd > -1) + { + if (input_device[i].fd > -1) + { dup2(fd, input_device[i].fd); - close (fd); - } else { + close(fd); + } + else + { input_device[i].fd = fd; } - } else if (input_device[i].fd > -1) { - close (input_device[i].fd); + } + else if (input_device[i].fd > -1) + { + close(input_device[i].fd); input_device[i].fd = -1; } } } -static void close_input_devices(void) { +static void close_input_devices(void) +{ for (unsigned int i = 0; i < number_of_input_devices; i++) - if (input_device[i].fd > -1) { + if (input_device[i].fd > -1) + { close(input_device[i].fd); input_device[i].fd = -1; } } -static void poll_input_devices(void) { +static void poll_input_devices(void) +{ struct pollfd fds[number_of_input_devices]; input_device_t *inputs[number_of_input_devices]; int nfds = 0; for (unsigned int i = 1; i < number_of_input_devices; i++) - if (input_device[i].fd > -1) { + if (input_device[i].fd > -1) + { fds[nfds].fd = input_device[i].fd; fds[nfds].events = POLLIN | POLLHUP | POLLERR; fds[nfds].revents = 0; @@ -190,7 +219,8 @@ static void poll_input_devices(void) { nfds++; } - if (nfds == 0) { + if (nfds == 0) + { // Only a single input device, which happens to be our master. poll() to avoid looping too fast. fds[0].fd = input_device[0].fd; fds[0].events = POLLIN | POLLHUP | POLLERR; @@ -200,23 +230,29 @@ static void poll_input_devices(void) { } int r = poll(fds, nfds, 60000 /* ms */); - if (r < 0) { - if (errno != EAGAIN) { + if (r < 0) + { + if (errno != EAGAIN) + { hal_info("%s: poll(): %m\n", __func__); inmux_thread_running = 0; } return; } - for (int i = 0; i < nfds && r > 0; i++) { - if (fds[i].revents & POLLIN) { + for (int i = 0; i < nfds && r > 0; i++) + { + if (fds[i].revents & POLLIN) + { //fprintf(stderr, "### input from fd %d (%s)\n", fds[i].fd, inputs[i]->name); struct input_event ev; while (sizeof(ev) == read(fds[i].fd, &ev, sizeof(ev))) write(input_device[0].fd, &ev, sizeof(ev)); r--; - } else if (fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) { + } + else if (fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) + { //fprintf(stderr, "### error on %d (%s)\n", fds[i].fd, inputs[i]->name); - close (fds[i].fd); + close(fds[i].fd); inputs[i]->fd = -1; r--; } @@ -228,10 +264,11 @@ static void *inmux_thread(void *) char threadname[17]; strncpy(threadname, __func__, sizeof(threadname)); threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); + prctl(PR_SET_NAME, (unsigned long)&threadname); inmux_thread_running = 1; - while (inmux_thread_running) { + while (inmux_thread_running) + { open_input_devices(); poll_input_devices(); } @@ -242,7 +279,8 @@ static void *inmux_thread(void *) void start_inmux_thread(void) { input_device[0].fd = open(input_device[0].name, O_RDWR | O_NONBLOCK); // nevis_ir. This is mandatory. - if (input_device[0].fd < 0){ + if (input_device[0].fd < 0) + { hal_info("%s: open(%s): %m\n", __func__, input_device[0].name); return; } @@ -270,14 +308,14 @@ void hal_api_init() if (!initialized) { cCpuFreqManager f; - f.SetCpuFreq(0); /* CPUFREQ == 0 is the trigger for leaving standby */ + f.SetCpuFreq(0); /* CPUFREQ == 0 is the trigger for leaving standby */ create_input_devices(); start_inmux_thread(); /* this is a strange hack: the drivers seem to only work correctly after * demux0 has been used once. After that, we can use demux1,2,... */ struct dmx_pes_filter_params p; - int dmx = open("/dev/dvb/adapter0/demux0", O_RDWR|O_CLOEXEC); + int dmx = open("/dev/dvb/adapter0/demux0", O_RDWR | O_CLOEXEC); if (dmx < 0) hal_info("%s: ERROR open /dev/dvb/adapter0/demux0 (%m)\n", __func__); else @@ -301,7 +339,8 @@ void hal_api_init() void hal_api_exit() { hal_info("%s, initialized = %d\n", __FUNCTION__, (int)initialized); - if (initialized) { + if (initialized) + { stop_inmux_thread(); close_input_devices(); } diff --git a/libspark/irmp.c b/libspark/irmp.c index 68b82cc..9daf3b4 100644 --- a/libspark/irmp.c +++ b/libspark/irmp.c @@ -1,4284 +1,4474 @@ -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * irmp.c - infrared multi-protocol decoder, supports several remote control protocols - * - * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de - * - * $Id: irmp.c,v 1.115 2012/02/21 08:41:46 fm Exp $ - * - * ATMEGA88 @ 8 MHz - * - * Supported mikrocontrollers: - * - * ATtiny45, ATtiny85 - * ATtiny84 - * ATmega8, ATmega16, ATmega32 - * ATmega162 - * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284 - * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P - * - * Typical manufacturers of remote controls: - * - * SIRCS - Sony - * NEC - NEC, Yamaha, Canon, Tevion, Harman/Kardon, Hitachi, JVC, Pioneer, Toshiba, Xoro, Orion, and many other Japanese manufacturers - * SAMSUNG - Samsung - * SAMSUNG32 - Samsung - * MATSUSHITA - Matsushita - * KASEIKYO - Panasonic, Denon & other Japanese manufacturers (members of "Japan's Association for Electric Home Application") - * RECS80 - Philips, Nokia, Thomson, Nordmende, Telefunken, Saba - * RC5 - Philips and other European manufacturers - * DENON - Denon, Sharp - * RC6 - Philips and other European manufacturers - * APPLE - Apple - * NUBERT - Nubert Subwoofer System - * B&O - Bang & Olufsen - * PANASONIC - Panasonic (older, yet not implemented) - * GRUNDIG - Grundig - * NOKIA - Nokia - * SIEMENS - Siemens, e.g. Gigaset M740AV - * FDC - FDC IR keyboard - * RCCAR - IR remote control for RC cars - * JVC - JVC - * THOMSON - Thomson - * NIKON - Nikon cameras - * RUWIDO - T-Home - * KATHREIN - Kathrein - * LEGO - Lego Power Functions RC - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * SIRCS - * ----- - * - * frame: 1 start bit + 12-20 data bits + no stop bit - * data: 7 command bits + 5 address bits + 0 to 8 additional bits - * - * start bit: data "0": data "1": stop bit: - * -----------------_________ ------_____ ------------______ - * 2400us 600us 600us 600us 1200us 600 us no stop bit - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * NEC + extended NEC - * ------------------------- - * - * frame: 1 start bit + 32 data bits + 1 stop bit - * data NEC: 8 address bits + 8 inverted address bits + 8 command bits + 8 inverted command bits - * data extended NEC: 16 address bits + 8 command bits + 8 inverted command bits - * - * start bit: data "0": data "1": stop bit: - * -----------------_________ ------______ ------________________ ------______.... - * 9000us 4500us 560us 560us 560us 1690 us 560us - * - * - * Repetition frame: - * - * -----------------_________------______ .... ~100ms Pause, then repeat - * 9000us 2250us 560us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * SAMSUNG - * ------- - * - * frame: 1 start bit + 16 data(1) bits + 1 sync bit + additional 20 data(2) bits + 1 stop bit - * data(1): 16 address bits - * data(2): 4 ID bits + 8 command bits + 8 inverted command bits - * - * start bit: data "0": data "1": sync bit: stop bit: - * ----------______________ ------______ ------________________ ------______________ ------______.... - * 4500us 4500us 550us 450us 550us 1450us 550us 4500us 550us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * SAMSUNG32 - * ---------- - * - * frame: 1 start bit + 32 data bits + 1 stop bit - * data: 16 address bits + 16 command bits - * - * start bit: data "0": data "1": stop bit: - * ----------______________ ------______ ------________________ ------______.... - * 4500us 4500us 550us 450us 550us 1450us 550us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * MATSUSHITA - * ---------- - * - * frame: 1 start bit + 24 data bits + 1 stop bit - * data: 6 custom bits + 6 command bits + 12 address bits - * - * start bit: data "0": data "1": stop bit: - * ----------_________ ------______ ------________________ ------______.... - * 3488us 3488us 872us 872us 872us 2616us 872us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * KASEIKYO - * -------- - * - * frame: 1 start bit + 48 data bits + 1 stop bit - * data: 16 manufacturer bits + 4 parity bits + 4 genre1 bits + 4 genre2 bits + 10 command bits + 2 id bits + 8 parity bits - * - * start bit: data "0": data "1": stop bit: - * ----------______ ------______ ------________________ ------______.... - * 3380us 1690us 423us 423us 423us 1269us 423us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * RECS80 - * ------ - * - * frame: 2 start bits + 10 data bits + 1 stop bit - * data: 1 toggle bit + 3 address bits + 6 command bits - * - * start bit: data "0": data "1": stop bit: - * -----_____________________ -----____________ -----______________ ------_______.... - * 158us 7432us 158us 4902us 158us 7432us 158us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * RECS80EXT - * --------- - * - * frame: 2 start bits + 11 data bits + 1 stop bit - * data: 1 toggle bit + 4 address bits + 6 command bits - * - * start bit: data "0": data "1": stop bit: - * -----_____________________ -----____________ -----______________ ------_______.... - * 158us 3637us 158us 4902us 158us 7432us 158us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * RC5 + RC5X - * ---------- - * - * RC5 frame: 2 start bits + 12 data bits + no stop bit - * RC5 data: 1 toggle bit + 5 address bits + 6 command bits - * RC5X frame: 1 start bit + 13 data bits + no stop bit - * RC5X data: 1 inverted command bit + 1 toggle bit + 5 address bits + 6 command bits - * - * start bit: data "0": data "1": - * ______----- ------______ ______------ - * 889us 889us 889us 889us 889us 889us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * DENON - * ----- - * - * frame: 0 start bits + 16 data bits + stop bit + 65ms pause + 16 inverted data bits + stop bit - * data: 5 address bits + 10 command bits - * - * Theory: - * - * data "0": data "1": - * ------________________ ------______________ - * 275us 775us 275us 1900us - * - * Practice: - * - * data "0": data "1": - * ------________________ ------______________ - * 310us 745us 310us 1780us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * RC6 - * --- - * - * RC6 frame: 1 start bit + 1 bit "1" + 3 mode bits + 1 toggle bit + 16 data bits + 2666 us pause - * RC6 data: 8 address bits + 8 command bits - * - * start bit toggle bit "0": toggle bit "1": data/mode "0": data/mode "1": - * ____________------- _______------- -------_______ _______------- -------_______ - * 2666us 889us 889us 889us 889us 889us 444us 444us 444us 444us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * APPLE - * ----- - * - * frame: 1 start bit + 32 data bits + 1 stop bit - * data: 16 address bits + 11100000 + 8 command bits - * - * start bit: data "0": data "1": stop bit: - * -----------------_________ ------______ ------________________ ------______.... - * 9000us 4500us 560us 560us 560us 1690 us 560us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * NUBERT (subwoofer system) - * ------------------------- - * - * frame: 1 start bit + 10 data bits + 1 stop bit - * data: 0 address bits + 10 command bits ? - * - * start bit: data "0": data "1": stop bit: - * ----------_____ ------______ ------________________ ------______.... - * 1340us 340us 500us 1300us 1340us 340us 500us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * BANG_OLUFSEN - * ------------ - * - * frame: 4 start bits + 16 data bits + 1 trailer bit + 1 stop bit - * data: 0 address bits + 16 command bits - * - * 1st start bit: 2nd start bit: 3rd start bit: 4th start bit: - * -----________ -----________ -----_____________ -----________ - * 210us 3000us 210us 3000us 210us 15000us 210us 3000us - * - * data "0": data "1": data "repeat bit": trailer bit: stop bit: - * -----________ -----_____________ -----___________ -----_____________ -----____... - * 210us 3000us 210us 9000us 210us 6000us 210us 12000us 210us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * GRUNDIG - * ------- - * - * packet: 1 start frame + 19,968ms pause + N info frames + 117,76ms pause + 1 stop frame - * frame: 1 pre bit + 1 start bit + 9 data bits + no stop bit - * pause between info frames: 117,76ms - * - * data of start frame: 9 x 1 - * data of info frame: 9 command bits - * data of stop frame: 9 x 1 - * - * pre bit: start bit data "0": data "1": - * ------____________ ------______ ______------ ------______ - * 528us 2639us 528us 528us 528us 528us 528us 528us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * NOKIA: - * ------ - * - * Timing similar to Grundig, but 16 data bits: - * frame: 1 pre bit + 1 start bit + 8 command bits + 8 address bits + no stop bit - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * SIEMENS or RUWIDO: - * ------------------ - * - * SIEMENS frame: 1 start bit + 22 data bits + no stop bit - * SIEMENS data: 13 address bits + 1 repeat bit + 7 data bits + 1 unknown bit - * - * start bit data "0": data "1": - * -------_______ _______------- -------_______ - * 250us 250us 250us 250us 250us 250us - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * PANASONIC (older protocol, yet not implemented, see also MATSUSHITA, timing very similar) - * ----------------------------------------------------------------------------------------- - * - * frame: 1 start bit + 22 data bits + 1 stop bit - * 22 data bits = 5 custom bits + 6 data bits + 5 inverted custom bits + 6 inverted data bits - * - * European version: T = 456us - * USA & Canada version: T = 422us - * - * start bit: data "0": data "1": stop bit: - * 8T 8T 2T 2T 2T 6T 2T - * -------------____________ ------_____ ------_____________ ------_______.... - * 3648us 3648us 912us 912us 912us 2736us 912us (Europe) - * 3376us 3376us 844us 844us 844us 2532us 844us (US) - * - *--------------------------------------------------------------------------------------------------------------------------------------------------- - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ - -#if defined(__18CXX) -#define PIC_C18 // Microchip C18 Compiler -#endif - -#if defined(__PCM__) || defined(__PCB__) || defined(__PCH__) // CCS PIC Compiler instead of AVR -#define PIC_CCS_COMPILER -#endif - -#ifdef unix // test on linux/unix -#include -#include -#include -#include -#include - -/* for crazy lirc stuff... */ -#include -#include -#include -#include - -#define ANALYZE -#define PROGMEM -#define memcpy_P memcpy - -#else // not unix: - -#ifdef WIN32 -#include -#include -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -#define ANALYZE -#define PROGMEM -#define memcpy_P memcpy - -#else - -#if defined (PIC_CCS_COMPILER) || defined(PIC_C18) - -#include -#define PROGMEM -#define memcpy_P memcpy - -#if defined (PIC_CCS_COMPILER) -typedef unsigned int8 uint8_t; -typedef unsigned int16 uint16_t; -#endif - -#else // AVR: - -#include -#include -#include -#include -#include -#include - -#endif // PIC_CCS_COMPILER or PIC_C18 - -#endif // windows -#endif // unix - -#ifndef IRMP_USE_AS_LIB -#include "irmpconfig.h" -#endif -#include "irmp.h" - -#if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRMP_SUPPORT_NOKIA_PROTOCOL == 1 || IRMP_SUPPORT_IR60_PROTOCOL == 1 -#define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL 1 -#else -#define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL 0 -#endif - -#if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1 || IRMP_SUPPORT_RUWIDO_PROTOCOL == 1 -#define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL 1 -#else -#define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL 0 -#endif - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 || \ - IRMP_SUPPORT_RC6_PROTOCOL == 1 || \ - IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 || \ - IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 || \ - IRMP_SUPPORT_GRUNDIG2_PROTOCOL == 1 || \ - IRMP_SUPPORT_IR60_PROTOCOL -#define IRMP_SUPPORT_MANCHESTER 1 -#else -#define IRMP_SUPPORT_MANCHESTER 0 -#endif - -#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 -#define IRMP_SUPPORT_SERIAL 1 -#else -#define IRMP_SUPPORT_SERIAL 0 -#endif - -#define IRMP_KEY_REPETITION_LEN (uint16_t)(F_INTERRUPTS * 150.0e-3 + 0.5) // autodetect key repetition within 150 msec - -#define MIN_TOLERANCE_00 1.0 // -0% -#define MAX_TOLERANCE_00 1.0 // +0% - -#define MIN_TOLERANCE_05 0.95 // -5% -#define MAX_TOLERANCE_05 1.05 // +5% - -#define MIN_TOLERANCE_10 0.9 // -10% -#define MAX_TOLERANCE_10 1.1 // +10% - -#define MIN_TOLERANCE_15 0.85 // -15% -#define MAX_TOLERANCE_15 1.15 // +15% - -#define MIN_TOLERANCE_20 0.8 // -20% -#define MAX_TOLERANCE_20 1.2 // +20% - -#define MIN_TOLERANCE_30 0.7 // -30% -#define MAX_TOLERANCE_30 1.3 // +30% - -#define MIN_TOLERANCE_40 0.6 // -40% -#define MAX_TOLERANCE_40 1.4 // +40% - -#define MIN_TOLERANCE_50 0.5 // -50% -#define MAX_TOLERANCE_50 1.5 // +50% - -#define MIN_TOLERANCE_60 0.4 // -60% -#define MAX_TOLERANCE_60 1.6 // +60% - -#define MIN_TOLERANCE_70 0.3 // -70% -#define MAX_TOLERANCE_70 1.7 // +70% - -#define SIRCS_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SIRCS_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define SIRCS_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#if IRMP_SUPPORT_NETBOX_PROTOCOL // only 5% to avoid conflict with NETBOX: -#define SIRCS_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5)) -#else // only 5% + 1 to avoid conflict with RC6: -#define SIRCS_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) -#endif -#define SIRCS_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SIRCS_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define SIRCS_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SIRCS_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define SIRCS_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SIRCS_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define NEC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define NEC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -#define NEC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define NEC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -#define NEC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define NEC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -#define NEC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define NEC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -#define NEC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define NEC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -#define NEC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define NEC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -// autodetect nec repetition frame within 50 msec: -// NEC seems to send the first repetition frame after 40ms, further repetition frames after 100 ms -#if 0 -#define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) -#else -#define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * 100.0e-3 * MAX_TOLERANCE_20 + 0.5) -#endif - -#define SAMSUNG_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SAMSUNG_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define SAMSUNG_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SAMSUNG_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define SAMSUNG_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define SAMSUNG_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -#define SAMSUNG_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define SAMSUNG_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -#define SAMSUNG_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define SAMSUNG_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) - -#define MATSUSHITA_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define MATSUSHITA_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define MATSUSHITA_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define MATSUSHITA_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define MATSUSHITA_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define MATSUSHITA_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define MATSUSHITA_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define MATSUSHITA_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define MATSUSHITA_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define MATSUSHITA_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) - -#define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define KASEIKYO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1) -#define KASEIKYO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1) -#define KASEIKYO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define KASEIKYO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -#define KASEIKYO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1) -#define KASEIKYO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1) - -#define RECS80_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1) -#define RECS80_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RECS80_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RECS80_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RECS80_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RECS80_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RECS80_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RECS80_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RECS80_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RECS80_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define RC5_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RC5_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define RC5_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RC5_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define DENON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define DENON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define DENON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define DENON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 -#define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5)) // no -1, avoid conflict with RUWIDO -#else -#define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) // be more tolerant -#endif -#define DENON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define THOMSON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define THOMSON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define THOMSON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define THOMSON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define THOMSON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define THOMSON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define RC6_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RC6_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RC6_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RC6_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RC6_TOGGLE_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RC6_TOGGLE_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RC6_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RC6_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_60 + 0.5) + 1) // pulses: 300 - 800 -#define RC6_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RC6_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1) // pauses: 300 - 600 - -#define RECS80EXT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1) -#define RECS80EXT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MAX_TOLERANCE_00 + 0.5) + 1) -#define RECS80EXT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1) -#define RECS80EXT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) -#define RECS80EXT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RECS80EXT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RECS80EXT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RECS80EXT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RECS80EXT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RECS80EXT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define NUBERT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NUBERT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NUBERT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NUBERT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NUBERT_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NUBERT_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NUBERT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NUBERT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NUBERT_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NUBERT_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NUBERT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NUBERT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) - -#define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX ((PAUSE_LEN)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) // value must be below IRMP_TIMEOUT -#define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_R_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_R_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define IR60_TIMEOUT_LEN ((uint8_t)(F_INTERRUPTS * IR60_TIMEOUT_TIME * 0.5)) -#define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define GRUNDIG_NOKIA_IR60_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define GRUNDIG_NOKIA_IR60_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) + 1) -#define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) - -#define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define GRUNDIG2_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG2_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define GRUNDIG2_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG2_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define GRUNDIG2_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG2_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define GRUNDIG2_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG2_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define GRUNDIG2_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG2_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define GRUNDIG2_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG2_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define GRUNDIG2_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG2_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define GRUNDIG2_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG2_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define FDC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1) // 5%: avoid conflict with NETBOX -#define FDC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MAX_TOLERANCE_05 + 0.5)) -#define FDC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1) -#define FDC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5)) -#define FDC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define FDC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1) -#define FDC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define FDC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#if 0 -#define FDC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) // could be negative: 255 -#else -#define FDC_0_PAUSE_LEN_MIN (1) // simply use 1 -#endif -#define FDC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define RCCAR_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RCCAR_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RCCAR_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define RCCAR_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define RCCAR_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define RCCAR_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define RCCAR_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define RCCAR_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) -#define RCCAR_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) -#define RCCAR_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) - -#define JVC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define JVC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define JVC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MIN_TOLERANCE_40 + 0.5) - 1) // HACK! -#define JVC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MAX_TOLERANCE_70 + 0.5) - 1) // HACK! -#define JVC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define JVC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define JVC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define JVC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define JVC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define JVC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -// autodetect JVC repetition frame within 50 msec: -#define JVC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * JVC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) - -#define NIKON_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NIKON_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NIKON_START_BIT_PAUSE_LEN_MIN ((uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NIKON_START_BIT_PAUSE_LEN_MAX ((uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NIKON_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NIKON_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NIKON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NIKON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NIKON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NIKON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NIKON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) -#define NIKON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) -#define NIKON_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) - -#define KATHREIN_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KATHREIN_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define KATHREIN_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KATHREIN_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define KATHREIN_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KATHREIN_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define KATHREIN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KATHREIN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define KATHREIN_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KATHREIN_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define KATHREIN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KATHREIN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define KATHREIN_SYNC_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define KATHREIN_SYNC_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MAX_TOLERANCE_10 + 0.5) + 1) - -#define NETBOX_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define NETBOX_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define NETBOX_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) -#define NETBOX_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) -#define NETBOX_PULSE_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME)) -#define NETBOX_PAUSE_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME)) -#define NETBOX_PULSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME / 4)) -#define NETBOX_PAUSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME / 4)) - -#define LEGO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define LEGO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define LEGO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define LEGO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define LEGO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define LEGO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define LEGO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define LEGO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) -#define LEGO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) -#define LEGO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) - -#define AUTO_FRAME_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5) // use uint16_t! - -#ifdef ANALYZE -#define ANALYZE_PUTCHAR(a) { if (! silent) { putchar (a); } } -#ifndef LIRC_IRMP -#define ANALYZE_ONLY_NORMAL_PUTCHAR(a) { if (! silent && !verbose) { putchar (a); } } -#else -#define ANALYZE_ONLY_NORMAL_PUTCHAR(a) -#endif -#define ANALYZE_PRINTF(...) { if (verbose) { printf (__VA_ARGS__); } } -#define ANALYZE_NEWLINE() { if (verbose) { putchar ('\n'); } } -static int silent = TRUE; -static int time_counter; -static int verbose; -#else -#define ANALYZE_PUTCHAR(a) -#define ANALYZE_ONLY_NORMAL_PUTCHAR(a) -#define ANALYZE_PRINTF(...) -#define ANALYZE_NEWLINE() -#endif - -#if IRMP_USE_CALLBACK == 1 -static void (*irmp_callback_ptr) (uint8_t); -#endif // IRMP_USE_CALLBACK == 1 - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Protocol names - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#if IRMP_PROTOCOL_NAMES == 1 -char * -irmp_protocol_names[IRMP_N_PROTOCOLS + 1] = -{ - "UNKNOWN", - "SIRCS", - "NEC", - "SAMSUNG", - "MATSUSH", - "KASEIKYO", - "RECS80", - "RC5", - "DENON", - "RC6", - "SAMSG32", - "APPLE", - "RECS80EX", - "NUBERT", - "BANG OLU", - "GRUNDIG", - "NOKIA", - "SIEMENS", - "FDC", - "RCCAR", - "JVC", - "RC6A", - "NIKON", - "RUWIDO", - "IR60", - "KATHREIN", - "NETBOX", - "NEC16", - "NEC42", - "LEGO", - "THOMSON" -}; -#endif - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Logging - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#if IRMP_LOGGING == 1 // logging via UART - -#if IRMP_EXT_LOGGING == 1 // use external logging -#include "irmpextlog.h" -#else // normal UART log (IRMP_EXT_LOGGING == 0) -#define BAUD 9600L -#include - -#ifdef UBRR0H - -#define UART0_UBRRH UBRR0H -#define UART0_UBRRL UBRR0L -#define UART0_UCSRA UCSR0A -#define UART0_UCSRB UCSR0B -#define UART0_UCSRC UCSR0C -#define UART0_UDRE_BIT_VALUE (1< ENDBITS) - { // if stop condition is true, output on uart - uint16_t i; - - for (i = 0; i < STARTCYCLES; i++) - { - irmp_uart_putc ('0'); // the ignored starting zeros - } - - for (i = 0; i < (buf_idx - ENDBITS + 20) / 8; i++) // transform bitset into uart chars - { - uint8_t d = buf[i]; - uint8_t j; - - for (j = 0; j < 8; j++) - { - irmp_uart_putc ((d & 1) + '0'); - d >>= 1; - } - } - - irmp_uart_putc ('\n'); - buf_idx = 0; - } - } - else - { - cnt = 0; - } - } - } -} - -#else -#define irmp_log(val) -#endif //IRMP_LOGGING - -typedef struct -{ - uint8_t protocol; // ir protocol - uint8_t pulse_1_len_min; // minimum length of pulse with bit value 1 - uint8_t pulse_1_len_max; // maximum length of pulse with bit value 1 - uint8_t pause_1_len_min; // minimum length of pause with bit value 1 - uint8_t pause_1_len_max; // maximum length of pause with bit value 1 - uint8_t pulse_0_len_min; // minimum length of pulse with bit value 0 - uint8_t pulse_0_len_max; // maximum length of pulse with bit value 0 - uint8_t pause_0_len_min; // minimum length of pause with bit value 0 - uint8_t pause_0_len_max; // maximum length of pause with bit value 0 - uint8_t address_offset; // address offset - uint8_t address_end; // end of address - uint8_t command_offset; // command offset - uint8_t command_end; // end of command - uint8_t complete_len; // complete length of frame - uint8_t stop_bit; // flag: frame has stop bit - uint8_t lsb_first; // flag: LSB first - uint8_t flags; // some flags -} IRMP_PARAMETER; - -#if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER sircs_param = -{ - IRMP_SIRCS_PROTOCOL, // protocol: ir protocol - SIRCS_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - SIRCS_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - SIRCS_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - SIRCS_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - SIRCS_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - SIRCS_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - SIRCS_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - SIRCS_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - SIRCS_ADDRESS_OFFSET, // address_offset: address offset - SIRCS_ADDRESS_OFFSET + SIRCS_ADDRESS_LEN, // address_end: end of address - SIRCS_COMMAND_OFFSET, // command_offset: command offset - SIRCS_COMMAND_OFFSET + SIRCS_COMMAND_LEN, // command_end: end of command - SIRCS_COMPLETE_DATA_LEN, // complete_len: complete length of frame - SIRCS_STOP_BIT, // stop_bit: flag: frame has stop bit - SIRCS_LSB, // lsb_first: flag: LSB first - SIRCS_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_NEC_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER nec_param = -{ - IRMP_NEC_PROTOCOL, // protocol: ir protocol - NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - NEC_ADDRESS_OFFSET, // address_offset: address offset - NEC_ADDRESS_OFFSET + NEC_ADDRESS_LEN, // address_end: end of address - NEC_COMMAND_OFFSET, // command_offset: command offset - NEC_COMMAND_OFFSET + NEC_COMMAND_LEN, // command_end: end of command - NEC_COMPLETE_DATA_LEN, // complete_len: complete length of frame - NEC_STOP_BIT, // stop_bit: flag: frame has stop bit - NEC_LSB, // lsb_first: flag: LSB first - NEC_FLAGS // flags: some flags -}; - -static const PROGMEM IRMP_PARAMETER nec_rep_param = -{ - IRMP_NEC_PROTOCOL, // protocol: ir protocol - NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - 0, // address_offset: address offset - 0, // address_end: end of address - 0, // command_offset: command offset - 0, // command_end: end of command - 0, // complete_len: complete length of frame - NEC_STOP_BIT, // stop_bit: flag: frame has stop bit - NEC_LSB, // lsb_first: flag: LSB first - NEC_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER nec42_param = -{ - IRMP_NEC42_PROTOCOL, // protocol: ir protocol - NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - NEC42_ADDRESS_OFFSET, // address_offset: address offset - NEC42_ADDRESS_OFFSET + NEC42_ADDRESS_LEN, // address_end: end of address - NEC42_COMMAND_OFFSET, // command_offset: command offset - NEC42_COMMAND_OFFSET + NEC42_COMMAND_LEN, // command_end: end of command - NEC42_COMPLETE_DATA_LEN, // complete_len: complete length of frame - NEC_STOP_BIT, // stop_bit: flag: frame has stop bit - NEC_LSB, // lsb_first: flag: LSB first - NEC_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER samsung_param = -{ - IRMP_SAMSUNG_PROTOCOL, // protocol: ir protocol - SAMSUNG_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - SAMSUNG_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - SAMSUNG_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - SAMSUNG_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - SAMSUNG_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - SAMSUNG_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - SAMSUNG_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - SAMSUNG_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - SAMSUNG_ADDRESS_OFFSET, // address_offset: address offset - SAMSUNG_ADDRESS_OFFSET + SAMSUNG_ADDRESS_LEN, // address_end: end of address - SAMSUNG_COMMAND_OFFSET, // command_offset: command offset - SAMSUNG_COMMAND_OFFSET + SAMSUNG_COMMAND_LEN, // command_end: end of command - SAMSUNG_COMPLETE_DATA_LEN, // complete_len: complete length of frame - SAMSUNG_STOP_BIT, // stop_bit: flag: frame has stop bit - SAMSUNG_LSB, // lsb_first: flag: LSB first - SAMSUNG_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER matsushita_param = -{ - IRMP_MATSUSHITA_PROTOCOL, // protocol: ir protocol - MATSUSHITA_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - MATSUSHITA_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - MATSUSHITA_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - MATSUSHITA_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - MATSUSHITA_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - MATSUSHITA_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - MATSUSHITA_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - MATSUSHITA_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - MATSUSHITA_ADDRESS_OFFSET, // address_offset: address offset - MATSUSHITA_ADDRESS_OFFSET + MATSUSHITA_ADDRESS_LEN, // address_end: end of address - MATSUSHITA_COMMAND_OFFSET, // command_offset: command offset - MATSUSHITA_COMMAND_OFFSET + MATSUSHITA_COMMAND_LEN, // command_end: end of command - MATSUSHITA_COMPLETE_DATA_LEN, // complete_len: complete length of frame - MATSUSHITA_STOP_BIT, // stop_bit: flag: frame has stop bit - MATSUSHITA_LSB, // lsb_first: flag: LSB first - MATSUSHITA_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER kaseikyo_param = -{ - IRMP_KASEIKYO_PROTOCOL, // protocol: ir protocol - KASEIKYO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - KASEIKYO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - KASEIKYO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - KASEIKYO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - KASEIKYO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - KASEIKYO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - KASEIKYO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - KASEIKYO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - KASEIKYO_ADDRESS_OFFSET, // address_offset: address offset - KASEIKYO_ADDRESS_OFFSET + KASEIKYO_ADDRESS_LEN, // address_end: end of address - KASEIKYO_COMMAND_OFFSET, // command_offset: command offset - KASEIKYO_COMMAND_OFFSET + KASEIKYO_COMMAND_LEN, // command_end: end of command - KASEIKYO_COMPLETE_DATA_LEN, // complete_len: complete length of frame - KASEIKYO_STOP_BIT, // stop_bit: flag: frame has stop bit - KASEIKYO_LSB, // lsb_first: flag: LSB first - KASEIKYO_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_RECS80_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER recs80_param = -{ - IRMP_RECS80_PROTOCOL, // protocol: ir protocol - RECS80_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - RECS80_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - RECS80_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - RECS80_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - RECS80_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - RECS80_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - RECS80_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - RECS80_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - RECS80_ADDRESS_OFFSET, // address_offset: address offset - RECS80_ADDRESS_OFFSET + RECS80_ADDRESS_LEN, // address_end: end of address - RECS80_COMMAND_OFFSET, // command_offset: command offset - RECS80_COMMAND_OFFSET + RECS80_COMMAND_LEN, // command_end: end of command - RECS80_COMPLETE_DATA_LEN, // complete_len: complete length of frame - RECS80_STOP_BIT, // stop_bit: flag: frame has stop bit - RECS80_LSB, // lsb_first: flag: LSB first - RECS80_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER rc5_param = -{ - IRMP_RC5_PROTOCOL, // protocol: ir protocol - RC5_BIT_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse - RC5_BIT_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse - RC5_BIT_LEN_MIN, // pause_1_len_min: here: minimum length of short pause - RC5_BIT_LEN_MAX, // pause_1_len_max: here: maximum length of short pause - 0, // pulse_0_len_min: here: not used - 0, // pulse_0_len_max: here: not used - 0, // pause_0_len_min: here: not used - 0, // pause_0_len_max: here: not used - RC5_ADDRESS_OFFSET, // address_offset: address offset - RC5_ADDRESS_OFFSET + RC5_ADDRESS_LEN, // address_end: end of address - RC5_COMMAND_OFFSET, // command_offset: command offset - RC5_COMMAND_OFFSET + RC5_COMMAND_LEN, // command_end: end of command - RC5_COMPLETE_DATA_LEN, // complete_len: complete length of frame - RC5_STOP_BIT, // stop_bit: flag: frame has stop bit - RC5_LSB, // lsb_first: flag: LSB first - RC5_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_DENON_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER denon_param = -{ - IRMP_DENON_PROTOCOL, // protocol: ir protocol - DENON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - DENON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - DENON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - DENON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - DENON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - DENON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - DENON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - DENON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - DENON_ADDRESS_OFFSET, // address_offset: address offset - DENON_ADDRESS_OFFSET + DENON_ADDRESS_LEN, // address_end: end of address - DENON_COMMAND_OFFSET, // command_offset: command offset - DENON_COMMAND_OFFSET + DENON_COMMAND_LEN, // command_end: end of command - DENON_COMPLETE_DATA_LEN, // complete_len: complete length of frame - DENON_STOP_BIT, // stop_bit: flag: frame has stop bit - DENON_LSB, // lsb_first: flag: LSB first - DENON_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_RC6_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER rc6_param = -{ - IRMP_RC6_PROTOCOL, // protocol: ir protocol - - RC6_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse - RC6_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse - RC6_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause - RC6_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause - 0, // pulse_0_len_min: here: not used - 0, // pulse_0_len_max: here: not used - 0, // pause_0_len_min: here: not used - 0, // pause_0_len_max: here: not used - RC6_ADDRESS_OFFSET, // address_offset: address offset - RC6_ADDRESS_OFFSET + RC6_ADDRESS_LEN, // address_end: end of address - RC6_COMMAND_OFFSET, // command_offset: command offset - RC6_COMMAND_OFFSET + RC6_COMMAND_LEN, // command_end: end of command - RC6_COMPLETE_DATA_LEN_SHORT, // complete_len: complete length of frame - RC6_STOP_BIT, // stop_bit: flag: frame has stop bit - RC6_LSB, // lsb_first: flag: LSB first - RC6_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER recs80ext_param = -{ - IRMP_RECS80EXT_PROTOCOL, // protocol: ir protocol - RECS80EXT_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - RECS80EXT_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - RECS80EXT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - RECS80EXT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - RECS80EXT_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - RECS80EXT_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - RECS80EXT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - RECS80EXT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - RECS80EXT_ADDRESS_OFFSET, // address_offset: address offset - RECS80EXT_ADDRESS_OFFSET + RECS80EXT_ADDRESS_LEN, // address_end: end of address - RECS80EXT_COMMAND_OFFSET, // command_offset: command offset - RECS80EXT_COMMAND_OFFSET + RECS80EXT_COMMAND_LEN, // command_end: end of command - RECS80EXT_COMPLETE_DATA_LEN, // complete_len: complete length of frame - RECS80EXT_STOP_BIT, // stop_bit: flag: frame has stop bit - RECS80EXT_LSB, // lsb_first: flag: LSB first - RECS80EXT_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_NUBERT_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER nubert_param = -{ - IRMP_NUBERT_PROTOCOL, // protocol: ir protocol - NUBERT_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - NUBERT_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - NUBERT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - NUBERT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - NUBERT_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - NUBERT_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - NUBERT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - NUBERT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - NUBERT_ADDRESS_OFFSET, // address_offset: address offset - NUBERT_ADDRESS_OFFSET + NUBERT_ADDRESS_LEN, // address_end: end of address - NUBERT_COMMAND_OFFSET, // command_offset: command offset - NUBERT_COMMAND_OFFSET + NUBERT_COMMAND_LEN, // command_end: end of command - NUBERT_COMPLETE_DATA_LEN, // complete_len: complete length of frame - NUBERT_STOP_BIT, // stop_bit: flag: frame has stop bit - NUBERT_LSB, // lsb_first: flag: LSB first - NUBERT_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER bang_olufsen_param = -{ - IRMP_BANG_OLUFSEN_PROTOCOL, // protocol: ir protocol - BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - BANG_OLUFSEN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - BANG_OLUFSEN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - BANG_OLUFSEN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - BANG_OLUFSEN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - BANG_OLUFSEN_ADDRESS_OFFSET, // address_offset: address offset - BANG_OLUFSEN_ADDRESS_OFFSET + BANG_OLUFSEN_ADDRESS_LEN, // address_end: end of address - BANG_OLUFSEN_COMMAND_OFFSET, // command_offset: command offset - BANG_OLUFSEN_COMMAND_OFFSET + BANG_OLUFSEN_COMMAND_LEN, // command_end: end of command - BANG_OLUFSEN_COMPLETE_DATA_LEN, // complete_len: complete length of frame - BANG_OLUFSEN_STOP_BIT, // stop_bit: flag: frame has stop bit - BANG_OLUFSEN_LSB, // lsb_first: flag: LSB first - BANG_OLUFSEN_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 - -static uint8_t first_bit; - -static const PROGMEM IRMP_PARAMETER grundig_param = -{ - IRMP_GRUNDIG_PROTOCOL, // protocol: ir protocol - - GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse - GRUNDIG_NOKIA_IR60_BIT_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse - GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, // pause_1_len_min: here: minimum length of short pause - GRUNDIG_NOKIA_IR60_BIT_LEN_MAX, // pause_1_len_max: here: maximum length of short pause - 0, // pulse_0_len_min: here: not used - 0, // pulse_0_len_max: here: not used - 0, // pause_0_len_min: here: not used - 0, // pause_0_len_max: here: not used - GRUNDIG_ADDRESS_OFFSET, // address_offset: address offset - GRUNDIG_ADDRESS_OFFSET + GRUNDIG_ADDRESS_LEN, // address_end: end of address - GRUNDIG_COMMAND_OFFSET, // command_offset: command offset - GRUNDIG_COMMAND_OFFSET + GRUNDIG_COMMAND_LEN + 1, // command_end: end of command (USE 1 bit MORE to STORE NOKIA DATA!) - NOKIA_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: NOKIA instead of GRUNDIG! - GRUNDIG_NOKIA_IR60_STOP_BIT, // stop_bit: flag: frame has stop bit - GRUNDIG_NOKIA_IR60_LSB, // lsb_first: flag: LSB first - GRUNDIG_NOKIA_IR60_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER ruwido_param = -{ - IRMP_RUWIDO_PROTOCOL, // protocol: ir protocol - SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse - SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse - SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause - SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause - 0, // pulse_0_len_min: here: not used - 0, // pulse_0_len_max: here: not used - 0, // pause_0_len_min: here: not used - 0, // pause_0_len_max: here: not used - RUWIDO_ADDRESS_OFFSET, // address_offset: address offset - RUWIDO_ADDRESS_OFFSET + RUWIDO_ADDRESS_LEN, // address_end: end of address - RUWIDO_COMMAND_OFFSET, // command_offset: command offset - RUWIDO_COMMAND_OFFSET + RUWIDO_COMMAND_LEN, // command_end: end of command - SIEMENS_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: SIEMENS instead of RUWIDO! - SIEMENS_OR_RUWIDO_STOP_BIT, // stop_bit: flag: frame has stop bit - SIEMENS_OR_RUWIDO_LSB, // lsb_first: flag: LSB first - SIEMENS_OR_RUWIDO_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_GRUNDIG2_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER grundig2_param = -{ - IRMP_GRUNDIG2_PROTOCOL, // protocol: ir protocol - GRUNDIG2_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse - GRUNDIG2_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse - GRUNDIG2_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause - GRUNDIG2_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause - 0, // pulse_0_len_min: here: not used - 0, // pulse_0_len_max: here: not used - 0, // pause_0_len_min: here: not used - 0, // pause_0_len_max: here: not used - GRUNDIG2_ADDRESS_OFFSET, // address_offset: address offset - GRUNDIG2_ADDRESS_OFFSET + GRUNDIG2_ADDRESS_LEN, // address_end: end of address - GRUNDIG2_COMMAND_OFFSET, // command_offset: command offset - GRUNDIG2_COMMAND_OFFSET + GRUNDIG2_COMMAND_LEN, // command_end: end of command - GRUNDIG2_COMPLETE_DATA_LEN, // complete_len: complete length of frame - GRUNDIG2_STOP_BIT, // stop_bit: flag: frame has stop bit - GRUNDIG2_LSB, // lsb_first: flag: LSB first - GRUNDIG2_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_FDC_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER fdc_param = -{ - IRMP_FDC_PROTOCOL, // protocol: ir protocol - FDC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - FDC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - FDC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - FDC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - FDC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - FDC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - FDC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - FDC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - FDC_ADDRESS_OFFSET, // address_offset: address offset - FDC_ADDRESS_OFFSET + FDC_ADDRESS_LEN, // address_end: end of address - FDC_COMMAND_OFFSET, // command_offset: command offset - FDC_COMMAND_OFFSET + FDC_COMMAND_LEN, // command_end: end of command - FDC_COMPLETE_DATA_LEN, // complete_len: complete length of frame - FDC_STOP_BIT, // stop_bit: flag: frame has stop bit - FDC_LSB, // lsb_first: flag: LSB first - FDC_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER rccar_param = -{ - IRMP_RCCAR_PROTOCOL, // protocol: ir protocol - RCCAR_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - RCCAR_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - RCCAR_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - RCCAR_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - RCCAR_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - RCCAR_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - RCCAR_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - RCCAR_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - RCCAR_ADDRESS_OFFSET, // address_offset: address offset - RCCAR_ADDRESS_OFFSET + RCCAR_ADDRESS_LEN, // address_end: end of address - RCCAR_COMMAND_OFFSET, // command_offset: command offset - RCCAR_COMMAND_OFFSET + RCCAR_COMMAND_LEN, // command_end: end of command - RCCAR_COMPLETE_DATA_LEN, // complete_len: complete length of frame - RCCAR_STOP_BIT, // stop_bit: flag: frame has stop bit - RCCAR_LSB, // lsb_first: flag: LSB first - RCCAR_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_NIKON_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER nikon_param = -{ - IRMP_NIKON_PROTOCOL, // protocol: ir protocol - NIKON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - NIKON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - NIKON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - NIKON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - NIKON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - NIKON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - NIKON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - NIKON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - NIKON_ADDRESS_OFFSET, // address_offset: address offset - NIKON_ADDRESS_OFFSET + NIKON_ADDRESS_LEN, // address_end: end of address - NIKON_COMMAND_OFFSET, // command_offset: command offset - NIKON_COMMAND_OFFSET + NIKON_COMMAND_LEN, // command_end: end of command - NIKON_COMPLETE_DATA_LEN, // complete_len: complete length of frame - NIKON_STOP_BIT, // stop_bit: flag: frame has stop bit - NIKON_LSB, // lsb_first: flag: LSB first - NIKON_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER kathrein_param = -{ - IRMP_KATHREIN_PROTOCOL, // protocol: ir protocol - KATHREIN_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - KATHREIN_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - KATHREIN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - KATHREIN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - KATHREIN_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - KATHREIN_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - KATHREIN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - KATHREIN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - KATHREIN_ADDRESS_OFFSET, // address_offset: address offset - KATHREIN_ADDRESS_OFFSET + KATHREIN_ADDRESS_LEN, // address_end: end of address - KATHREIN_COMMAND_OFFSET, // command_offset: command offset - KATHREIN_COMMAND_OFFSET + KATHREIN_COMMAND_LEN, // command_end: end of command - KATHREIN_COMPLETE_DATA_LEN, // complete_len: complete length of frame - KATHREIN_STOP_BIT, // stop_bit: flag: frame has stop bit - KATHREIN_LSB, // lsb_first: flag: LSB first - KATHREIN_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER netbox_param = -{ - IRMP_NETBOX_PROTOCOL, // protocol: ir protocol - NETBOX_PULSE_LEN, // pulse_1_len_min: minimum length of pulse with bit value 1, here: exact value - NETBOX_PULSE_REST_LEN, // pulse_1_len_max: maximum length of pulse with bit value 1, here: rest value - NETBOX_PAUSE_LEN, // pause_1_len_min: minimum length of pause with bit value 1, here: exact value - NETBOX_PAUSE_REST_LEN, // pause_1_len_max: maximum length of pause with bit value 1, here: rest value - NETBOX_PULSE_LEN, // pulse_0_len_min: minimum length of pulse with bit value 0, here: exact value - NETBOX_PULSE_REST_LEN, // pulse_0_len_max: maximum length of pulse with bit value 0, here: rest value - NETBOX_PAUSE_LEN, // pause_0_len_min: minimum length of pause with bit value 0, here: exact value - NETBOX_PAUSE_REST_LEN, // pause_0_len_max: maximum length of pause with bit value 0, here: rest value - NETBOX_ADDRESS_OFFSET, // address_offset: address offset - NETBOX_ADDRESS_OFFSET + NETBOX_ADDRESS_LEN, // address_end: end of address - NETBOX_COMMAND_OFFSET, // command_offset: command offset - NETBOX_COMMAND_OFFSET + NETBOX_COMMAND_LEN, // command_end: end of command - NETBOX_COMPLETE_DATA_LEN, // complete_len: complete length of frame - NETBOX_STOP_BIT, // stop_bit: flag: frame has stop bit - NETBOX_LSB, // lsb_first: flag: LSB first - NETBOX_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER lego_param = -{ - IRMP_LEGO_PROTOCOL, // protocol: ir protocol - LEGO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - LEGO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - LEGO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - LEGO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - LEGO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - LEGO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - LEGO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - LEGO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - LEGO_ADDRESS_OFFSET, // address_offset: address offset - LEGO_ADDRESS_OFFSET + LEGO_ADDRESS_LEN, // address_end: end of address - LEGO_COMMAND_OFFSET, // command_offset: command offset - LEGO_COMMAND_OFFSET + LEGO_COMMAND_LEN, // command_end: end of command - LEGO_COMPLETE_DATA_LEN, // complete_len: complete length of frame - LEGO_STOP_BIT, // stop_bit: flag: frame has stop bit - LEGO_LSB, // lsb_first: flag: LSB first - LEGO_FLAGS // flags: some flags -}; - -#endif - -#if IRMP_SUPPORT_THOMSON_PROTOCOL == 1 - -static const PROGMEM IRMP_PARAMETER thomson_param = -{ - IRMP_THOMSON_PROTOCOL, // protocol: ir protocol - THOMSON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 - THOMSON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 - THOMSON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 - THOMSON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 - THOMSON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 - THOMSON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 - THOMSON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 - THOMSON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 - THOMSON_ADDRESS_OFFSET, // address_offset: address offset - THOMSON_ADDRESS_OFFSET + THOMSON_ADDRESS_LEN, // address_end: end of address - THOMSON_COMMAND_OFFSET, // command_offset: command offset - THOMSON_COMMAND_OFFSET + THOMSON_COMMAND_LEN, // command_end: end of command - THOMSON_COMPLETE_DATA_LEN, // complete_len: complete length of frame - THOMSON_STOP_BIT, // stop_bit: flag: frame has stop bit - THOMSON_LSB, // lsb_first: flag: LSB first - THOMSON_FLAGS // flags: some flags -}; - -#endif - -static uint8_t irmp_bit; // current bit position -static IRMP_PARAMETER irmp_param; - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) -static IRMP_PARAMETER irmp_param2; -#endif - -static volatile uint8_t irmp_ir_detected; -static volatile uint8_t irmp_protocol; -static volatile uint16_t irmp_address; -static volatile uint16_t irmp_command; -static volatile uint16_t irmp_id; // only used for SAMSUNG protocol -static volatile uint8_t irmp_flags; -// static volatile uint8_t irmp_busy_flag; - -#ifdef ANALYZE -static uint8_t IRMP_PIN; -#endif - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Initialize IRMP decoder - * @details Configures IRMP input pin - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#ifndef ANALYZE -void -irmp_init (void) -{ -#ifndef ARDUINO -#if !defined(PIC_CCS_COMPILER) && !defined(PIC_C18) // only AVR - IRMP_PORT &= ~(1<> 8) == (~irmp_command & 0x00FF)) - { - irmp_command &= 0xff; - irmp_command |= irmp_id << 8; - rtc = TRUE; - } - break; -#endif -#if IRMP_SUPPORT_NEC_PROTOCOL == 1 - case IRMP_NEC_PROTOCOL: - if ((irmp_command >> 8) == (~irmp_command & 0x00FF)) - { - irmp_command &= 0xff; - rtc = TRUE; - } - else if (irmp_address == 0x87EE) - { - ANALYZE_PRINTF ("Switching to APPLE protocol\n"); - irmp_protocol = IRMP_APPLE_PROTOCOL; - irmp_address = (irmp_command & 0xFF00) >> 8; - irmp_command &= 0x00FF; - rtc = TRUE; - } - break; -#endif -#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 - case IRMP_SIEMENS_PROTOCOL: - case IRMP_RUWIDO_PROTOCOL: - if (((irmp_command >> 1) & 0x0001) == (~irmp_command & 0x0001)) - { - irmp_command >>= 1; - rtc = TRUE; - } - break; -#endif -#if IRMP_SUPPORT_GRUNDIG2_PROTOCOL == 1 - case IRMP_GRUNDIG2_PROTOCOL: - if (irmp_command & 0x0001) - { - irmp_command >>= 1; - rtc = TRUE; - } - break; -#endif -#if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1 - case IRMP_KATHREIN_PROTOCOL: - if (irmp_command != 0x0000) - { - rtc = TRUE; - } - break; -#endif -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 - case IRMP_RC5_PROTOCOL: - irmp_address &= ~0x20; // clear toggle bit - rtc = TRUE; - break; -#endif -#if IRMP_SUPPORT_IR60_PROTOCOL == 1 - case IRMP_IR60_PROTOCOL: - if (irmp_command != 0x007d) // 0x007d (== 62<<1 + 1) is start instruction frame - { - rtc = TRUE; - } - break; -#endif -#if IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - case IRMP_RCCAR_PROTOCOL: - // frame in irmp_data: - // Bit 12 11 10 9 8 7 6 5 4 3 2 1 0 - // V D7 D6 D5 D4 D3 D2 D1 D0 A1 A0 C1 C0 // 10 9 8 7 6 5 4 3 2 1 0 - irmp_address = (irmp_command & 0x000C) >> 2; // addr: 0 0 0 0 0 0 0 0 0 A1 A0 - irmp_command = ((irmp_command & 0x1000) >> 2) | // V-Bit: V 0 0 0 0 0 0 0 0 0 0 - ((irmp_command & 0x0003) << 8) | // C-Bits: 0 C1 C0 0 0 0 0 0 0 0 0 - ((irmp_command & 0x0FF0) >> 4); // D-Bits: D7 D6 D5 D4 D3 D2 D1 D0 - rtc = TRUE; // Summe: V C1 C0 D7 D6 D5 D4 D3 D2 D1 D0 - break; -#endif - -#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 // squeeze code to 8 bit, upper bit indicates release-key - case IRMP_NETBOX_PROTOCOL: - if (irmp_command & 0x1000) // last bit set? - { - if ((irmp_command & 0x1f) == 0x15) // key pressed: 101 01 (LSB) - { - irmp_command >>= 5; - irmp_command &= 0x7F; - rtc = TRUE; - } - else if ((irmp_command & 0x1f) == 0x10) // key released: 000 01 (LSB) - { - irmp_command >>= 5; - irmp_command |= 0x80; - rtc = TRUE; - } - else - { - ANALYZE_PRINTF("error NETBOX: bit6/7 must be 0/1\n"); - } - } - else - { - ANALYZE_PRINTF("error NETBOX: last bit not set\n"); - } - break; -#endif -#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 - case IRMP_LEGO_PROTOCOL: - { - uint8_t crc = 0x0F ^ ((irmp_command & 0xF000) >> 12) ^ ((irmp_command & 0x0F00) >> 8) ^ ((irmp_command & 0x00F0) >> 4); - - if ((irmp_command & 0x000F) == crc) - { - irmp_command >>= 4; - rtc = TRUE; - } - else - { - ANALYZE_PRINTF ("CRC error in LEGO protocol\n"); - rtc = TRUE; - } - break; - } -#endif - default: - rtc = TRUE; - } - - if (rtc) - { - irmp_data_p->protocol = irmp_protocol; - irmp_data_p->address = irmp_address; - irmp_data_p->command = irmp_command; - irmp_data_p->flags = irmp_flags; - irmp_command = 0; - irmp_address = 0; - irmp_flags = 0; - } - - irmp_ir_detected = FALSE; - } - - return rtc; -} - -// uint8_t -// irmp_is_busy (void) -// { -// return irmp_busy_flag; -// } - -#if IRMP_USE_CALLBACK == 1 -void -irmp_set_callback_ptr (void (*cb)(uint8_t)) -{ - irmp_callback_ptr = cb; -} -#endif // IRMP_USE_CALLBACK == 1 - -// these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR() -static uint16_t irmp_tmp_address; // ir address -static uint16_t irmp_tmp_command; // ir command - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1 -static uint16_t irmp_tmp_address2; // ir address -static uint16_t irmp_tmp_command2; // ir command -#endif - -#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 -static uint16_t irmp_tmp_id; // ir id (only SAMSUNG) -#endif -#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 -static uint8_t xor_check[6]; // check kaseikyo "parity" bits -static uint8_t genre2; // save genre2 bits here, later copied to MSB in flags -#endif - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * store bit - * @details store bit in temp address or temp command - * @param value to store: 0 or 1 - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -// verhindert, dass irmp_store_bit() inline compiliert wird: -// static void irmp_store_bit (uint8_t) __attribute__ ((noinline)); - -static void -irmp_store_bit (uint8_t value) -{ -#if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 - if (irmp_bit == 0 && irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL) - { - first_bit = value; - } - else -#endif - - if (irmp_bit >= irmp_param.address_offset && irmp_bit < irmp_param.address_end) - { - if (irmp_param.lsb_first) - { - irmp_tmp_address |= (((uint16_t) (value)) << (irmp_bit - irmp_param.address_offset)); // CV wants cast - } - else - { - irmp_tmp_address <<= 1; - irmp_tmp_address |= value; - } - } - else if (irmp_bit >= irmp_param.command_offset && irmp_bit < irmp_param.command_end) - { - if (irmp_param.lsb_first) - { - irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast - } - else - { - irmp_tmp_command <<= 1; - irmp_tmp_command |= value; - } - } - -#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 - else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit >= 13 && irmp_bit < 26) - { - irmp_tmp_address2 |= (((uint16_t) (value)) << (irmp_bit - 13)); // CV wants cast - } -#endif - -#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 - else if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit >= SAMSUNG_ID_OFFSET && irmp_bit < SAMSUNG_ID_OFFSET + SAMSUNG_ID_LEN) - { - irmp_tmp_id |= (((uint16_t) (value)) << (irmp_bit - SAMSUNG_ID_OFFSET)); // store with LSB first - } -#endif - -#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 - else if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL) - { - if (irmp_bit >= 20 && irmp_bit < 24) - { - irmp_tmp_command |= (((uint16_t) (value)) << (irmp_bit - 8)); // store 4 system bits (genre 1) in upper nibble with LSB first - } - else if (irmp_bit >= 24 && irmp_bit < 28) - { - genre2 |= (((uint8_t) (value)) << (irmp_bit - 20)); // store 4 system bits (genre 2) in upper nibble with LSB first - } - - if (irmp_bit < KASEIKYO_COMPLETE_DATA_LEN) - { - if (value) - { - xor_check[irmp_bit / 8] |= 1 << (irmp_bit % 8); - } - else - { - xor_check[irmp_bit / 8] &= ~(1 << (irmp_bit % 8)); - } - } - } -#endif - - irmp_bit++; -} - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * store bit - * @details store bit in temp address or temp command - * @param value to store: 0 or 1 - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) -static void -irmp_store_bit2 (uint8_t value) -{ - uint8_t irmp_bit2; - - if (irmp_param.protocol) - { - irmp_bit2 = irmp_bit - 2; - } - else - { - irmp_bit2 = irmp_bit - 1; - } - - if (irmp_bit2 >= irmp_param2.address_offset && irmp_bit2 < irmp_param2.address_end) - { - irmp_tmp_address2 |= (((uint16_t) (value)) << (irmp_bit2 - irmp_param2.address_offset)); // CV wants cast - } - else if (irmp_bit2 >= irmp_param2.command_offset && irmp_bit2 < irmp_param2.command_end) - { - irmp_tmp_command2 |= (((uint16_t) (value)) << (irmp_bit2 - irmp_param2.command_offset)); // CV wants cast - } -} -#endif // IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * ISR routine - * @details ISR routine, called 10000 times per second - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -uint8_t -irmp_ISR (uint8_t x42) -{ - static uint8_t irmp_start_bit_detected; // flag: start bit detected - static uint8_t wait_for_space; // flag: wait for data bit space - static uint8_t wait_for_start_space; // flag: wait for start bit space - static uint8_t irmp_pulse_time; // count bit time for pulse - static PAUSE_LEN irmp_pause_time; // count bit time for pause - static uint16_t last_irmp_address = 0xFFFF; // save last irmp address to recognize key repetition - static uint16_t last_irmp_command = 0xFFFF; // save last irmp command to recognize key repetition - static uint16_t repetition_len; // SIRCS repeats frame 2-5 times with 45 ms pause - static uint8_t repetition_frame_number; -#if IRMP_SUPPORT_DENON_PROTOCOL == 1 - static uint16_t last_irmp_denon_command; // save last irmp command to recognize DENON frame repetition -#endif -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 - static uint8_t rc5_cmd_bit6; // bit 6 of RC5 command is the inverted 2nd start bit -#endif -#if IRMP_SUPPORT_MANCHESTER == 1 - static PAUSE_LEN last_pause; // last pause value -#endif -#if IRMP_SUPPORT_MANCHESTER == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 - static uint8_t last_value; // last bit value -#endif - uint8_t irmp_input; // input value - -#ifdef ANALYZE - time_counter++; -#endif - - irmp_input = input(x42); - -#if IRMP_USE_CALLBACK == 1 - if (irmp_callback_ptr) - { - static uint8_t last_inverted_input; - - if (last_inverted_input != !irmp_input) - { - (*irmp_callback_ptr) (! irmp_input); - last_inverted_input = !irmp_input; - } - } -#endif // IRMP_USE_CALLBACK == 1 - - irmp_log(irmp_input); // log ir signal, if IRMP_LOGGING defined - - if (! irmp_ir_detected) // ir code already detected? - { // no... - if (! irmp_start_bit_detected) // start bit detected? - { // no... - if (! irmp_input) // receiving burst? - { // yes... -// irmp_busy_flag = TRUE; -#ifdef ANALYZE - if (! irmp_pulse_time) - { - ANALYZE_PRINTF("%8.3fms [starting pulse]\n", (double) (time_counter * 1000) / F_INTERRUPTS); - } -#endif - irmp_pulse_time++; // increment counter - } - else - { // no... - if (irmp_pulse_time) // it's dark.... - { // set flags for counting the time of darkness... - irmp_start_bit_detected = 1; - wait_for_start_space = 1; - wait_for_space = 0; - irmp_tmp_command = 0; - irmp_tmp_address = 0; -#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 - genre2 = 0; -#endif - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1 - irmp_tmp_command2 = 0; - irmp_tmp_address2 = 0; -#endif - - irmp_bit = 0xff; - irmp_pause_time = 1; // 1st pause: set to 1, not to 0! -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 - rc5_cmd_bit6 = 0; // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame! -#endif - } - else - { - if (repetition_len < 0xFFFF) // avoid overflow of counter - { - repetition_len++; - } - } - } - } - else - { - if (wait_for_start_space) // we have received start bit... - { // ...and are counting the time of darkness - if (irmp_input) // still dark? - { // yes - irmp_pause_time++; // increment counter - -#if IRMP_SUPPORT_NIKON_PROTOCOL == 1 - if (((irmp_pulse_time < NIKON_START_BIT_PULSE_LEN_MIN || irmp_pulse_time > NIKON_START_BIT_PULSE_LEN_MAX) && irmp_pause_time > IRMP_TIMEOUT_LEN) || - irmp_pause_time > IRMP_TIMEOUT_NIKON_LEN) -#else - if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout? -#endif - { // yes... -#if IRMP_SUPPORT_JVC_PROTOCOL == 1 - if (irmp_protocol == IRMP_JVC_PROTOCOL) // don't show eror if JVC protocol, irmp_pulse_time has been set below! - { - ; - } - else -#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 - { - ANALYZE_PRINTF ("%8.3fms error 1: pause after start bit pulse %d too long: %d\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time); - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); - } -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // reset flags, let's wait for another start bit - irmp_pulse_time = 0; - irmp_pause_time = 0; - } - } - else - { // receiving first data pulse! - IRMP_PARAMETER * irmp_param_p = (IRMP_PARAMETER *) 0; - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) - irmp_param2.protocol = 0; -#endif - - ANALYZE_PRINTF ("%8.3fms [start-bit: pulse = %2d, pause = %2d]\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time); - -#if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 - if (irmp_pulse_time >= SIRCS_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIRCS_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= SIRCS_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIRCS_START_BIT_PAUSE_LEN_MAX) - { // it's SIRCS - ANALYZE_PRINTF ("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX, - SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) (IRMP_PARAMETER *) &sircs_param; - } - else -#endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1 - -#if IRMP_SUPPORT_JVC_PROTOCOL == 1 - if (irmp_protocol == IRMP_JVC_PROTOCOL && // last protocol was JVC, awaiting repeat frame - irmp_pulse_time >= JVC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= JVC_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= JVC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= JVC_REPEAT_START_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("protocol = NEC or JVC (type 1) repeat frame, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - JVC_START_BIT_PULSE_LEN_MIN, JVC_START_BIT_PULSE_LEN_MAX, - JVC_REPEAT_START_BIT_PAUSE_LEN_MIN, JVC_REPEAT_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &nec_param; - } - else -#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 - -#if IRMP_SUPPORT_NEC_PROTOCOL == 1 - if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX) - { -#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 - ANALYZE_PRINTF ("protocol = NEC42, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, - NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &nec42_param; -#else - ANALYZE_PRINTF ("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, - NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &nec_param; -#endif - - } - else if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX) - { // it's NEC -#if IRMP_SUPPORT_JVC_PROTOCOL == 1 - if (irmp_protocol == IRMP_JVC_PROTOCOL) // last protocol was JVC, awaiting repeat frame - { // some jvc remote controls use nec repetition frame for jvc repetition frame - ANALYZE_PRINTF ("protocol = JVC repeat frame type 2, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, - NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &nec_param; - } - else -#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 - { - ANALYZE_PRINTF ("protocol = NEC (repetition frame), start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, - NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX); - - irmp_param_p = (IRMP_PARAMETER *) &nec_rep_param; - } - } - else - -#if IRMP_SUPPORT_JVC_PROTOCOL == 1 - if (irmp_protocol == IRMP_JVC_PROTOCOL && // last protocol was JVC, awaiting repeat frame - irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= NEC_0_PAUSE_LEN_MIN && irmp_pause_time <= NEC_0_PAUSE_LEN_MAX) - { // it's JVC repetition type 3 - ANALYZE_PRINTF ("protocol = JVC repeat frame type 3, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, - NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &nec_param; - } - else -#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 - -#endif // IRMP_SUPPORT_NEC_PROTOCOL == 1 - -#if IRMP_SUPPORT_NIKON_PROTOCOL == 1 - if (irmp_pulse_time >= NIKON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NIKON_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= NIKON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NIKON_START_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("protocol = NIKON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX, - NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &nikon_param; - } - else -#endif // IRMP_SUPPORT_NIKON_PROTOCOL == 1 - -#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 - if (irmp_pulse_time >= SAMSUNG_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX) - { // it's SAMSUNG - ANALYZE_PRINTF ("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX, - SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &samsung_param; - } - else -#endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 - -#if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1 - if (irmp_pulse_time >= MATSUSHITA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MATSUSHITA_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= MATSUSHITA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MATSUSHITA_START_BIT_PAUSE_LEN_MAX) - { // it's MATSUSHITA - ANALYZE_PRINTF ("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX, - MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &matsushita_param; - } - else -#endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1 - -#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 - if (irmp_pulse_time >= KASEIKYO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KASEIKYO_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= KASEIKYO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KASEIKYO_START_BIT_PAUSE_LEN_MAX) - { // it's KASEIKYO - ANALYZE_PRINTF ("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX, - KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &kaseikyo_param; - } - else -#endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 - -#if IRMP_SUPPORT_RECS80_PROTOCOL == 1 - if (irmp_pulse_time >= RECS80_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= RECS80_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80_START_BIT_PAUSE_LEN_MAX) - { // it's RECS80 - ANALYZE_PRINTF ("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX, - RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &recs80_param; - } - else -#endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1 - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 - if (((irmp_pulse_time >= RC5_START_BIT_LEN_MIN && irmp_pulse_time <= RC5_START_BIT_LEN_MAX) || - (irmp_pulse_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX)) && - ((irmp_pause_time >= RC5_START_BIT_LEN_MIN && irmp_pause_time <= RC5_START_BIT_LEN_MAX) || - (irmp_pause_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX))) - { // it's RC5 -#if IRMP_SUPPORT_FDC_PROTOCOL == 1 - if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("protocol = RC5 or FDC\n"); - ANALYZE_PRINTF ("FDC start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, - FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX); - ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, - RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX); - memcpy_P (&irmp_param2, &fdc_param, sizeof (IRMP_PARAMETER)); - } - else -#endif // IRMP_SUPPORT_FDC_PROTOCOL == 1 - -#if IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("protocol = RC5 or RCCAR\n"); - ANALYZE_PRINTF ("RCCAR start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, - RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX); - ANALYZE_PRINTF ("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, - RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX); - memcpy_P (&irmp_param2, &rccar_param, sizeof (IRMP_PARAMETER)); - } - else -#endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - { - ANALYZE_PRINTF ("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or pulse: %3d - %3d, pause: %3d - %3d\n", - RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, - 2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX, - RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, - 2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX); - } - - irmp_param_p = (IRMP_PARAMETER *) &rc5_param; - last_pause = irmp_pause_time; - - if ((irmp_pulse_time > RC5_START_BIT_LEN_MAX && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX) || - (irmp_pause_time > RC5_START_BIT_LEN_MAX && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX)) - { - last_value = 0; - rc5_cmd_bit6 = 1<<6; - } - else - { - last_value = 1; - } - } - else -#endif // IRMP_SUPPORT_RC5_PROTOCOL == 1 - -#if IRMP_SUPPORT_DENON_PROTOCOL == 1 - if ( (irmp_pulse_time >= DENON_PULSE_LEN_MIN && irmp_pulse_time <= DENON_PULSE_LEN_MAX) && - ((irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) || - (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX))) - { // it's DENON - ANALYZE_PRINTF ("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n", - DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, - DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX, - DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &denon_param; - } - else -#endif // IRMP_SUPPORT_DENON_PROTOCOL == 1 - -#if IRMP_SUPPORT_THOMSON_PROTOCOL == 1 - if ( (irmp_pulse_time >= THOMSON_PULSE_LEN_MIN && irmp_pulse_time <= THOMSON_PULSE_LEN_MAX) && - ((irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX) || - (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX))) - { // it's THOMSON - ANALYZE_PRINTF ("protocol = THOMSON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n", - THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, - THOMSON_1_PAUSE_LEN_MIN, THOMSON_1_PAUSE_LEN_MAX, - THOMSON_0_PAUSE_LEN_MIN, THOMSON_0_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &thomson_param; - } - else -#endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1 - -#if IRMP_SUPPORT_RC6_PROTOCOL == 1 - if (irmp_pulse_time >= RC6_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RC6_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= RC6_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RC6_START_BIT_PAUSE_LEN_MAX) - { // it's RC6 - ANALYZE_PRINTF ("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX, - RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &rc6_param; - last_pause = 0; - last_value = 1; - } - else -#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 - -#if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1 - if (irmp_pulse_time >= RECS80EXT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80EXT_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= RECS80EXT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80EXT_START_BIT_PAUSE_LEN_MAX) - { // it's RECS80EXT - ANALYZE_PRINTF ("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX, - RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &recs80ext_param; - } - else -#endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1 - -#if IRMP_SUPPORT_NUBERT_PROTOCOL == 1 - if (irmp_pulse_time >= NUBERT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NUBERT_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= NUBERT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NUBERT_START_BIT_PAUSE_LEN_MAX) - { // it's NUBERT - ANALYZE_PRINTF ("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX, - NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &nubert_param; - } - else -#endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1 - -#if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 - if (irmp_pulse_time >= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX && - irmp_pause_time >= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX) - { // it's BANG_OLUFSEN - ANALYZE_PRINTF ("protocol = BANG_OLUFSEN\n"); - ANALYZE_PRINTF ("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n", - BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX, - BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX); - ANALYZE_PRINTF ("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n", - BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX, - BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX); - ANALYZE_PRINTF ("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n", - BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX, - BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX); - ANALYZE_PRINTF ("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n", - BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX, - BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &bang_olufsen_param; - last_value = 0; - } - else -#endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 - -#if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 - if (irmp_pulse_time >= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN && irmp_pulse_time <= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX && - irmp_pause_time >= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX) - { // it's GRUNDIG - ANALYZE_PRINTF ("protocol = GRUNDIG, pre bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX, - GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &grundig_param; - last_pause = irmp_pause_time; - last_value = 1; - } - else -#endif // IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 - -#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 - if (((irmp_pulse_time >= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX) || - (irmp_pulse_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX)) && - ((irmp_pause_time >= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX) || - (irmp_pause_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX))) - { // it's RUWIDO or SIEMENS - ANALYZE_PRINTF ("protocol = RUWIDO, start bit timings: pulse: %3d - %3d or %3d - %3d, pause: %3d - %3d or %3d - %3d\n", - SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX, - 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX, - SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX, - 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &ruwido_param; - last_pause = irmp_pause_time; - last_value = 1; - } - else -#endif // IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 - -#if IRMP_SUPPORT_GRUNDIG2_PROTOCOL == 1 - if ((irmp_pulse_time >= GRUNDIG2_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= GRUNDIG2_START_BIT_PULSE_LEN_MAX) && - (irmp_pause_time >= GRUNDIG2_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG2_START_BIT_PAUSE_LEN_MAX)) - { // it's GRUNDIG2 - ANALYZE_PRINTF ("protocol = GRUNDIG2, start bit timings: pulse: %3d - %3d or %3d - %3d, pause: %3d - %3d or %3d - %3d\n", - GRUNDIG2_START_BIT_PULSE_LEN_MIN, GRUNDIG2_START_BIT_PULSE_LEN_MAX, - 2 * GRUNDIG2_START_BIT_PULSE_LEN_MIN, 2 * GRUNDIG2_START_BIT_PULSE_LEN_MAX, - GRUNDIG2_START_BIT_PAUSE_LEN_MIN, GRUNDIG2_START_BIT_PAUSE_LEN_MAX, - 2 * GRUNDIG2_START_BIT_PAUSE_LEN_MIN, 2 * GRUNDIG2_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &grundig2_param; - last_pause = irmp_pause_time; - last_value = 1; - } - else -#endif // IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 - -#if IRMP_SUPPORT_FDC_PROTOCOL == 1 - if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("protocol = FDC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, - FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &fdc_param; - } - else -#endif // IRMP_SUPPORT_FDC_PROTOCOL == 1 - -#if IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("protocol = RCCAR, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, - RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &rccar_param; - } - else -#endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - -#if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1 - if (irmp_pulse_time >= KATHREIN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX) - { // it's KATHREIN - ANALYZE_PRINTF ("protocol = KATHREIN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - KATHREIN_START_BIT_PULSE_LEN_MIN, KATHREIN_START_BIT_PULSE_LEN_MAX, - KATHREIN_START_BIT_PAUSE_LEN_MIN, KATHREIN_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &kathrein_param; - } - else -#endif // IRMP_SUPPORT_KATHREIN_PROTOCOL == 1 - -#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 - if (irmp_pulse_time >= NETBOX_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NETBOX_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= NETBOX_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NETBOX_START_BIT_PAUSE_LEN_MAX) - { // it's NETBOX - ANALYZE_PRINTF ("protocol = NETBOX, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - NETBOX_START_BIT_PULSE_LEN_MIN, NETBOX_START_BIT_PULSE_LEN_MAX, - NETBOX_START_BIT_PAUSE_LEN_MIN, NETBOX_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &netbox_param; - } - else -#endif // IRMP_SUPPORT_NETBOX_PROTOCOL == 1 - -#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 - if (irmp_pulse_time >= LEGO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= LEGO_START_BIT_PULSE_LEN_MAX && - irmp_pause_time >= LEGO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= LEGO_START_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("protocol = LEGO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", - LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX, - LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX); - irmp_param_p = (IRMP_PARAMETER *) &lego_param; - } - else -#endif // IRMP_SUPPORT_LEGO_PROTOCOL == 1 - - { - ANALYZE_PRINTF ("protocol = UNKNOWN\n"); -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // wait for another start bit... - } - - if (irmp_start_bit_detected) - { - memcpy_P (&irmp_param, irmp_param_p, sizeof (IRMP_PARAMETER)); - -#ifdef ANALYZE - if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) - { - ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max); - ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max); - } - else - { - ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max, - 2 * irmp_param.pulse_1_len_min, 2 * irmp_param.pulse_1_len_max); - ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max, - 2 * irmp_param.pause_1_len_min, 2 * irmp_param.pause_1_len_max); - } - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) - if (irmp_param2.protocol) - { - ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param2.pulse_0_len_min, irmp_param2.pulse_0_len_max); - ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param2.pause_0_len_min, irmp_param2.pause_0_len_max); - ANALYZE_PRINTF ("pulse_1: %3d - %3d\n", irmp_param2.pulse_1_len_min, irmp_param2.pulse_1_len_max); - ANALYZE_PRINTF ("pause_1: %3d - %3d\n", irmp_param2.pause_1_len_min, irmp_param2.pause_1_len_max); - } -#endif - - -#if IRMP_SUPPORT_RC6_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_RC6_PROTOCOL) - { - ANALYZE_PRINTF ("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN, RC6_TOGGLE_BIT_LEN_MAX); - } -#endif - - if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) - { - ANALYZE_PRINTF ("pulse_0: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max); - ANALYZE_PRINTF ("pause_0: %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max); - } - else - { - ANALYZE_PRINTF ("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max, - 2 * irmp_param.pulse_0_len_min, 2 * irmp_param.pulse_0_len_max); - ANALYZE_PRINTF ("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max, - 2 * irmp_param.pause_0_len_min, 2 * irmp_param.pause_0_len_max); - } - -#if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL) - { - ANALYZE_PRINTF ("pulse_r: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max); - ANALYZE_PRINTF ("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN, BANG_OLUFSEN_R_PAUSE_LEN_MAX); - } -#endif - - ANALYZE_PRINTF ("command_offset: %2d\n", irmp_param.command_offset); - ANALYZE_PRINTF ("command_len: %3d\n", irmp_param.command_end - irmp_param.command_offset); - ANALYZE_PRINTF ("complete_len: %3d\n", irmp_param.complete_len); - ANALYZE_PRINTF ("stop_bit: %3d\n", irmp_param.stop_bit); -#endif // ANALYZE - } - - irmp_bit = 0; - -#if IRMP_SUPPORT_MANCHESTER == 1 - if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) && - irmp_param.protocol != IRMP_RUWIDO_PROTOCOL && // Manchester, but not RUWIDO - irmp_param.protocol != IRMP_RC6_PROTOCOL) // Manchester, but not RC6 - { - if (irmp_pause_time > irmp_param.pulse_1_len_max && irmp_pause_time <= 2 * irmp_param.pulse_1_len_max) - { - ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); - ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1'); - ANALYZE_NEWLINE (); - irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1); - } - else if (! last_value) // && irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max) - { - ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); - - ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0'); - ANALYZE_NEWLINE (); - irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0); - } - } - else -#endif // IRMP_SUPPORT_MANCHESTER == 1 - -#if IRMP_SUPPORT_SERIAL == 1 - if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) - { - ; // do nothing - } - else -#endif // IRMP_SUPPORT_SERIAL == 1 - - -#if IRMP_SUPPORT_DENON_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_DENON_PROTOCOL) - { - ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); - - if (irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) - { // pause timings correct for "1"? - ANALYZE_PUTCHAR ('1'); // yes, store 1 - ANALYZE_NEWLINE (); - irmp_store_bit (1); - } - else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX) - { // pause timings correct for "0"? - ANALYZE_PUTCHAR ('0'); // yes, store 0 - ANALYZE_NEWLINE (); - irmp_store_bit (0); - } - } - else -#endif // IRMP_SUPPORT_DENON_PROTOCOL == 1 -#if IRMP_SUPPORT_THOMSON_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_THOMSON_PROTOCOL) - { - ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); - - if (irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX) - { // pause timings correct for "1"? - ANALYZE_PUTCHAR ('1'); // yes, store 1 - ANALYZE_NEWLINE (); - irmp_store_bit (1); - } - else // if (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX) - { // pause timings correct for "0"? - ANALYZE_PUTCHAR ('0'); // yes, store 0 - ANALYZE_NEWLINE (); - irmp_store_bit (0); - } - } - else -#endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1 - { - ; // else do nothing - } - - irmp_pulse_time = 1; // set counter to 1, not 0 - irmp_pause_time = 0; - wait_for_start_space = 0; - } - } - else if (wait_for_space) // the data section.... - { // counting the time of darkness.... - uint8_t got_light = FALSE; - - if (irmp_input) // still dark? - { // yes... - if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 1) - { - if ( -#if IRMP_SUPPORT_MANCHESTER == 1 - (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) || -#endif -#if IRMP_SUPPORT_SERIAL == 1 - (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) || -#endif - (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max)) - { -#ifdef ANALYZE - if (! (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) - { - ANALYZE_PRINTF ("stop bit detected\n"); - } -#endif - irmp_param.stop_bit = 0; - } - else - { - ANALYZE_PRINTF ("error: stop bit timing wrong, irmp_bit = %d, irmp_pulse_time = %d, pulse_0_len_min = %d, pulse_0_len_max = %d\n", - irmp_bit, irmp_pulse_time, irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max); - -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // wait for another start bit... - irmp_pulse_time = 0; - irmp_pause_time = 0; - } - } - else - { - irmp_pause_time++; // increment counter - -#if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && // Sony has a variable number of bits: - irmp_pause_time > SIRCS_PAUSE_LEN_MAX && // minimum is 12 - irmp_bit >= 12 - 1) // pause too long? - { // yes, break and close this frame - irmp_param.complete_len = irmp_bit + 1; // set new complete length - got_light = TRUE; // this is a lie, but helps (generates stop bit) - irmp_tmp_address |= (irmp_bit - SIRCS_MINIMUM_DATA_LEN + 1) << 8; // new: store number of additional bits in upper byte of address! - irmp_param.command_end = irmp_param.command_offset + irmp_bit + 1; // correct command length - irmp_pause_time = SIRCS_PAUSE_LEN_MAX - 1; // correct pause length - } - else -#endif -#if IRMP_SUPPORT_SERIAL == 1 - // NETBOX generates no stop bit, here is the timeout condition: - if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) && irmp_param.protocol == IRMP_NETBOX_PROTOCOL && - irmp_pause_time >= NETBOX_PULSE_LEN * (NETBOX_COMPLETE_DATA_LEN - irmp_bit)) - { - got_light = TRUE; // this is a lie, but helps (generates stop bit) - } - else -#endif -#if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && !irmp_param.stop_bit) - { - if (irmp_pause_time > IR60_TIMEOUT_LEN && irmp_bit == 6) - { - ANALYZE_PRINTF ("Switching to IR60 protocol\n"); - got_light = TRUE; // this is a lie, but generates a stop bit ;-) - irmp_param.stop_bit = TRUE; // set flag - - irmp_param.protocol = IRMP_IR60_PROTOCOL; // change protocol - irmp_param.complete_len = IR60_COMPLETE_DATA_LEN; // correct complete len - irmp_param.address_offset = IR60_ADDRESS_OFFSET; - irmp_param.address_end = IR60_ADDRESS_OFFSET + IR60_ADDRESS_LEN; - irmp_param.command_offset = IR60_COMMAND_OFFSET; - irmp_param.command_end = IR60_COMMAND_OFFSET + IR60_COMMAND_LEN; - - irmp_tmp_command <<= 1; - irmp_tmp_command |= first_bit; - } - else if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN - 2) - { // special manchester decoder - irmp_param.complete_len = GRUNDIG_COMPLETE_DATA_LEN; // correct complete len - got_light = TRUE; // this is a lie, but generates a stop bit ;-) - irmp_param.stop_bit = TRUE; // set flag - } - else if (irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN) - { - ANALYZE_PRINTF ("Switching to NOKIA protocol\n"); - irmp_param.protocol = IRMP_NOKIA_PROTOCOL; // change protocol - irmp_param.address_offset = NOKIA_ADDRESS_OFFSET; - irmp_param.address_end = NOKIA_ADDRESS_OFFSET + NOKIA_ADDRESS_LEN; - irmp_param.command_offset = NOKIA_COMMAND_OFFSET; - irmp_param.command_end = NOKIA_COMMAND_OFFSET + NOKIA_COMMAND_LEN; - - if (irmp_tmp_command & 0x300) - { - irmp_tmp_address = (irmp_tmp_command >> 8); - irmp_tmp_command &= 0xFF; - } - } - } - else -#endif -#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_RUWIDO_PROTOCOL && !irmp_param.stop_bit) - { - if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= RUWIDO_COMPLETE_DATA_LEN - 2) - { // special manchester decoder - irmp_param.complete_len = RUWIDO_COMPLETE_DATA_LEN; // correct complete len - got_light = TRUE; // this is a lie, but generates a stop bit ;-) - irmp_param.stop_bit = TRUE; // set flag - } - else if (irmp_bit >= RUWIDO_COMPLETE_DATA_LEN) - { - ANALYZE_PRINTF ("Switching to SIEMENS protocol\n"); - irmp_param.protocol = IRMP_SIEMENS_PROTOCOL; // change protocol - irmp_param.address_offset = SIEMENS_ADDRESS_OFFSET; - irmp_param.address_end = SIEMENS_ADDRESS_OFFSET + SIEMENS_ADDRESS_LEN; - irmp_param.command_offset = SIEMENS_COMMAND_OFFSET; - irmp_param.command_end = SIEMENS_COMMAND_OFFSET + SIEMENS_COMMAND_LEN; - - // 76543210 - // RUWIDO: AAAAAAAAACCCCCCCp - // SIEMENS: AAAAAAAAAAACCCCCCCCCCp - irmp_tmp_address <<= 2; - irmp_tmp_address |= (irmp_tmp_command >> 6); - irmp_tmp_command &= 0x003F; - irmp_tmp_command <<= 4; - irmp_tmp_command |= last_value; - } - } - else -#endif -#if IRMP_SUPPORT_MANCHESTER == 1 - if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) && - irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= irmp_param.complete_len - 2 && !irmp_param.stop_bit) - { // special manchester decoder - got_light = TRUE; // this is a lie, but generates a stop bit ;-) - irmp_param.stop_bit = TRUE; // set flag - } - else -#endif // IRMP_SUPPORT_MANCHESTER == 1 - if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout? - { // yes... - if (irmp_bit == irmp_param.complete_len - 1 && irmp_param.stop_bit == 0) - { - irmp_bit++; - } -#if IRMP_SUPPORT_JVC_PROTOCOL == 1 - else if (irmp_param.protocol == IRMP_NEC_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17)) // it was a JVC stop bit - { - ANALYZE_PRINTF ("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit); - irmp_param.stop_bit = TRUE; // set flag - irmp_param.protocol = IRMP_JVC_PROTOCOL; // switch protocol - irmp_param.complete_len = irmp_bit; // patch length: 16 or 17 - irmp_tmp_command = (irmp_tmp_address >> 4); // set command: upper 12 bits are command bits - irmp_tmp_address = irmp_tmp_address & 0x000F; // lower 4 bits are address bits - irmp_start_bit_detected = 1; // tricky: don't wait for another start bit... - } -#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 - -#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 -#if IRMP_SUPPORT_NEC_PROTOCOL == 1 - else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit == 32) // it was a NEC stop bit - { - ANALYZE_PRINTF ("Switching to NEC protocol\n"); - irmp_param.stop_bit = TRUE; // set flag - irmp_param.protocol = IRMP_NEC_PROTOCOL; // switch protocol - irmp_param.complete_len = irmp_bit; // patch length: 16 or 17 - - // 0123456789ABC0123456789ABC0123456701234567 - // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc - // NEC: AAAAAAAAaaaaaaaaCCCCCCCCcccccccc - irmp_tmp_address |= (irmp_tmp_address2 & 0x0007) << 13; // fm 2012-02-13: 12 -> 13 - irmp_tmp_command = (irmp_tmp_address2 >> 3) | (irmp_tmp_command << 10); - } -#endif // IRMP_SUPPORT_NEC_PROTOCOL == 1 -#if IRMP_SUPPORT_JVC_PROTOCOL == 1 - else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17)) // it was a JVC stop bit - { - ANALYZE_PRINTF ("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit); - irmp_param.stop_bit = TRUE; // set flag - irmp_param.protocol = IRMP_JVC_PROTOCOL; // switch protocol - irmp_param.complete_len = irmp_bit; // patch length: 16 or 17 - - // 0123456789ABC0123456789ABC0123456701234567 - // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc - // JVC: AAAACCCCCCCCCCCC - irmp_tmp_command = (irmp_tmp_address >> 4) | (irmp_tmp_address2 << 9); // set command: upper 12 bits are command bits - irmp_tmp_address = irmp_tmp_address & 0x000F; // lower 4 bits are address bits - } -#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 -#endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1 - else - { - ANALYZE_PRINTF ("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit); - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); - -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // wait for another start bit... - irmp_pulse_time = 0; - irmp_pause_time = 0; - } - } - } - } - else - { // got light now! - got_light = TRUE; - } - - if (got_light) - { - ANALYZE_PRINTF ("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); - -#if IRMP_SUPPORT_MANCHESTER == 1 - if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) // Manchester - { -#if 1 - if (irmp_pulse_time > irmp_param.pulse_1_len_max /* && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max */) -#else // better, but some IR-RCs use asymmetric timings :-/ - if (irmp_pulse_time > irmp_param.pulse_1_len_max && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max && - irmp_pause_time <= 2 * irmp_param.pause_1_len_max) -#endif - { -#if IRMP_SUPPORT_RC6_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit - { - ANALYZE_PUTCHAR ('T'); - if (irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode 6A - { - irmp_store_bit (1); - last_value = 1; - } - else // RC6 mode 0 - { - irmp_store_bit (0); - last_value = 0; - } - ANALYZE_NEWLINE (); - } - else -#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 - { - ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1'); - irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1 ); - -#if IRMP_SUPPORT_RC6_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit - { - ANALYZE_PUTCHAR ('T'); - irmp_store_bit (1); - - if (irmp_pause_time > 2 * irmp_param.pause_1_len_max) - { - last_value = 0; - } - else - { - last_value = 1; - } - ANALYZE_NEWLINE (); - } - else -#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 - { - ANALYZE_PUTCHAR ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0'); - irmp_store_bit ((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0 ); -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) - if (! irmp_param2.protocol) -#endif - { - ANALYZE_NEWLINE (); - } - last_value = (irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0; - } - } - } - else if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max - /* && irmp_pause_time <= 2 * irmp_param.pause_1_len_max */) - { - uint8_t manchester_value; - - if (last_pause > irmp_param.pause_1_len_max && last_pause <= 2 * irmp_param.pause_1_len_max) - { - manchester_value = last_value ? 0 : 1; - last_value = manchester_value; - } - else - { - manchester_value = last_value; - } - - ANALYZE_PUTCHAR (manchester_value + '0'); - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) - if (! irmp_param2.protocol) -#endif - { - ANALYZE_NEWLINE (); - } - -#if IRMP_SUPPORT_RC6_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 1 && manchester_value == 1) // RC6 mode != 0 ??? - { - ANALYZE_PRINTF ("Switching to RC6A protocol\n"); - irmp_param.complete_len = RC6_COMPLETE_DATA_LEN_LONG; - irmp_param.address_offset = 5; - irmp_param.address_end = irmp_param.address_offset + 15; - irmp_param.command_offset = irmp_param.address_end + 1; // skip 1 system bit, changes like a toggle bit - irmp_param.command_end = irmp_param.command_offset + 16 - 1; - irmp_tmp_address = 0; - } -#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 - - irmp_store_bit (manchester_value); - } - else - { -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1 - if (irmp_param2.protocol == IRMP_FDC_PROTOCOL && - irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX && - ((irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX) || - (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX))) - { - ANALYZE_PUTCHAR ('?'); - irmp_param.protocol = 0; // switch to FDC, see below - } - else -#endif // IRMP_SUPPORT_FDC_PROTOCOL == 1 -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL && - irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX && - ((irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX) || - (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX))) - { - ANALYZE_PUTCHAR ('?'); - irmp_param.protocol = 0; // switch to RCCAR, see below - } - else -#endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - { - ANALYZE_PUTCHAR ('?'); - ANALYZE_NEWLINE (); - ANALYZE_PRINTF ("error 3 manchester: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // reset flags and wait for next start bit - irmp_pause_time = 0; - } - } - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1 - if (irmp_param2.protocol == IRMP_FDC_PROTOCOL && irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX) - { - if (irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF (" 1 (FDC)\n"); - irmp_store_bit2 (1); - } - else if (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF (" 0 (FDC)\n"); - irmp_store_bit2 (0); - } - - if (! irmp_param.protocol) - { - ANALYZE_PRINTF ("Switching to FDC protocol\n"); - memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER)); - irmp_param2.protocol = 0; - irmp_tmp_address = irmp_tmp_address2; - irmp_tmp_command = irmp_tmp_command2; - } - } -#endif // IRMP_SUPPORT_FDC_PROTOCOL == 1 -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL && irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX) - { - if (irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF (" 1 (RCCAR)\n"); - irmp_store_bit2 (1); - } - else if (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF (" 0 (RCCAR)\n"); - irmp_store_bit2 (0); - } - - if (! irmp_param.protocol) - { - ANALYZE_PRINTF ("Switching to RCCAR protocol\n"); - memcpy (&irmp_param, &irmp_param2, sizeof (IRMP_PARAMETER)); - irmp_param2.protocol = 0; - irmp_tmp_address = irmp_tmp_address2; - irmp_tmp_command = irmp_tmp_command2; - } - } -#endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1 - - last_pause = irmp_pause_time; - wait_for_space = 0; - } - else -#endif // IRMP_SUPPORT_MANCHESTER == 1 - -#if IRMP_SUPPORT_SERIAL == 1 - if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) - { - while (irmp_bit < irmp_param.complete_len && irmp_pulse_time > irmp_param.pulse_1_len_max) - { - ANALYZE_PUTCHAR ('1'); - irmp_store_bit (1); - - if (irmp_pulse_time >= irmp_param.pulse_1_len_min) - { - irmp_pulse_time -= irmp_param.pulse_1_len_min; - } - else - { - irmp_pulse_time = 0; - } - } - - while (irmp_bit < irmp_param.complete_len && irmp_pause_time > irmp_param.pause_1_len_max) - { - ANALYZE_PUTCHAR ('0'); - irmp_store_bit (0); - - if (irmp_pause_time >= irmp_param.pause_1_len_min) - { - irmp_pause_time -= irmp_param.pause_1_len_min; - } - else - { - irmp_pause_time = 0; - } - } - ANALYZE_NEWLINE (); - wait_for_space = 0; - } - else -#endif // IRMP_SUPPORT_SERIAL == 1 - -#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit == 16) // Samsung: 16th bit - { - if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX && - irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("SYNC\n"); - wait_for_space = 0; - irmp_tmp_id = 0; - irmp_bit++; - } - else if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX) - { - irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL; - irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET; - irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN; - irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN; - - if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX) - { - ANALYZE_PUTCHAR ('1'); - ANALYZE_NEWLINE (); - irmp_store_bit (1); - wait_for_space = 0; - } - else - { - ANALYZE_PUTCHAR ('0'); - ANALYZE_NEWLINE (); - irmp_store_bit (0); - wait_for_space = 0; - } - - ANALYZE_PRINTF ("Switching to SAMSUNG32 protocol\n"); - } - else - { // timing incorrect! - ANALYZE_PRINTF ("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // reset flags and wait for next start bit - irmp_pause_time = 0; - } - } - else -#endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL - -#if IRMP_SUPPORT_NEC16_PROTOCOL -#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && -#else // IRMP_SUPPORT_NEC_PROTOCOL instead - if (irmp_param.protocol == IRMP_NEC_PROTOCOL && -#endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1 - irmp_bit == 8 && irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("Switching to NEC16 protocol\n"); - irmp_param.protocol = IRMP_NEC16_PROTOCOL; - irmp_param.address_offset = NEC16_ADDRESS_OFFSET; - irmp_param.address_end = NEC16_ADDRESS_OFFSET + NEC16_ADDRESS_LEN; - irmp_param.command_offset = NEC16_COMMAND_OFFSET; - irmp_param.command_end = NEC16_COMMAND_OFFSET + NEC16_COMMAND_LEN; - irmp_param.complete_len = NEC16_COMPLETE_DATA_LEN; - wait_for_space = 0; - } - else -#endif // IRMP_SUPPORT_NEC16_PROTOCOL - -#if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL) - { - if (irmp_pulse_time >= BANG_OLUFSEN_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_PULSE_LEN_MAX) - { - if (irmp_bit == 1) // Bang & Olufsen: 3rd bit - { - if (irmp_pause_time >= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("3rd start bit\n"); - wait_for_space = 0; - irmp_bit++; - } - else - { // timing incorrect! - ANALYZE_PRINTF ("error 3a B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // reset flags and wait for next start bit - irmp_pause_time = 0; - } - } - else if (irmp_bit == 19) // Bang & Olufsen: trailer bit - { - if (irmp_pause_time >= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("trailer bit\n"); - wait_for_space = 0; - irmp_bit++; - } - else - { // timing incorrect! - ANALYZE_PRINTF ("error 3b B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // reset flags and wait for next start bit - irmp_pause_time = 0; - } - } - else - { - if (irmp_pause_time >= BANG_OLUFSEN_1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_1_PAUSE_LEN_MAX) - { // pulse & pause timings correct for "1"? - ANALYZE_PUTCHAR ('1'); - ANALYZE_NEWLINE (); - irmp_store_bit (1); - last_value = 1; - wait_for_space = 0; - } - else if (irmp_pause_time >= BANG_OLUFSEN_0_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_0_PAUSE_LEN_MAX) - { // pulse & pause timings correct for "0"? - ANALYZE_PUTCHAR ('0'); - ANALYZE_NEWLINE (); - irmp_store_bit (0); - last_value = 0; - wait_for_space = 0; - } - else if (irmp_pause_time >= BANG_OLUFSEN_R_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_R_PAUSE_LEN_MAX) - { - ANALYZE_PUTCHAR (last_value + '0'); - ANALYZE_NEWLINE (); - irmp_store_bit (last_value); - wait_for_space = 0; - } - else - { // timing incorrect! - ANALYZE_PRINTF ("error 3c B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // reset flags and wait for next start bit - irmp_pause_time = 0; - } - } - } - else - { // timing incorrect! - ANALYZE_PRINTF ("error 3d B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // reset flags and wait for next start bit - irmp_pause_time = 0; - } - } - else -#endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL - - if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max && - irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max) - { // pulse & pause timings correct for "1"? - ANALYZE_PUTCHAR ('1'); - ANALYZE_NEWLINE (); - irmp_store_bit (1); - wait_for_space = 0; - } - else if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max && - irmp_pause_time >= irmp_param.pause_0_len_min && irmp_pause_time <= irmp_param.pause_0_len_max) - { // pulse & pause timings correct for "0"? - ANALYZE_PUTCHAR ('0'); - ANALYZE_NEWLINE (); - irmp_store_bit (0); - wait_for_space = 0; - } - else -#if IRMP_SUPPORT_KATHREIN_PROTOCOL - - if (irmp_param.protocol == IRMP_KATHREIN_PROTOCOL && - irmp_pulse_time >= KATHREIN_1_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_1_PULSE_LEN_MAX && - (((irmp_bit == 8 || irmp_bit == 6) && - irmp_pause_time >= KATHREIN_SYNC_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_SYNC_BIT_PAUSE_LEN_MAX) || - (irmp_bit == 12 && - irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX))) - - { - if (irmp_bit == 8) - { - irmp_bit++; - ANALYZE_PUTCHAR ('S'); - ANALYZE_NEWLINE (); - irmp_tmp_command <<= 1; - } - else - { - ANALYZE_PUTCHAR ('S'); - ANALYZE_NEWLINE (); - irmp_store_bit (1); - } - wait_for_space = 0; - } - else -#endif // IRMP_SUPPORT_KATHREIN_PROTOCOL - { // timing incorrect! - ANALYZE_PRINTF ("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // reset flags and wait for next start bit - irmp_pause_time = 0; - } - - irmp_pulse_time = 1; // set counter to 1, not 0 - } - } - else - { // counting the pulse length ... - if (! irmp_input) // still light? - { // yes... - irmp_pulse_time++; // increment counter - } - else - { // now it's dark! - wait_for_space = 1; // let's count the time (see above) - irmp_pause_time = 1; // set pause counter to 1, not 0 - } - } - - if (irmp_start_bit_detected && irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 0) // enough bits received? - { - if (last_irmp_command == irmp_tmp_command && repetition_len < AUTO_FRAME_REPETITION_LEN) - { - repetition_frame_number++; - } - else - { - repetition_frame_number = 0; - } - -#if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 - // if SIRCS protocol and the code will be repeated within 50 ms, we will ignore 2nd and 3rd repetition frame - if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && (repetition_frame_number == 1 || repetition_frame_number == 2)) - { - ANALYZE_PRINTF ("code skipped: SIRCS auto repetition frame #%d, counter = %d, auto repetition len = %d\n", - repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); - repetition_len = 0; - } - else -#endif - -#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 - // if KASEIKYO protocol and the code will be repeated within 50 ms, we will ignore 2nd repetition frame - if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && repetition_frame_number == 1) - { - ANALYZE_PRINTF ("code skipped: KASEIKYO auto repetition frame #%d, counter = %d, auto repetition len = %d\n", - repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); - repetition_len = 0; - } - else -#endif - -#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 - // if SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame - if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01)) - { - ANALYZE_PRINTF ("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n", - repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); - repetition_len = 0; - } - else -#endif - -#if IRMP_SUPPORT_NUBERT_PROTOCOL == 1 - // if NUBERT protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame - if (irmp_param.protocol == IRMP_NUBERT_PROTOCOL && (repetition_frame_number & 0x01)) - { - ANALYZE_PRINTF ("code skipped: NUBERT auto repetition frame #%d, counter = %d, auto repetition len = %d\n", - repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); - repetition_len = 0; - } - else -#endif - - { - ANALYZE_PRINTF ("%8.3fms code detected, length = %d\n", (double) (time_counter * 1000) / F_INTERRUPTS, irmp_bit); - irmp_ir_detected = TRUE; - -#if IRMP_SUPPORT_DENON_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_DENON_PROTOCOL) - { // check for repetition frame - if ((~irmp_tmp_command & 0x3FF) == last_irmp_denon_command) // command bits must be inverted - { - irmp_tmp_command = last_irmp_denon_command; // use command received before! - - irmp_protocol = irmp_param.protocol; // store protocol - irmp_address = irmp_tmp_address; // store address - irmp_command = irmp_tmp_command ; // store command - } - else - { - ANALYZE_PRINTF ("waiting for inverted command repetition\n"); - irmp_ir_detected = FALSE; - last_irmp_denon_command = irmp_tmp_command; - } - } - else -#endif // IRMP_SUPPORT_DENON_PROTOCOL - -#if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && irmp_tmp_command == 0x01ff) - { // Grundig start frame? - ANALYZE_PRINTF ("Detected GRUNDIG start frame, ignoring it\n"); - irmp_ir_detected = FALSE; - } - else -#endif // IRMP_SUPPORT_GRUNDIG_PROTOCOL - -#if IRMP_SUPPORT_NOKIA_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_NOKIA_PROTOCOL && irmp_tmp_address == 0x00ff && irmp_tmp_command == 0x00fe) - { // Nokia start frame? - ANALYZE_PRINTF ("Detected NOKIA start frame, ignoring it\n"); - irmp_ir_detected = FALSE; - } - else -#endif // IRMP_SUPPORT_NOKIA_PROTOCOL - { -#if IRMP_SUPPORT_NEC_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0) // repetition frame - { - if (repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX) - { - ANALYZE_PRINTF ("Detected NEC repetition frame, repetition_len = %d\n", repetition_len); - irmp_tmp_address = last_irmp_address; // address is last address - irmp_tmp_command = last_irmp_command; // command is last command - irmp_flags |= IRMP_FLAG_REPETITION; - repetition_len = 0; - } - else - { - ANALYZE_PRINTF ("Detected NEC repetition frame, ignoring it: timeout occured, repetition_len = %d > %d\n", - repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX); - irmp_ir_detected = FALSE; - } - } -#endif // IRMP_SUPPORT_NEC_PROTOCOL - -#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL) - { - uint8_t xor; - // ANALYZE_PRINTF ("0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", - // xor_check[0], xor_check[1], xor_check[2], xor_check[3], xor_check[4], xor_check[5]); - - xor = (xor_check[0] & 0x0F) ^ ((xor_check[0] & 0xF0) >> 4) ^ (xor_check[1] & 0x0F) ^ ((xor_check[1] & 0xF0) >> 4); - - if (xor != (xor_check[2] & 0x0F)) - { - ANALYZE_PRINTF ("error 4: wrong XOR check for customer id: 0x%1x 0x%1x\n", xor, xor_check[2] & 0x0F); - irmp_ir_detected = FALSE; - } - - xor = xor_check[2] ^ xor_check[3] ^ xor_check[4]; - - if (xor != xor_check[5]) - { - ANALYZE_PRINTF ("error 4: wrong XOR check for data bits: 0x%02x 0x%02x\n", xor, xor_check[5]); - irmp_ir_detected = FALSE; - } - - irmp_flags |= genre2; // write the genre2 bits into MSB of the flag byte - } -#endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 - -#if IRMP_SUPPORT_RC6_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode = 6? - { - irmp_protocol = IRMP_RC6A_PROTOCOL; - } - else -#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 - - irmp_protocol = irmp_param.protocol; - -#if IRMP_SUPPORT_FDC_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_FDC_PROTOCOL) - { - if (irmp_tmp_command & 0x000F) // released key? - { - irmp_tmp_command = (irmp_tmp_command >> 4) | 0x80; // yes, set bit 7 - } - else - { - irmp_tmp_command >>= 4; // no, it's a pressed key - } - irmp_tmp_command |= (irmp_tmp_address << 2) & 0x0F00; // 000000CCCCAAAAAA -> 0000CCCC00000000 - irmp_tmp_address &= 0x003F; - } -#endif - - irmp_address = irmp_tmp_address; // store address -#if IRMP_SUPPORT_NEC_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_NEC_PROTOCOL) - { - last_irmp_address = irmp_tmp_address; // store as last address, too - } -#endif - -#if IRMP_SUPPORT_RC5_PROTOCOL == 1 - if (irmp_param.protocol == IRMP_RC5_PROTOCOL) - { - irmp_tmp_command |= rc5_cmd_bit6; // store bit 6 - } -#endif - irmp_command = irmp_tmp_command; // store command - -#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 - irmp_id = irmp_tmp_id; -#endif - } - } - - if (irmp_ir_detected) - { - if (last_irmp_command == irmp_tmp_command && - last_irmp_address == irmp_tmp_address && - repetition_len < IRMP_KEY_REPETITION_LEN) - { - irmp_flags |= IRMP_FLAG_REPETITION; - } - - last_irmp_address = irmp_tmp_address; // store as last address, too - last_irmp_command = irmp_tmp_command; // store as last command, too - - repetition_len = 0; - } - else - { - ANALYZE_ONLY_NORMAL_PUTCHAR ('\n'); - } - -// irmp_busy_flag = FALSE; - irmp_start_bit_detected = 0; // and wait for next start bit - irmp_tmp_command = 0; - irmp_pulse_time = 0; - irmp_pause_time = 0; - -#if IRMP_SUPPORT_JVC_PROTOCOL == 1 - if (irmp_protocol == IRMP_JVC_PROTOCOL) // the stop bit of JVC frame is also start bit of next frame - { // set pulse time here! - irmp_pulse_time = ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME)); - } -#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 - } - } - } - return (irmp_ir_detected); -} - -#ifdef ANALYZE - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * main functions - for Unix/Linux + Windows only! - * - * AVR: see main.c! - * - * Compile it under linux with: - * cc irmp.c -o irmp - * - * usage: ./irmp [-v|-s|-a|-l|-p] < file - * - * options: - * -v verbose - * -s silent - * -a analyze - * -l list pulse/pauses - * -p print timings - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ - -#ifndef IRMP_EMBED -static void -print_timings (void) -{ - printf ("IRMP_TIMEOUT_LEN: %d [%d byte(s)]\n", IRMP_TIMEOUT_LEN, sizeof (PAUSE_LEN)); - printf ("IRMP_KEY_REPETITION_LEN %d\n", IRMP_KEY_REPETITION_LEN); - puts (""); - printf ("PROTOCOL S S-PULSE S-PAUSE PULSE-0 PAUSE-0 PULSE-1 PAUSE-1\n"); - printf ("====================================================================================\n"); - printf ("SIRCS 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX, SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX, - SIRCS_0_PULSE_LEN_MIN, SIRCS_0_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX, - SIRCS_1_PULSE_LEN_MIN, SIRCS_1_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX); - - printf ("NEC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX, - NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX, - NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX); - - printf ("NEC (rep) 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX, - NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX, - NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX); - - printf ("SAMSUNG 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX, SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX, - SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_0_PAUSE_LEN_MIN, SAMSUNG_0_PAUSE_LEN_MAX, - SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_1_PAUSE_LEN_MIN, SAMSUNG_1_PAUSE_LEN_MAX); - - printf ("MATSUSHITA 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX, MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX, - MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_0_PAUSE_LEN_MIN, MATSUSHITA_0_PAUSE_LEN_MAX, - MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_1_PAUSE_LEN_MIN, MATSUSHITA_1_PAUSE_LEN_MAX); - - printf ("KASEIKYO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX, KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX, - KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_0_PAUSE_LEN_MIN, KASEIKYO_0_PAUSE_LEN_MAX, - KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_1_PAUSE_LEN_MIN, KASEIKYO_1_PAUSE_LEN_MAX); - - printf ("RECS80 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX, RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX, - RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_0_PAUSE_LEN_MIN, RECS80_0_PAUSE_LEN_MAX, - RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_1_PAUSE_LEN_MIN, RECS80_1_PAUSE_LEN_MAX); - - printf ("RC5 1 %3d - %3d %3d - %3d %3d - %3d\n", - RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, - RC5_BIT_LEN_MIN, RC5_BIT_LEN_MAX); - - printf ("DENON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, - DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX, - DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX); - - printf ("THOMSON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, - THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, THOMSON_0_PAUSE_LEN_MIN, THOMSON_0_PAUSE_LEN_MAX, - THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, THOMSON_1_PAUSE_LEN_MIN, THOMSON_1_PAUSE_LEN_MAX); - - printf ("RC6 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX, RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX, - RC6_BIT_PULSE_LEN_MIN, RC6_BIT_PULSE_LEN_MAX, RC6_BIT_PAUSE_LEN_MIN, RC6_BIT_PAUSE_LEN_MAX); - - printf ("RECS80EXT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX, RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX, - RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_0_PAUSE_LEN_MIN, RECS80EXT_0_PAUSE_LEN_MAX, - RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_1_PAUSE_LEN_MIN, RECS80EXT_1_PAUSE_LEN_MAX); - - printf ("NUBERT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX, NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX, - NUBERT_0_PULSE_LEN_MIN, NUBERT_0_PULSE_LEN_MAX, NUBERT_0_PAUSE_LEN_MIN, NUBERT_0_PAUSE_LEN_MAX, - NUBERT_1_PULSE_LEN_MIN, NUBERT_1_PULSE_LEN_MAX, NUBERT_1_PAUSE_LEN_MIN, NUBERT_1_PAUSE_LEN_MAX); - - printf ("BANG_OLUFSEN 1 %3d - %3d %3d - %3d\n", - BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX, - BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX); - - printf ("BANG_OLUFSEN 2 %3d - %3d %3d - %3d\n", - BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX, - BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX); - - printf ("BANG_OLUFSEN 3 %3d - %3d %3d - %3d\n", - BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX, - BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX); - - printf ("BANG_OLUFSEN 4 %3d - %3d %3d - %3d\n", - BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX, - BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX); - - printf ("BANG_OLUFSEN - %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_0_PAUSE_LEN_MIN, BANG_OLUFSEN_0_PAUSE_LEN_MAX, - BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_1_PAUSE_LEN_MIN, BANG_OLUFSEN_1_PAUSE_LEN_MAX); - - printf ("GRUNDIG/NOKIA 1 %3d - %3d %3d - %3d %3d - %3d\n", - GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX, - GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX, - GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_BIT_LEN_MAX); - - printf ("SIEMENS/RUWIDO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX, - SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX, - SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX, - SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX, - 2 * SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX, - 2 * SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX); - - printf ("GRUNDIG2 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - GRUNDIG2_START_BIT_PULSE_LEN_MIN, GRUNDIG2_START_BIT_PULSE_LEN_MAX, - GRUNDIG2_START_BIT_PAUSE_LEN_MIN, GRUNDIG2_START_BIT_PAUSE_LEN_MAX, - GRUNDIG2_BIT_PULSE_LEN_MIN, GRUNDIG2_BIT_PULSE_LEN_MAX, - GRUNDIG2_BIT_PAUSE_LEN_MIN, GRUNDIG2_BIT_PAUSE_LEN_MAX, - 2 * GRUNDIG2_BIT_PULSE_LEN_MIN, 2 * GRUNDIG2_BIT_PULSE_LEN_MAX, - 2 * GRUNDIG2_BIT_PAUSE_LEN_MIN, 2 * GRUNDIG2_BIT_PAUSE_LEN_MAX); - - printf ("FDC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX, - FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_0_PAUSE_LEN_MIN, FDC_0_PAUSE_LEN_MAX, - FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_1_PAUSE_LEN_MIN, FDC_1_PAUSE_LEN_MAX); - - printf ("RCCAR 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX, - RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_0_PAUSE_LEN_MIN, RCCAR_0_PAUSE_LEN_MAX, - RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_1_PAUSE_LEN_MIN, RCCAR_1_PAUSE_LEN_MAX); - - printf ("NIKON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX, NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX, - NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_0_PAUSE_LEN_MIN, NIKON_0_PAUSE_LEN_MAX, - NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_1_PAUSE_LEN_MIN, NIKON_1_PAUSE_LEN_MAX); - - printf ("LEGO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", - LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX, LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX, - LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_0_PAUSE_LEN_MIN, LEGO_0_PAUSE_LEN_MAX, - LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_1_PAUSE_LEN_MIN, LEGO_1_PAUSE_LEN_MAX); - -} - -void -print_spectrum (char * text, int * buf, int is_pulse) -{ - int i; - int j; - int min; - int max; - int max_value = 0; - int value; - int sum = 0; - int counter = 0; - double average = 0; - double tolerance; - - puts ("-------------------------------------------------------------------------------"); - printf ("%s:\n", text); - - for (i = 0; i < 256; i++) - { - if (buf[i] > max_value) - { - max_value = buf[i]; - } - } - - for (i = 1; i < 100; i++) - { - if (buf[i] > 0) - { - printf ("%3d ", i); - value = (buf[i] * 60) / max_value; - - for (j = 0; j < value; j++) - { - putchar ('o'); - } - printf (" %d\n", buf[i]); - - sum += i * buf[i]; - counter += buf[i]; - } - else - { - max = i - 1; - - if (counter > 0) - { - average = (float) sum / (float) counter; - - if (is_pulse) - { - printf ("pulse "); - } - else - { - printf ("pause "); - } - - printf ("avg: %4.1f=%6.1f us, ", average, (1000000. * average) / (float) F_INTERRUPTS); - printf ("min: %2d=%6.1f us, ", min, (1000000. * min) / (float) F_INTERRUPTS); - printf ("max: %2d=%6.1f us, ", max, (1000000. * max) / (float) F_INTERRUPTS); - - tolerance = (max - average); - - if (average - min > tolerance) - { - tolerance = average - min; - } - - tolerance = tolerance * 100 / average; - printf ("tol: %4.1f%%\n", tolerance); - } - - counter = 0; - sum = 0; - min = i + 1; - } - } -} -#endif - -#define STATE_LEFT_SHIFT 0x01 -#define STATE_RIGHT_SHIFT 0x02 -#define STATE_LEFT_CTRL 0x04 -#define STATE_LEFT_ALT 0x08 -#define STATE_RIGHT_ALT 0x10 - -#define KEY_ESCAPE 0x1B // keycode = 0x006e -#define KEY_MENUE 0x80 // keycode = 0x0070 -#define KEY_BACK 0x81 // keycode = 0x0071 -#define KEY_FORWARD 0x82 // keycode = 0x0072 -#define KEY_ADDRESS 0x83 // keycode = 0x0073 -#define KEY_WINDOW 0x84 // keycode = 0x0074 -#define KEY_1ST_PAGE 0x85 // keycode = 0x0075 -#define KEY_STOP 0x86 // keycode = 0x0076 -#define KEY_MAIL 0x87 // keycode = 0x0077 -#define KEY_FAVORITES 0x88 // keycode = 0x0078 -#define KEY_NEW_PAGE 0x89 // keycode = 0x0079 -#define KEY_SETUP 0x8A // keycode = 0x007a -#define KEY_FONT 0x8B // keycode = 0x007b -#define KEY_PRINT 0x8C // keycode = 0x007c -#define KEY_ON_OFF 0x8E // keycode = 0x007c - -#define KEY_INSERT 0x90 // keycode = 0x004b -#define KEY_DELETE 0x91 // keycode = 0x004c -#define KEY_LEFT 0x92 // keycode = 0x004f -#define KEY_HOME 0x93 // keycode = 0x0050 -#define KEY_END 0x94 // keycode = 0x0051 -#define KEY_UP 0x95 // keycode = 0x0053 -#define KEY_DOWN 0x96 // keycode = 0x0054 -#define KEY_PAGE_UP 0x97 // keycode = 0x0055 -#define KEY_PAGE_DOWN 0x98 // keycode = 0x0056 -#define KEY_RIGHT 0x99 // keycode = 0x0059 -#define KEY_MOUSE_1 0x9E // keycode = 0x0400 -#define KEY_MOUSE_2 0x9F // keycode = 0x0800 - -#ifndef LIRC_IRMP -static uint8_t -get_fdc_key (uint16_t cmd) -{ - static uint8_t key_table[128] = - { - // 0 1 2 3 4 5 6 7 8 9 A B C D E F - 0, '^', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'ß', '´', 0, '\b', - '\t','q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 'ü', '+', 0, 0, 'a', - 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'ö', 'ä', '#', '\r', 0, '<', 'y', 'x', - 'c', 'v', 'b', 'n', 'm', ',', '.', '-', 0, 0, 0, 0, 0, ' ', 0, 0, - - 0, '°', '!', '"', '§', '$', '%', '&', '/', '(', ')', '=', '?', '`', 0, '\b', - '\t','Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 'Ü', '*', 0, 0, 'A', - 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Ö', 'Ä', '\'','\r', 0, '>', 'Y', 'X', - 'C', 'V', 'B', 'N', 'M', ';', ':', '_', 0, 0, 0, 0, 0, ' ', 0, 0 - }; - static uint8_t state; - - uint8_t key = 0; - - switch (cmd) - { - case 0x002C: state |= STATE_LEFT_SHIFT; break; // pressed left shift - case 0x00AC: state &= ~STATE_LEFT_SHIFT; break; // released left shift - case 0x0039: state |= STATE_RIGHT_SHIFT; break; // pressed right shift - case 0x00B9: state &= ~STATE_RIGHT_SHIFT; break; // released right shift - case 0x003A: state |= STATE_LEFT_CTRL; break; // pressed left ctrl - case 0x00BA: state &= ~STATE_LEFT_CTRL; break; // released left ctrl - case 0x003C: state |= STATE_LEFT_ALT; break; // pressed left alt - case 0x00BC: state &= ~STATE_LEFT_ALT; break; // released left alt - case 0x003E: state |= STATE_RIGHT_ALT; break; // pressed left alt - case 0x00BE: state &= ~STATE_RIGHT_ALT; break; // released left alt - - case 0x006e: key = KEY_ESCAPE; break; - case 0x004b: key = KEY_INSERT; break; - case 0x004c: key = KEY_DELETE; break; - case 0x004f: key = KEY_LEFT; break; - case 0x0050: key = KEY_HOME; break; - case 0x0051: key = KEY_END; break; - case 0x0053: key = KEY_UP; break; - case 0x0054: key = KEY_DOWN; break; - case 0x0055: key = KEY_PAGE_UP; break; - case 0x0056: key = KEY_PAGE_DOWN; break; - case 0x0059: key = KEY_RIGHT; break; - case 0x0400: key = KEY_MOUSE_1; break; - case 0x0800: key = KEY_MOUSE_2; break; - - default: - { - if (!(cmd & 0x80)) // pressed key - { - if (cmd >= 0x70 && cmd <= 0x7F) // function keys - { - key = cmd + 0x10; // 7x -> 8x - } - else if (cmd < 64) // key listed in key_table - { - if (state & (STATE_LEFT_ALT | STATE_RIGHT_ALT)) - { - switch (cmd) - { - case 0x0003: key = '²'; break; - case 0x0008: key = '{'; break; - case 0x0009: key = '['; break; - case 0x000A: key = ']'; break; - case 0x000B: key = '}'; break; - case 0x000C: key = '\\'; break; - case 0x001C: key = '~'; break; - case 0x002D: key = '|'; break; - case 0x0034: key = 0xB5; break; // Mu - } - } - else if (state & (STATE_LEFT_CTRL)) - { - if (key_table[cmd] >= 'a' && key_table[cmd] <= 'z') - { - key = key_table[cmd] - 'a' + 1; - } - else - { - key = key_table[cmd]; - } - } - else - { - int idx = cmd + ((state & (STATE_LEFT_SHIFT | STATE_RIGHT_SHIFT)) ? 64 : 0); - - if (key_table[idx]) - { - key = key_table[idx]; - } - } - } - } - break; - } - } - - return (key); -} - -static int analyze = FALSE; -static int list = FALSE; -static IRMP_DATA irmp_data; - -static void -next_tick (void) -{ - if (! analyze && ! list) - { - (void) irmp_ISR (); - - if (irmp_get_data (&irmp_data)) - { - uint8_t key; - - ANALYZE_ONLY_NORMAL_PUTCHAR (' '); - - if (verbose) - { - printf ("%8.3fms ", (double) (time_counter * 1000) / F_INTERRUPTS); - } - - if (irmp_data.protocol == IRMP_FDC_PROTOCOL && (key = get_fdc_key (irmp_data.command)) != 0) - { - if ((key >= 0x20 && key < 0x7F) || key >= 0xA0) - { - printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = '%c'\n", - irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, key); - } - else if (key == '\r' || key == '\t' || key == KEY_ESCAPE || (key >= 0x80 && key <= 0x9F)) // function keys - { - char * p = (char *) NULL; - - switch (key) - { - case '\t' : p = "TAB"; break; - case '\r' : p = "CR"; break; - case KEY_ESCAPE : p = "ESCAPE"; break; - case KEY_MENUE : p = "MENUE"; break; - case KEY_BACK : p = "BACK"; break; - case KEY_FORWARD : p = "FORWARD"; break; - case KEY_ADDRESS : p = "ADDRESS"; break; - case KEY_WINDOW : p = "WINDOW"; break; - case KEY_1ST_PAGE : p = "1ST_PAGE"; break; - case KEY_STOP : p = "STOP"; break; - case KEY_MAIL : p = "MAIL"; break; - case KEY_FAVORITES : p = "FAVORITES"; break; - case KEY_NEW_PAGE : p = "NEW_PAGE"; break; - case KEY_SETUP : p = "SETUP"; break; - case KEY_FONT : p = "FONT"; break; - case KEY_PRINT : p = "PRINT"; break; - case KEY_ON_OFF : p = "ON_OFF"; break; - - case KEY_INSERT : p = "INSERT"; break; - case KEY_DELETE : p = "DELETE"; break; - case KEY_LEFT : p = "LEFT"; break; - case KEY_HOME : p = "HOME"; break; - case KEY_END : p = "END"; break; - case KEY_UP : p = "UP"; break; - case KEY_DOWN : p = "DOWN"; break; - case KEY_PAGE_UP : p = "PAGE_UP"; break; - case KEY_PAGE_DOWN : p = "PAGE_DOWN"; break; - case KEY_RIGHT : p = "RIGHT"; break; - case KEY_MOUSE_1 : p = "KEY_MOUSE_1"; break; - case KEY_MOUSE_2 : p = "KEY_MOUSE_2"; break; - default : p = ""; break; - } - - printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = %s\n", - irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, p); - } - else - { - printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x\n", - irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key); - } - } - else - { - printf ("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x\n", - irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags); - } - } - } -} -#endif - -#ifndef LIRC_IRMP -int -main (int argc, char ** argv) -{ - int i; - int ch; - int last_ch = 0; - int pulse = 0; - int pause = 0; - - int start_pulses[256]; - int start_pauses[256]; - int pulses[256]; - int pauses[256]; - - int first_pulse = TRUE; - int first_pause = TRUE; - - if (argc == 2) - { - if (! strcmp (argv[1], "-v")) - { - verbose = TRUE; - } - else if (! strcmp (argv[1], "-l")) - { - list = TRUE; - } - else if (! strcmp (argv[1], "-a")) - { - analyze = TRUE; - } - else if (! strcmp (argv[1], "-s")) - { - silent = TRUE; - } - else if (! strcmp (argv[1], "-p")) - { - print_timings (); - return (0); - } - } - - for (i = 0; i < 256; i++) - { - start_pulses[i] = 0; - start_pauses[i] = 0; - pulses[i] = 0; - pauses[i] = 0; - } - - IRMP_PIN = 0xFF; - - while ((ch = getchar ()) != EOF) - { - if (ch == '_' || ch == '0') - { - if (last_ch != ch) - { - if (pause > 0) - { - if (list) - { - printf ("pause: %d\n", pause); - } - - if (analyze) - { - if (first_pause) - { - if (pause < 256) - { - start_pauses[pause]++; - } - first_pause = FALSE; - } - else - { - if (pause < 256) - { - pauses[pause]++; - } - } - } - } - pause = 0; - } - pulse++; - IRMP_PIN = 0x00; - } - else if (ch == 0xaf || ch == '-' || ch == '1') - { - if (last_ch != ch) - { - if (list) - { - printf ("pulse: %d ", pulse); - } - - if (analyze) - { - if (first_pulse) - { - if (pulse < 256) - { - start_pulses[pulse]++; - } - first_pulse = FALSE; - } - else - { - if (pulse < 256) - { - pulses[pulse]++; - } - } - } - pulse = 0; - } - - pause++; - IRMP_PIN = 0xff; - } - else if (ch == '\n') - { - IRMP_PIN = 0xff; - - if (list && pause > 0) - { - printf ("pause: %d\n", pause); - } - pause = 0; - - if (! analyze) - { - for (i = 0; i < (int) ((8000.0 * F_INTERRUPTS) / 10000); i++) // newline: long pause of 800 msec - { - next_tick (); - } - } - first_pulse = TRUE; - first_pause = TRUE; - } - else if (ch == '#') - { - if (analyze) - { - while ((ch = getchar()) != '\n' && ch != EOF) - { - ; - } - } - else - { - puts ("-------------------------------------------------------------------"); - putchar (ch); - - while ((ch = getchar()) != '\n' && ch != EOF) - { - if (ch != '\r') // ignore CR in DOS/Windows files - { - putchar (ch); - } - } - putchar ('\n'); - } - - } - - last_ch = ch; - - next_tick (); - } - - if (analyze) - { - print_spectrum ("START PULSES", start_pulses, TRUE); - print_spectrum ("START PAUSES", start_pauses, FALSE); - print_spectrum ("PULSES", pulses, TRUE); - print_spectrum ("PAUSES", pauses, FALSE); - puts ("-------------------------------------------------------------------------------"); - } - return 0; -} -#else -#ifndef IRMP_EMBED -/* 50 ms. This should be longer than the longest light pulse */ -#define POLL_MS (50 * 1000) -#define LIRC_PULSE 0x01000000 -#define LIRC_PULSE_MASK 0x00FFFFFF - -int main (int argc, char ** argv) -{ - int fd; - int pulse; - int last_pulse = 1; - uint32_t lircdata; /* lirc_t to be correct... */ - unsigned int count = 0; /* how many timeouts? */ - IRMP_DATA d; - - silent = TRUE; - - if (argc == 2) - { - if (! strcmp (argv[1], "-v")) - { - verbose = TRUE; - silent = FALSE; - } - else if (! strcmp (argv[1], "-p")) - { - print_timings (); - return (0); - } - } - - IRMP_PIN = 0xFF; - fd = open("/dev/lirc", O_RDONLY); - if (fd < 0) - { - perror ("open /dev/lirc"); - return 1; - } - /* TODO: ioctl to find out if we have a compatible LIRC_MODE2 device */ - - while(1) - { - fd_set fds; - struct timeval tv; - int ret; - - FD_ZERO(&fds); - FD_SET(fd, &fds); - tv.tv_sec = 0; - tv.tv_usec = POLL_MS; - /* any singal can interrupt select. we rely on the linux-only feature - * that the timeout is automatcally recalculated in this case! */ - do { - ret = select(fd + 1, &fds, NULL, NULL, &tv); - } while (ret == -1 && errno == EINTR); - - if (ret == -1) { - /* errno != EINTR... */ - perror("lirmp: select"); - break; - } - - if (ret == 0) - { - count++; - lircdata = POLL_MS; /* timeout */ - pulse = !last_pulse; /* lirc sends data on signal change */ - } - else - { - if (read(fd, &lircdata, sizeof(lircdata)) != sizeof(lircdata)) - { - perror("read"); - break; - } - pulse = (lircdata & LIRC_PULSE); /* we got light... */ - last_pulse = pulse; - lircdata &= LIRC_PULSE_MASK; /* how long the pulse was in microseconds */ - } - - if (ret && count) - { - if (count * POLL_MS > lircdata) - lircdata = 0; - else - lircdata -= count * POLL_MS; - count = 0; - } - //printf("lircdata: ret:%d c:%d %d\n", ret, ch - '0', lircdata); - lircdata /= (1000000 / F_INTERRUPTS); - - if (pulse) - IRMP_PIN = 0x00; - else - IRMP_PIN = 0xff; - - do { - (void) irmp_ISR (); - if (irmp_get_data (&d)) - { - printf("protocol: %2d address: 0x%04x command: 0x%04x flags: %d\n", - d.protocol, d.address, d.command, d.flags); - - /* do something else here... */ - - /* todo: do we need to complete the loop if we already - * detected the singal in this pulse? */ - } - } while (lircdata-- > 0); - } - return 0; -} -#endif // IRMP_EMBED -#endif // LIRC_IRMP -#endif // ANALYZE +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * irmp.c - infrared multi-protocol decoder, supports several remote control protocols + * + * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de + * + * $Id: irmp.c,v 1.115 2012/02/21 08:41:46 fm Exp $ + * + * ATMEGA88 @ 8 MHz + * + * Supported mikrocontrollers: + * + * ATtiny45, ATtiny85 + * ATtiny84 + * ATmega8, ATmega16, ATmega32 + * ATmega162 + * ATmega164, ATmega324, ATmega644, ATmega644P, ATmega1284 + * ATmega88, ATmega88P, ATmega168, ATmega168P, ATmega328P + * + * Typical manufacturers of remote controls: + * + * SIRCS - Sony + * NEC - NEC, Yamaha, Canon, Tevion, Harman/Kardon, Hitachi, JVC, Pioneer, Toshiba, Xoro, Orion, and many other Japanese manufacturers + * SAMSUNG - Samsung + * SAMSUNG32 - Samsung + * MATSUSHITA - Matsushita + * KASEIKYO - Panasonic, Denon & other Japanese manufacturers (members of "Japan's Association for Electric Home Application") + * RECS80 - Philips, Nokia, Thomson, Nordmende, Telefunken, Saba + * RC5 - Philips and other European manufacturers + * DENON - Denon, Sharp + * RC6 - Philips and other European manufacturers + * APPLE - Apple + * NUBERT - Nubert Subwoofer System + * B&O - Bang & Olufsen + * PANASONIC - Panasonic (older, yet not implemented) + * GRUNDIG - Grundig + * NOKIA - Nokia + * SIEMENS - Siemens, e.g. Gigaset M740AV + * FDC - FDC IR keyboard + * RCCAR - IR remote control for RC cars + * JVC - JVC + * THOMSON - Thomson + * NIKON - Nikon cameras + * RUWIDO - T-Home + * KATHREIN - Kathrein + * LEGO - Lego Power Functions RC + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * SIRCS + * ----- + * + * frame: 1 start bit + 12-20 data bits + no stop bit + * data: 7 command bits + 5 address bits + 0 to 8 additional bits + * + * start bit: data "0": data "1": stop bit: + * -----------------_________ ------_____ ------------______ + * 2400us 600us 600us 600us 1200us 600 us no stop bit + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * NEC + extended NEC + * ------------------------- + * + * frame: 1 start bit + 32 data bits + 1 stop bit + * data NEC: 8 address bits + 8 inverted address bits + 8 command bits + 8 inverted command bits + * data extended NEC: 16 address bits + 8 command bits + 8 inverted command bits + * + * start bit: data "0": data "1": stop bit: + * -----------------_________ ------______ ------________________ ------______.... + * 9000us 4500us 560us 560us 560us 1690 us 560us + * + * + * Repetition frame: + * + * -----------------_________------______ .... ~100ms Pause, then repeat + * 9000us 2250us 560us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * SAMSUNG + * ------- + * + * frame: 1 start bit + 16 data(1) bits + 1 sync bit + additional 20 data(2) bits + 1 stop bit + * data(1): 16 address bits + * data(2): 4 ID bits + 8 command bits + 8 inverted command bits + * + * start bit: data "0": data "1": sync bit: stop bit: + * ----------______________ ------______ ------________________ ------______________ ------______.... + * 4500us 4500us 550us 450us 550us 1450us 550us 4500us 550us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * SAMSUNG32 + * ---------- + * + * frame: 1 start bit + 32 data bits + 1 stop bit + * data: 16 address bits + 16 command bits + * + * start bit: data "0": data "1": stop bit: + * ----------______________ ------______ ------________________ ------______.... + * 4500us 4500us 550us 450us 550us 1450us 550us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * MATSUSHITA + * ---------- + * + * frame: 1 start bit + 24 data bits + 1 stop bit + * data: 6 custom bits + 6 command bits + 12 address bits + * + * start bit: data "0": data "1": stop bit: + * ----------_________ ------______ ------________________ ------______.... + * 3488us 3488us 872us 872us 872us 2616us 872us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * KASEIKYO + * -------- + * + * frame: 1 start bit + 48 data bits + 1 stop bit + * data: 16 manufacturer bits + 4 parity bits + 4 genre1 bits + 4 genre2 bits + 10 command bits + 2 id bits + 8 parity bits + * + * start bit: data "0": data "1": stop bit: + * ----------______ ------______ ------________________ ------______.... + * 3380us 1690us 423us 423us 423us 1269us 423us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * RECS80 + * ------ + * + * frame: 2 start bits + 10 data bits + 1 stop bit + * data: 1 toggle bit + 3 address bits + 6 command bits + * + * start bit: data "0": data "1": stop bit: + * -----_____________________ -----____________ -----______________ ------_______.... + * 158us 7432us 158us 4902us 158us 7432us 158us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * RECS80EXT + * --------- + * + * frame: 2 start bits + 11 data bits + 1 stop bit + * data: 1 toggle bit + 4 address bits + 6 command bits + * + * start bit: data "0": data "1": stop bit: + * -----_____________________ -----____________ -----______________ ------_______.... + * 158us 3637us 158us 4902us 158us 7432us 158us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * RC5 + RC5X + * ---------- + * + * RC5 frame: 2 start bits + 12 data bits + no stop bit + * RC5 data: 1 toggle bit + 5 address bits + 6 command bits + * RC5X frame: 1 start bit + 13 data bits + no stop bit + * RC5X data: 1 inverted command bit + 1 toggle bit + 5 address bits + 6 command bits + * + * start bit: data "0": data "1": + * ______----- ------______ ______------ + * 889us 889us 889us 889us 889us 889us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * DENON + * ----- + * + * frame: 0 start bits + 16 data bits + stop bit + 65ms pause + 16 inverted data bits + stop bit + * data: 5 address bits + 10 command bits + * + * Theory: + * + * data "0": data "1": + * ------________________ ------______________ + * 275us 775us 275us 1900us + * + * Practice: + * + * data "0": data "1": + * ------________________ ------______________ + * 310us 745us 310us 1780us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * RC6 + * --- + * + * RC6 frame: 1 start bit + 1 bit "1" + 3 mode bits + 1 toggle bit + 16 data bits + 2666 us pause + * RC6 data: 8 address bits + 8 command bits + * + * start bit toggle bit "0": toggle bit "1": data/mode "0": data/mode "1": + * ____________------- _______------- -------_______ _______------- -------_______ + * 2666us 889us 889us 889us 889us 889us 444us 444us 444us 444us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * APPLE + * ----- + * + * frame: 1 start bit + 32 data bits + 1 stop bit + * data: 16 address bits + 11100000 + 8 command bits + * + * start bit: data "0": data "1": stop bit: + * -----------------_________ ------______ ------________________ ------______.... + * 9000us 4500us 560us 560us 560us 1690 us 560us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * NUBERT (subwoofer system) + * ------------------------- + * + * frame: 1 start bit + 10 data bits + 1 stop bit + * data: 0 address bits + 10 command bits ? + * + * start bit: data "0": data "1": stop bit: + * ----------_____ ------______ ------________________ ------______.... + * 1340us 340us 500us 1300us 1340us 340us 500us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * BANG_OLUFSEN + * ------------ + * + * frame: 4 start bits + 16 data bits + 1 trailer bit + 1 stop bit + * data: 0 address bits + 16 command bits + * + * 1st start bit: 2nd start bit: 3rd start bit: 4th start bit: + * -----________ -----________ -----_____________ -----________ + * 210us 3000us 210us 3000us 210us 15000us 210us 3000us + * + * data "0": data "1": data "repeat bit": trailer bit: stop bit: + * -----________ -----_____________ -----___________ -----_____________ -----____... + * 210us 3000us 210us 9000us 210us 6000us 210us 12000us 210us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * GRUNDIG + * ------- + * + * packet: 1 start frame + 19,968ms pause + N info frames + 117,76ms pause + 1 stop frame + * frame: 1 pre bit + 1 start bit + 9 data bits + no stop bit + * pause between info frames: 117,76ms + * + * data of start frame: 9 x 1 + * data of info frame: 9 command bits + * data of stop frame: 9 x 1 + * + * pre bit: start bit data "0": data "1": + * ------____________ ------______ ______------ ------______ + * 528us 2639us 528us 528us 528us 528us 528us 528us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * NOKIA: + * ------ + * + * Timing similar to Grundig, but 16 data bits: + * frame: 1 pre bit + 1 start bit + 8 command bits + 8 address bits + no stop bit + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * SIEMENS or RUWIDO: + * ------------------ + * + * SIEMENS frame: 1 start bit + 22 data bits + no stop bit + * SIEMENS data: 13 address bits + 1 repeat bit + 7 data bits + 1 unknown bit + * + * start bit data "0": data "1": + * -------_______ _______------- -------_______ + * 250us 250us 250us 250us 250us 250us + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * PANASONIC (older protocol, yet not implemented, see also MATSUSHITA, timing very similar) + * ----------------------------------------------------------------------------------------- + * + * frame: 1 start bit + 22 data bits + 1 stop bit + * 22 data bits = 5 custom bits + 6 data bits + 5 inverted custom bits + 6 inverted data bits + * + * European version: T = 456us + * USA & Canada version: T = 422us + * + * start bit: data "0": data "1": stop bit: + * 8T 8T 2T 2T 2T 6T 2T + * -------------____________ ------_____ ------_____________ ------_______.... + * 3648us 3648us 912us 912us 912us 2736us 912us (Europe) + * 3376us 3376us 844us 844us 844us 2532us 844us (US) + * + *--------------------------------------------------------------------------------------------------------------------------------------------------- + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ + +#if defined(__18CXX) +#define PIC_C18 // Microchip C18 Compiler +#endif + +#if defined(__PCM__) || defined(__PCB__) || defined(__PCH__) // CCS PIC Compiler instead of AVR +#define PIC_CCS_COMPILER +#endif + +#ifdef unix // test on linux/unix +#include +#include +#include +#include +#include + +/* for crazy lirc stuff... */ +#include +#include +#include +#include + +#define ANALYZE +#define PROGMEM +#define memcpy_P memcpy + +#else // not unix: + +#ifdef WIN32 +#include +#include +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +#define ANALYZE +#define PROGMEM +#define memcpy_P memcpy + +#else + +#if defined (PIC_CCS_COMPILER) || defined(PIC_C18) + +#include +#define PROGMEM +#define memcpy_P memcpy + +#if defined (PIC_CCS_COMPILER) +typedef unsigned int8 uint8_t; +typedef unsigned int16 uint16_t; +#endif + +#else // AVR: + +#include +#include +#include +#include +#include +#include + +#endif // PIC_CCS_COMPILER or PIC_C18 + +#endif // windows +#endif // unix + +#ifndef IRMP_USE_AS_LIB +#include "irmpconfig.h" +#endif +#include "irmp.h" + +#if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1 || IRMP_SUPPORT_NOKIA_PROTOCOL == 1 || IRMP_SUPPORT_IR60_PROTOCOL == 1 +#define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL 1 +#else +#define IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL 0 +#endif + +#if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1 || IRMP_SUPPORT_RUWIDO_PROTOCOL == 1 +#define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL 1 +#else +#define IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL 0 +#endif + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 || \ + IRMP_SUPPORT_RC6_PROTOCOL == 1 || \ + IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 || \ + IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 || \ + IRMP_SUPPORT_GRUNDIG2_PROTOCOL == 1 || \ + IRMP_SUPPORT_IR60_PROTOCOL +#define IRMP_SUPPORT_MANCHESTER 1 +#else +#define IRMP_SUPPORT_MANCHESTER 0 +#endif + +#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 +#define IRMP_SUPPORT_SERIAL 1 +#else +#define IRMP_SUPPORT_SERIAL 0 +#endif + +#define IRMP_KEY_REPETITION_LEN (uint16_t)(F_INTERRUPTS * 150.0e-3 + 0.5) // autodetect key repetition within 150 msec + +#define MIN_TOLERANCE_00 1.0 // -0% +#define MAX_TOLERANCE_00 1.0 // +0% + +#define MIN_TOLERANCE_05 0.95 // -5% +#define MAX_TOLERANCE_05 1.05 // +5% + +#define MIN_TOLERANCE_10 0.9 // -10% +#define MAX_TOLERANCE_10 1.1 // +10% + +#define MIN_TOLERANCE_15 0.85 // -15% +#define MAX_TOLERANCE_15 1.15 // +15% + +#define MIN_TOLERANCE_20 0.8 // -20% +#define MAX_TOLERANCE_20 1.2 // +20% + +#define MIN_TOLERANCE_30 0.7 // -30% +#define MAX_TOLERANCE_30 1.3 // +30% + +#define MIN_TOLERANCE_40 0.6 // -40% +#define MAX_TOLERANCE_40 1.4 // +40% + +#define MIN_TOLERANCE_50 0.5 // -50% +#define MAX_TOLERANCE_50 1.5 // +50% + +#define MIN_TOLERANCE_60 0.4 // -60% +#define MAX_TOLERANCE_60 1.6 // +60% + +#define MIN_TOLERANCE_70 0.3 // -70% +#define MAX_TOLERANCE_70 1.7 // +70% + +#define SIRCS_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SIRCS_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define SIRCS_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#if IRMP_SUPPORT_NETBOX_PROTOCOL // only 5% to avoid conflict with NETBOX: +#define SIRCS_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5)) +#else // only 5% + 1 to avoid conflict with RC6: +#define SIRCS_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) +#endif +#define SIRCS_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SIRCS_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define SIRCS_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SIRCS_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define SIRCS_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SIRCS_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIRCS_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define NEC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define NEC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define NEC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define NEC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define NEC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define NEC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define NEC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define NEC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define NEC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define NEC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define NEC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define NEC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NEC_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +// autodetect nec repetition frame within 50 msec: +// NEC seems to send the first repetition frame after 40ms, further repetition frames after 100 ms +#if 0 +#define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * NEC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) +#else +#define NEC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * 100.0e-3 * MAX_TOLERANCE_20 + 0.5) +#endif + +#define SAMSUNG_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SAMSUNG_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define SAMSUNG_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SAMSUNG_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define SAMSUNG_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define SAMSUNG_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_PULSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define SAMSUNG_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define SAMSUNG_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define SAMSUNG_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define SAMSUNG_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SAMSUNG_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) + +#define MATSUSHITA_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define MATSUSHITA_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define MATSUSHITA_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define MATSUSHITA_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define MATSUSHITA_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define MATSUSHITA_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define MATSUSHITA_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define MATSUSHITA_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define MATSUSHITA_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define MATSUSHITA_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * MATSUSHITA_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) + +#define KASEIKYO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define KASEIKYO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define KASEIKYO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define KASEIKYO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define KASEIKYO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1) +#define KASEIKYO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1) +#define KASEIKYO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define KASEIKYO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define KASEIKYO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MIN_TOLERANCE_50 + 0.5) - 1) +#define KASEIKYO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KASEIKYO_0_PAUSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1) + +#define RECS80_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1) +#define RECS80_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RECS80_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RECS80_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RECS80_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RECS80_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RECS80_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RECS80_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RECS80_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RECS80_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define RC5_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RC5_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define RC5_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RC5_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC5_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define DENON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define DENON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define DENON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define DENON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 +#define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5)) // no -1, avoid conflict with RUWIDO +#else +#define DENON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) // be more tolerant +#endif +#define DENON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * DENON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define THOMSON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define THOMSON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define THOMSON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define THOMSON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define THOMSON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define THOMSON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * THOMSON_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define RC6_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RC6_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RC6_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RC6_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RC6_TOGGLE_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RC6_TOGGLE_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_TOGGLE_BIT_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RC6_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RC6_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_60 + 0.5) + 1) // pulses: 300 - 800 +#define RC6_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RC6_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RC6_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1) // pauses: 300 - 600 + +#define RECS80EXT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MIN_TOLERANCE_00 + 0.5) - 1) +#define RECS80EXT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PULSE_TIME * MAX_TOLERANCE_00 + 0.5) + 1) +#define RECS80EXT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1) +#define RECS80EXT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) +#define RECS80EXT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RECS80EXT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RECS80EXT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RECS80EXT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RECS80EXT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RECS80EXT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RECS80EXT_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define NUBERT_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NUBERT_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NUBERT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NUBERT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NUBERT_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NUBERT_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NUBERT_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NUBERT_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NUBERT_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NUBERT_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NUBERT_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NUBERT_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NUBERT_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) + +#define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT2_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX ((PAUSE_LEN)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT3_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5) + 1) // value must be below IRMP_TIMEOUT +#define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_START_BIT4_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_R_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_R_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_R_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define IR60_TIMEOUT_LEN ((uint8_t)(F_INTERRUPTS * IR60_TIMEOUT_TIME * 0.5)) +#define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define GRUNDIG_NOKIA_IR60_BIT_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define GRUNDIG_NOKIA_IR60_BIT_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_BIT_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) + 1) +#define GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) + +#define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define GRUNDIG2_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG2_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define GRUNDIG2_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG2_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define GRUNDIG2_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG2_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define GRUNDIG2_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG2_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define GRUNDIG2_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG2_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define GRUNDIG2_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG2_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define GRUNDIG2_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * GRUNDIG2_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define GRUNDIG2_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * GRUNDIG2_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define FDC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1) // 5%: avoid conflict with NETBOX +#define FDC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PULSE_TIME * MAX_TOLERANCE_05 + 0.5)) +#define FDC_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MIN_TOLERANCE_05 + 0.5) - 1) +#define FDC_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_START_BIT_PAUSE_TIME * MAX_TOLERANCE_05 + 0.5)) +#define FDC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define FDC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_PULSE_TIME * MAX_TOLERANCE_50 + 0.5) + 1) +#define FDC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define FDC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#if 0 +#define FDC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) // could be negative: 255 +#else +#define FDC_0_PAUSE_LEN_MIN (1) // simply use 1 +#endif +#define FDC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * FDC_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define RCCAR_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RCCAR_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RCCAR_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define RCCAR_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define RCCAR_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define RCCAR_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define RCCAR_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define RCCAR_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_1_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) +#define RCCAR_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MIN_TOLERANCE_30 + 0.5) - 1) +#define RCCAR_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * RCCAR_0_PAUSE_TIME * MAX_TOLERANCE_30 + 0.5) + 1) + +#define JVC_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define JVC_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define JVC_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MIN_TOLERANCE_40 + 0.5) - 1) // HACK! +#define JVC_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * (JVC_FRAME_REPEAT_PAUSE_TIME - IRMP_TIMEOUT_TIME) * MAX_TOLERANCE_70 + 0.5) - 1) // HACK! +#define JVC_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define JVC_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define JVC_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define JVC_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define JVC_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define JVC_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * JVC_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +// autodetect JVC repetition frame within 50 msec: +#define JVC_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * JVC_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + +#define NIKON_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NIKON_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_START_BIT_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NIKON_START_BIT_PAUSE_LEN_MIN ((uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NIKON_START_BIT_PAUSE_LEN_MAX ((uint16_t)(F_INTERRUPTS * NIKON_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NIKON_REPEAT_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NIKON_REPEAT_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_REPEAT_START_BIT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NIKON_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NIKON_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_PULSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NIKON_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NIKON_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_1_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NIKON_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MIN_TOLERANCE_20 + 0.5) - 1) +#define NIKON_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NIKON_0_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + 1) +#define NIKON_FRAME_REPEAT_PAUSE_LEN_MAX (uint16_t)(F_INTERRUPTS * NIKON_FRAME_REPEAT_PAUSE_TIME * MAX_TOLERANCE_20 + 0.5) + +#define KATHREIN_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define KATHREIN_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define KATHREIN_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define KATHREIN_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define KATHREIN_1_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define KATHREIN_1_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define KATHREIN_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define KATHREIN_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_1_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define KATHREIN_0_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define KATHREIN_0_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define KATHREIN_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define KATHREIN_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_0_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define KATHREIN_SYNC_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define KATHREIN_SYNC_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * KATHREIN_SYNC_BIT_PAUSE_LEN_TIME * MAX_TOLERANCE_10 + 0.5) + 1) + +#define NETBOX_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define NETBOX_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PULSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define NETBOX_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MIN_TOLERANCE_10 + 0.5) - 1) +#define NETBOX_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * NETBOX_START_BIT_PAUSE_TIME * MAX_TOLERANCE_10 + 0.5) + 1) +#define NETBOX_PULSE_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME)) +#define NETBOX_PAUSE_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME)) +#define NETBOX_PULSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PULSE_TIME / 4)) +#define NETBOX_PAUSE_REST_LEN ((uint8_t)(F_INTERRUPTS * NETBOX_PAUSE_TIME / 4)) + +#define LEGO_START_BIT_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_START_BIT_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define LEGO_START_BIT_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_START_BIT_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_START_BIT_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define LEGO_PULSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_PULSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_PULSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define LEGO_1_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_1_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_1_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) +#define LEGO_0_PAUSE_LEN_MIN ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MIN_TOLERANCE_40 + 0.5) - 1) +#define LEGO_0_PAUSE_LEN_MAX ((uint8_t)(F_INTERRUPTS * LEGO_0_PAUSE_TIME * MAX_TOLERANCE_40 + 0.5) + 1) + +#define AUTO_FRAME_REPETITION_LEN (uint16_t)(F_INTERRUPTS * AUTO_FRAME_REPETITION_TIME + 0.5) // use uint16_t! + +#ifdef ANALYZE +#define ANALYZE_PUTCHAR(a) { if (! silent) { putchar (a); } } +#ifndef LIRC_IRMP +#define ANALYZE_ONLY_NORMAL_PUTCHAR(a) { if (! silent && !verbose) { putchar (a); } } +#else +#define ANALYZE_ONLY_NORMAL_PUTCHAR(a) +#endif +#define ANALYZE_PRINTF(...) { if (verbose) { printf (__VA_ARGS__); } } +#define ANALYZE_NEWLINE() { if (verbose) { putchar ('\n'); } } +static int silent = TRUE; +static int time_counter; +static int verbose; +#else +#define ANALYZE_PUTCHAR(a) +#define ANALYZE_ONLY_NORMAL_PUTCHAR(a) +#define ANALYZE_PRINTF(...) +#define ANALYZE_NEWLINE() +#endif + +#if IRMP_USE_CALLBACK == 1 +static void (*irmp_callback_ptr)(uint8_t); +#endif // IRMP_USE_CALLBACK == 1 + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Protocol names + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#if IRMP_PROTOCOL_NAMES == 1 +char * +irmp_protocol_names[IRMP_N_PROTOCOLS + 1] = +{ + "UNKNOWN", + "SIRCS", + "NEC", + "SAMSUNG", + "MATSUSH", + "KASEIKYO", + "RECS80", + "RC5", + "DENON", + "RC6", + "SAMSG32", + "APPLE", + "RECS80EX", + "NUBERT", + "BANG OLU", + "GRUNDIG", + "NOKIA", + "SIEMENS", + "FDC", + "RCCAR", + "JVC", + "RC6A", + "NIKON", + "RUWIDO", + "IR60", + "KATHREIN", + "NETBOX", + "NEC16", + "NEC42", + "LEGO", + "THOMSON" +}; +#endif + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Logging + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#if IRMP_LOGGING == 1 // logging via UART + +#if IRMP_EXT_LOGGING == 1 // use external logging +#include "irmpextlog.h" +#else // normal UART log (IRMP_EXT_LOGGING == 0) +#define BAUD 9600L +#include + +#ifdef UBRR0H + +#define UART0_UBRRH UBRR0H +#define UART0_UBRRL UBRR0L +#define UART0_UCSRA UCSR0A +#define UART0_UCSRB UCSR0B +#define UART0_UCSRC UCSR0C +#define UART0_UDRE_BIT_VALUE (1< ENDBITS) + { + // if stop condition is true, output on uart + uint16_t i; + + for (i = 0; i < STARTCYCLES; i++) + { + irmp_uart_putc('0'); // the ignored starting zeros + } + + for (i = 0; i < (buf_idx - ENDBITS + 20) / 8; i++) // transform bitset into uart chars + { + uint8_t d = buf[i]; + uint8_t j; + + for (j = 0; j < 8; j++) + { + irmp_uart_putc((d & 1) + '0'); + d >>= 1; + } + } + + irmp_uart_putc('\n'); + buf_idx = 0; + } + } + else + { + cnt = 0; + } + } + } +} + +#else +#define irmp_log(val) +#endif //IRMP_LOGGING + +typedef struct +{ + uint8_t protocol; // ir protocol + uint8_t pulse_1_len_min; // minimum length of pulse with bit value 1 + uint8_t pulse_1_len_max; // maximum length of pulse with bit value 1 + uint8_t pause_1_len_min; // minimum length of pause with bit value 1 + uint8_t pause_1_len_max; // maximum length of pause with bit value 1 + uint8_t pulse_0_len_min; // minimum length of pulse with bit value 0 + uint8_t pulse_0_len_max; // maximum length of pulse with bit value 0 + uint8_t pause_0_len_min; // minimum length of pause with bit value 0 + uint8_t pause_0_len_max; // maximum length of pause with bit value 0 + uint8_t address_offset; // address offset + uint8_t address_end; // end of address + uint8_t command_offset; // command offset + uint8_t command_end; // end of command + uint8_t complete_len; // complete length of frame + uint8_t stop_bit; // flag: frame has stop bit + uint8_t lsb_first; // flag: LSB first + uint8_t flags; // some flags +} IRMP_PARAMETER; + +#if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER sircs_param = +{ + IRMP_SIRCS_PROTOCOL, // protocol: ir protocol + SIRCS_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + SIRCS_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + SIRCS_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + SIRCS_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + SIRCS_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + SIRCS_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + SIRCS_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + SIRCS_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + SIRCS_ADDRESS_OFFSET, // address_offset: address offset + SIRCS_ADDRESS_OFFSET + SIRCS_ADDRESS_LEN, // address_end: end of address + SIRCS_COMMAND_OFFSET, // command_offset: command offset + SIRCS_COMMAND_OFFSET + SIRCS_COMMAND_LEN, // command_end: end of command + SIRCS_COMPLETE_DATA_LEN, // complete_len: complete length of frame + SIRCS_STOP_BIT, // stop_bit: flag: frame has stop bit + SIRCS_LSB, // lsb_first: flag: LSB first + SIRCS_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_NEC_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER nec_param = +{ + IRMP_NEC_PROTOCOL, // protocol: ir protocol + NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + NEC_ADDRESS_OFFSET, // address_offset: address offset + NEC_ADDRESS_OFFSET + NEC_ADDRESS_LEN, // address_end: end of address + NEC_COMMAND_OFFSET, // command_offset: command offset + NEC_COMMAND_OFFSET + NEC_COMMAND_LEN, // command_end: end of command + NEC_COMPLETE_DATA_LEN, // complete_len: complete length of frame + NEC_STOP_BIT, // stop_bit: flag: frame has stop bit + NEC_LSB, // lsb_first: flag: LSB first + NEC_FLAGS // flags: some flags +}; + +static const PROGMEM IRMP_PARAMETER nec_rep_param = +{ + IRMP_NEC_PROTOCOL, // protocol: ir protocol + NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + 0, // address_offset: address offset + 0, // address_end: end of address + 0, // command_offset: command offset + 0, // command_end: end of command + 0, // complete_len: complete length of frame + NEC_STOP_BIT, // stop_bit: flag: frame has stop bit + NEC_LSB, // lsb_first: flag: LSB first + NEC_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER nec42_param = +{ + IRMP_NEC42_PROTOCOL, // protocol: ir protocol + NEC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + NEC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + NEC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + NEC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + NEC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + NEC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + NEC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + NEC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + NEC42_ADDRESS_OFFSET, // address_offset: address offset + NEC42_ADDRESS_OFFSET + NEC42_ADDRESS_LEN, // address_end: end of address + NEC42_COMMAND_OFFSET, // command_offset: command offset + NEC42_COMMAND_OFFSET + NEC42_COMMAND_LEN, // command_end: end of command + NEC42_COMPLETE_DATA_LEN, // complete_len: complete length of frame + NEC_STOP_BIT, // stop_bit: flag: frame has stop bit + NEC_LSB, // lsb_first: flag: LSB first + NEC_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER samsung_param = +{ + IRMP_SAMSUNG_PROTOCOL, // protocol: ir protocol + SAMSUNG_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + SAMSUNG_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + SAMSUNG_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + SAMSUNG_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + SAMSUNG_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + SAMSUNG_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + SAMSUNG_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + SAMSUNG_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + SAMSUNG_ADDRESS_OFFSET, // address_offset: address offset + SAMSUNG_ADDRESS_OFFSET + SAMSUNG_ADDRESS_LEN, // address_end: end of address + SAMSUNG_COMMAND_OFFSET, // command_offset: command offset + SAMSUNG_COMMAND_OFFSET + SAMSUNG_COMMAND_LEN, // command_end: end of command + SAMSUNG_COMPLETE_DATA_LEN, // complete_len: complete length of frame + SAMSUNG_STOP_BIT, // stop_bit: flag: frame has stop bit + SAMSUNG_LSB, // lsb_first: flag: LSB first + SAMSUNG_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER matsushita_param = +{ + IRMP_MATSUSHITA_PROTOCOL, // protocol: ir protocol + MATSUSHITA_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + MATSUSHITA_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + MATSUSHITA_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + MATSUSHITA_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + MATSUSHITA_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + MATSUSHITA_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + MATSUSHITA_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + MATSUSHITA_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + MATSUSHITA_ADDRESS_OFFSET, // address_offset: address offset + MATSUSHITA_ADDRESS_OFFSET + MATSUSHITA_ADDRESS_LEN, // address_end: end of address + MATSUSHITA_COMMAND_OFFSET, // command_offset: command offset + MATSUSHITA_COMMAND_OFFSET + MATSUSHITA_COMMAND_LEN, // command_end: end of command + MATSUSHITA_COMPLETE_DATA_LEN, // complete_len: complete length of frame + MATSUSHITA_STOP_BIT, // stop_bit: flag: frame has stop bit + MATSUSHITA_LSB, // lsb_first: flag: LSB first + MATSUSHITA_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER kaseikyo_param = +{ + IRMP_KASEIKYO_PROTOCOL, // protocol: ir protocol + KASEIKYO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + KASEIKYO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + KASEIKYO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + KASEIKYO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + KASEIKYO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + KASEIKYO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + KASEIKYO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + KASEIKYO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + KASEIKYO_ADDRESS_OFFSET, // address_offset: address offset + KASEIKYO_ADDRESS_OFFSET + KASEIKYO_ADDRESS_LEN, // address_end: end of address + KASEIKYO_COMMAND_OFFSET, // command_offset: command offset + KASEIKYO_COMMAND_OFFSET + KASEIKYO_COMMAND_LEN, // command_end: end of command + KASEIKYO_COMPLETE_DATA_LEN, // complete_len: complete length of frame + KASEIKYO_STOP_BIT, // stop_bit: flag: frame has stop bit + KASEIKYO_LSB, // lsb_first: flag: LSB first + KASEIKYO_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_RECS80_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER recs80_param = +{ + IRMP_RECS80_PROTOCOL, // protocol: ir protocol + RECS80_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + RECS80_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + RECS80_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + RECS80_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + RECS80_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + RECS80_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + RECS80_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + RECS80_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + RECS80_ADDRESS_OFFSET, // address_offset: address offset + RECS80_ADDRESS_OFFSET + RECS80_ADDRESS_LEN, // address_end: end of address + RECS80_COMMAND_OFFSET, // command_offset: command offset + RECS80_COMMAND_OFFSET + RECS80_COMMAND_LEN, // command_end: end of command + RECS80_COMPLETE_DATA_LEN, // complete_len: complete length of frame + RECS80_STOP_BIT, // stop_bit: flag: frame has stop bit + RECS80_LSB, // lsb_first: flag: LSB first + RECS80_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER rc5_param = +{ + IRMP_RC5_PROTOCOL, // protocol: ir protocol + RC5_BIT_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse + RC5_BIT_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse + RC5_BIT_LEN_MIN, // pause_1_len_min: here: minimum length of short pause + RC5_BIT_LEN_MAX, // pause_1_len_max: here: maximum length of short pause + 0, // pulse_0_len_min: here: not used + 0, // pulse_0_len_max: here: not used + 0, // pause_0_len_min: here: not used + 0, // pause_0_len_max: here: not used + RC5_ADDRESS_OFFSET, // address_offset: address offset + RC5_ADDRESS_OFFSET + RC5_ADDRESS_LEN, // address_end: end of address + RC5_COMMAND_OFFSET, // command_offset: command offset + RC5_COMMAND_OFFSET + RC5_COMMAND_LEN, // command_end: end of command + RC5_COMPLETE_DATA_LEN, // complete_len: complete length of frame + RC5_STOP_BIT, // stop_bit: flag: frame has stop bit + RC5_LSB, // lsb_first: flag: LSB first + RC5_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_DENON_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER denon_param = +{ + IRMP_DENON_PROTOCOL, // protocol: ir protocol + DENON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + DENON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + DENON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + DENON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + DENON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + DENON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + DENON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + DENON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + DENON_ADDRESS_OFFSET, // address_offset: address offset + DENON_ADDRESS_OFFSET + DENON_ADDRESS_LEN, // address_end: end of address + DENON_COMMAND_OFFSET, // command_offset: command offset + DENON_COMMAND_OFFSET + DENON_COMMAND_LEN, // command_end: end of command + DENON_COMPLETE_DATA_LEN, // complete_len: complete length of frame + DENON_STOP_BIT, // stop_bit: flag: frame has stop bit + DENON_LSB, // lsb_first: flag: LSB first + DENON_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_RC6_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER rc6_param = +{ + IRMP_RC6_PROTOCOL, // protocol: ir protocol + + RC6_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse + RC6_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse + RC6_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause + RC6_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause + 0, // pulse_0_len_min: here: not used + 0, // pulse_0_len_max: here: not used + 0, // pause_0_len_min: here: not used + 0, // pause_0_len_max: here: not used + RC6_ADDRESS_OFFSET, // address_offset: address offset + RC6_ADDRESS_OFFSET + RC6_ADDRESS_LEN, // address_end: end of address + RC6_COMMAND_OFFSET, // command_offset: command offset + RC6_COMMAND_OFFSET + RC6_COMMAND_LEN, // command_end: end of command + RC6_COMPLETE_DATA_LEN_SHORT, // complete_len: complete length of frame + RC6_STOP_BIT, // stop_bit: flag: frame has stop bit + RC6_LSB, // lsb_first: flag: LSB first + RC6_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER recs80ext_param = +{ + IRMP_RECS80EXT_PROTOCOL, // protocol: ir protocol + RECS80EXT_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + RECS80EXT_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + RECS80EXT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + RECS80EXT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + RECS80EXT_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + RECS80EXT_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + RECS80EXT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + RECS80EXT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + RECS80EXT_ADDRESS_OFFSET, // address_offset: address offset + RECS80EXT_ADDRESS_OFFSET + RECS80EXT_ADDRESS_LEN, // address_end: end of address + RECS80EXT_COMMAND_OFFSET, // command_offset: command offset + RECS80EXT_COMMAND_OFFSET + RECS80EXT_COMMAND_LEN, // command_end: end of command + RECS80EXT_COMPLETE_DATA_LEN, // complete_len: complete length of frame + RECS80EXT_STOP_BIT, // stop_bit: flag: frame has stop bit + RECS80EXT_LSB, // lsb_first: flag: LSB first + RECS80EXT_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_NUBERT_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER nubert_param = +{ + IRMP_NUBERT_PROTOCOL, // protocol: ir protocol + NUBERT_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + NUBERT_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + NUBERT_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + NUBERT_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + NUBERT_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + NUBERT_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + NUBERT_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + NUBERT_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + NUBERT_ADDRESS_OFFSET, // address_offset: address offset + NUBERT_ADDRESS_OFFSET + NUBERT_ADDRESS_LEN, // address_end: end of address + NUBERT_COMMAND_OFFSET, // command_offset: command offset + NUBERT_COMMAND_OFFSET + NUBERT_COMMAND_LEN, // command_end: end of command + NUBERT_COMPLETE_DATA_LEN, // complete_len: complete length of frame + NUBERT_STOP_BIT, // stop_bit: flag: frame has stop bit + NUBERT_LSB, // lsb_first: flag: LSB first + NUBERT_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER bang_olufsen_param = +{ + IRMP_BANG_OLUFSEN_PROTOCOL, // protocol: ir protocol + BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + BANG_OLUFSEN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + BANG_OLUFSEN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + BANG_OLUFSEN_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + BANG_OLUFSEN_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + BANG_OLUFSEN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + BANG_OLUFSEN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + BANG_OLUFSEN_ADDRESS_OFFSET, // address_offset: address offset + BANG_OLUFSEN_ADDRESS_OFFSET + BANG_OLUFSEN_ADDRESS_LEN, // address_end: end of address + BANG_OLUFSEN_COMMAND_OFFSET, // command_offset: command offset + BANG_OLUFSEN_COMMAND_OFFSET + BANG_OLUFSEN_COMMAND_LEN, // command_end: end of command + BANG_OLUFSEN_COMPLETE_DATA_LEN, // complete_len: complete length of frame + BANG_OLUFSEN_STOP_BIT, // stop_bit: flag: frame has stop bit + BANG_OLUFSEN_LSB, // lsb_first: flag: LSB first + BANG_OLUFSEN_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 + +static uint8_t first_bit; + +static const PROGMEM IRMP_PARAMETER grundig_param = +{ + IRMP_GRUNDIG_PROTOCOL, // protocol: ir protocol + + GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse + GRUNDIG_NOKIA_IR60_BIT_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse + GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, // pause_1_len_min: here: minimum length of short pause + GRUNDIG_NOKIA_IR60_BIT_LEN_MAX, // pause_1_len_max: here: maximum length of short pause + 0, // pulse_0_len_min: here: not used + 0, // pulse_0_len_max: here: not used + 0, // pause_0_len_min: here: not used + 0, // pause_0_len_max: here: not used + GRUNDIG_ADDRESS_OFFSET, // address_offset: address offset + GRUNDIG_ADDRESS_OFFSET + GRUNDIG_ADDRESS_LEN, // address_end: end of address + GRUNDIG_COMMAND_OFFSET, // command_offset: command offset + GRUNDIG_COMMAND_OFFSET + GRUNDIG_COMMAND_LEN + 1, // command_end: end of command (USE 1 bit MORE to STORE NOKIA DATA!) + NOKIA_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: NOKIA instead of GRUNDIG! + GRUNDIG_NOKIA_IR60_STOP_BIT, // stop_bit: flag: frame has stop bit + GRUNDIG_NOKIA_IR60_LSB, // lsb_first: flag: LSB first + GRUNDIG_NOKIA_IR60_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER ruwido_param = +{ + IRMP_RUWIDO_PROTOCOL, // protocol: ir protocol + SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse + SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse + SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause + SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause + 0, // pulse_0_len_min: here: not used + 0, // pulse_0_len_max: here: not used + 0, // pause_0_len_min: here: not used + 0, // pause_0_len_max: here: not used + RUWIDO_ADDRESS_OFFSET, // address_offset: address offset + RUWIDO_ADDRESS_OFFSET + RUWIDO_ADDRESS_LEN, // address_end: end of address + RUWIDO_COMMAND_OFFSET, // command_offset: command offset + RUWIDO_COMMAND_OFFSET + RUWIDO_COMMAND_LEN, // command_end: end of command + SIEMENS_COMPLETE_DATA_LEN, // complete_len: complete length of frame, here: SIEMENS instead of RUWIDO! + SIEMENS_OR_RUWIDO_STOP_BIT, // stop_bit: flag: frame has stop bit + SIEMENS_OR_RUWIDO_LSB, // lsb_first: flag: LSB first + SIEMENS_OR_RUWIDO_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_GRUNDIG2_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER grundig2_param = +{ + IRMP_GRUNDIG2_PROTOCOL, // protocol: ir protocol + GRUNDIG2_BIT_PULSE_LEN_MIN, // pulse_1_len_min: here: minimum length of short pulse + GRUNDIG2_BIT_PULSE_LEN_MAX, // pulse_1_len_max: here: maximum length of short pulse + GRUNDIG2_BIT_PAUSE_LEN_MIN, // pause_1_len_min: here: minimum length of short pause + GRUNDIG2_BIT_PAUSE_LEN_MAX, // pause_1_len_max: here: maximum length of short pause + 0, // pulse_0_len_min: here: not used + 0, // pulse_0_len_max: here: not used + 0, // pause_0_len_min: here: not used + 0, // pause_0_len_max: here: not used + GRUNDIG2_ADDRESS_OFFSET, // address_offset: address offset + GRUNDIG2_ADDRESS_OFFSET + GRUNDIG2_ADDRESS_LEN, // address_end: end of address + GRUNDIG2_COMMAND_OFFSET, // command_offset: command offset + GRUNDIG2_COMMAND_OFFSET + GRUNDIG2_COMMAND_LEN, // command_end: end of command + GRUNDIG2_COMPLETE_DATA_LEN, // complete_len: complete length of frame + GRUNDIG2_STOP_BIT, // stop_bit: flag: frame has stop bit + GRUNDIG2_LSB, // lsb_first: flag: LSB first + GRUNDIG2_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_FDC_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER fdc_param = +{ + IRMP_FDC_PROTOCOL, // protocol: ir protocol + FDC_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + FDC_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + FDC_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + FDC_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + FDC_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + FDC_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + FDC_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + FDC_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + FDC_ADDRESS_OFFSET, // address_offset: address offset + FDC_ADDRESS_OFFSET + FDC_ADDRESS_LEN, // address_end: end of address + FDC_COMMAND_OFFSET, // command_offset: command offset + FDC_COMMAND_OFFSET + FDC_COMMAND_LEN, // command_end: end of command + FDC_COMPLETE_DATA_LEN, // complete_len: complete length of frame + FDC_STOP_BIT, // stop_bit: flag: frame has stop bit + FDC_LSB, // lsb_first: flag: LSB first + FDC_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER rccar_param = +{ + IRMP_RCCAR_PROTOCOL, // protocol: ir protocol + RCCAR_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + RCCAR_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + RCCAR_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + RCCAR_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + RCCAR_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + RCCAR_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + RCCAR_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + RCCAR_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + RCCAR_ADDRESS_OFFSET, // address_offset: address offset + RCCAR_ADDRESS_OFFSET + RCCAR_ADDRESS_LEN, // address_end: end of address + RCCAR_COMMAND_OFFSET, // command_offset: command offset + RCCAR_COMMAND_OFFSET + RCCAR_COMMAND_LEN, // command_end: end of command + RCCAR_COMPLETE_DATA_LEN, // complete_len: complete length of frame + RCCAR_STOP_BIT, // stop_bit: flag: frame has stop bit + RCCAR_LSB, // lsb_first: flag: LSB first + RCCAR_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_NIKON_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER nikon_param = +{ + IRMP_NIKON_PROTOCOL, // protocol: ir protocol + NIKON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + NIKON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + NIKON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + NIKON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + NIKON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + NIKON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + NIKON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + NIKON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + NIKON_ADDRESS_OFFSET, // address_offset: address offset + NIKON_ADDRESS_OFFSET + NIKON_ADDRESS_LEN, // address_end: end of address + NIKON_COMMAND_OFFSET, // command_offset: command offset + NIKON_COMMAND_OFFSET + NIKON_COMMAND_LEN, // command_end: end of command + NIKON_COMPLETE_DATA_LEN, // complete_len: complete length of frame + NIKON_STOP_BIT, // stop_bit: flag: frame has stop bit + NIKON_LSB, // lsb_first: flag: LSB first + NIKON_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER kathrein_param = +{ + IRMP_KATHREIN_PROTOCOL, // protocol: ir protocol + KATHREIN_1_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + KATHREIN_1_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + KATHREIN_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + KATHREIN_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + KATHREIN_0_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + KATHREIN_0_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + KATHREIN_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + KATHREIN_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + KATHREIN_ADDRESS_OFFSET, // address_offset: address offset + KATHREIN_ADDRESS_OFFSET + KATHREIN_ADDRESS_LEN, // address_end: end of address + KATHREIN_COMMAND_OFFSET, // command_offset: command offset + KATHREIN_COMMAND_OFFSET + KATHREIN_COMMAND_LEN, // command_end: end of command + KATHREIN_COMPLETE_DATA_LEN, // complete_len: complete length of frame + KATHREIN_STOP_BIT, // stop_bit: flag: frame has stop bit + KATHREIN_LSB, // lsb_first: flag: LSB first + KATHREIN_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER netbox_param = +{ + IRMP_NETBOX_PROTOCOL, // protocol: ir protocol + NETBOX_PULSE_LEN, // pulse_1_len_min: minimum length of pulse with bit value 1, here: exact value + NETBOX_PULSE_REST_LEN, // pulse_1_len_max: maximum length of pulse with bit value 1, here: rest value + NETBOX_PAUSE_LEN, // pause_1_len_min: minimum length of pause with bit value 1, here: exact value + NETBOX_PAUSE_REST_LEN, // pause_1_len_max: maximum length of pause with bit value 1, here: rest value + NETBOX_PULSE_LEN, // pulse_0_len_min: minimum length of pulse with bit value 0, here: exact value + NETBOX_PULSE_REST_LEN, // pulse_0_len_max: maximum length of pulse with bit value 0, here: rest value + NETBOX_PAUSE_LEN, // pause_0_len_min: minimum length of pause with bit value 0, here: exact value + NETBOX_PAUSE_REST_LEN, // pause_0_len_max: maximum length of pause with bit value 0, here: rest value + NETBOX_ADDRESS_OFFSET, // address_offset: address offset + NETBOX_ADDRESS_OFFSET + NETBOX_ADDRESS_LEN, // address_end: end of address + NETBOX_COMMAND_OFFSET, // command_offset: command offset + NETBOX_COMMAND_OFFSET + NETBOX_COMMAND_LEN, // command_end: end of command + NETBOX_COMPLETE_DATA_LEN, // complete_len: complete length of frame + NETBOX_STOP_BIT, // stop_bit: flag: frame has stop bit + NETBOX_LSB, // lsb_first: flag: LSB first + NETBOX_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER lego_param = +{ + IRMP_LEGO_PROTOCOL, // protocol: ir protocol + LEGO_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + LEGO_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + LEGO_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + LEGO_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + LEGO_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + LEGO_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + LEGO_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + LEGO_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + LEGO_ADDRESS_OFFSET, // address_offset: address offset + LEGO_ADDRESS_OFFSET + LEGO_ADDRESS_LEN, // address_end: end of address + LEGO_COMMAND_OFFSET, // command_offset: command offset + LEGO_COMMAND_OFFSET + LEGO_COMMAND_LEN, // command_end: end of command + LEGO_COMPLETE_DATA_LEN, // complete_len: complete length of frame + LEGO_STOP_BIT, // stop_bit: flag: frame has stop bit + LEGO_LSB, // lsb_first: flag: LSB first + LEGO_FLAGS // flags: some flags +}; + +#endif + +#if IRMP_SUPPORT_THOMSON_PROTOCOL == 1 + +static const PROGMEM IRMP_PARAMETER thomson_param = +{ + IRMP_THOMSON_PROTOCOL, // protocol: ir protocol + THOMSON_PULSE_LEN_MIN, // pulse_1_len_min: minimum length of pulse with bit value 1 + THOMSON_PULSE_LEN_MAX, // pulse_1_len_max: maximum length of pulse with bit value 1 + THOMSON_1_PAUSE_LEN_MIN, // pause_1_len_min: minimum length of pause with bit value 1 + THOMSON_1_PAUSE_LEN_MAX, // pause_1_len_max: maximum length of pause with bit value 1 + THOMSON_PULSE_LEN_MIN, // pulse_0_len_min: minimum length of pulse with bit value 0 + THOMSON_PULSE_LEN_MAX, // pulse_0_len_max: maximum length of pulse with bit value 0 + THOMSON_0_PAUSE_LEN_MIN, // pause_0_len_min: minimum length of pause with bit value 0 + THOMSON_0_PAUSE_LEN_MAX, // pause_0_len_max: maximum length of pause with bit value 0 + THOMSON_ADDRESS_OFFSET, // address_offset: address offset + THOMSON_ADDRESS_OFFSET + THOMSON_ADDRESS_LEN, // address_end: end of address + THOMSON_COMMAND_OFFSET, // command_offset: command offset + THOMSON_COMMAND_OFFSET + THOMSON_COMMAND_LEN, // command_end: end of command + THOMSON_COMPLETE_DATA_LEN, // complete_len: complete length of frame + THOMSON_STOP_BIT, // stop_bit: flag: frame has stop bit + THOMSON_LSB, // lsb_first: flag: LSB first + THOMSON_FLAGS // flags: some flags +}; + +#endif + +static uint8_t irmp_bit; // current bit position +static IRMP_PARAMETER irmp_param; + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) +static IRMP_PARAMETER irmp_param2; +#endif + +static volatile uint8_t irmp_ir_detected; +static volatile uint8_t irmp_protocol; +static volatile uint16_t irmp_address; +static volatile uint16_t irmp_command; +static volatile uint16_t irmp_id; // only used for SAMSUNG protocol +static volatile uint8_t irmp_flags; +// static volatile uint8_t irmp_busy_flag; + +#ifdef ANALYZE +static uint8_t IRMP_PIN; +#endif + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Initialize IRMP decoder + * @details Configures IRMP input pin + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#ifndef ANALYZE +void +irmp_init(void) +{ +#ifndef ARDUINO +#if !defined(PIC_CCS_COMPILER) && !defined(PIC_C18) // only AVR + IRMP_PORT &= ~(1 << IRMP_BIT); // deactivate pullup + IRMP_DDR &= ~(1 << IRMP_BIT); // set pin to input +#endif + +#if IRMP_LOGGING == 1 + irmp_uart_init(); +#endif +#endif //ARDUINO +} +#endif +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Get IRMP data + * @details gets decoded IRMP data + * @param pointer in order to store IRMP data + * @return TRUE: successful, FALSE: failed + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +uint8_t +irmp_get_data(IRMP_DATA *irmp_data_p) +{ + uint8_t rtc = FALSE; + + if (irmp_ir_detected) + { + switch (irmp_protocol) + { +#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + case IRMP_SAMSUNG_PROTOCOL: + if ((irmp_command >> 8) == (~irmp_command & 0x00FF)) + { + irmp_command &= 0xff; + irmp_command |= irmp_id << 8; + rtc = TRUE; + } + break; +#endif +#if IRMP_SUPPORT_NEC_PROTOCOL == 1 + case IRMP_NEC_PROTOCOL: + if ((irmp_command >> 8) == (~irmp_command & 0x00FF)) + { + irmp_command &= 0xff; + rtc = TRUE; + } + else if (irmp_address == 0x87EE) + { + ANALYZE_PRINTF("Switching to APPLE protocol\n"); + irmp_protocol = IRMP_APPLE_PROTOCOL; + irmp_address = (irmp_command & 0xFF00) >> 8; + irmp_command &= 0x00FF; + rtc = TRUE; + } + break; +#endif +#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 + case IRMP_SIEMENS_PROTOCOL: + case IRMP_RUWIDO_PROTOCOL: + if (((irmp_command >> 1) & 0x0001) == (~irmp_command & 0x0001)) + { + irmp_command >>= 1; + rtc = TRUE; + } + break; +#endif +#if IRMP_SUPPORT_GRUNDIG2_PROTOCOL == 1 + case IRMP_GRUNDIG2_PROTOCOL: + if (irmp_command & 0x0001) + { + irmp_command >>= 1; + rtc = TRUE; + } + break; +#endif +#if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1 + case IRMP_KATHREIN_PROTOCOL: + if (irmp_command != 0x0000) + { + rtc = TRUE; + } + break; +#endif +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 + case IRMP_RC5_PROTOCOL: + irmp_address &= ~0x20; // clear toggle bit + rtc = TRUE; + break; +#endif +#if IRMP_SUPPORT_IR60_PROTOCOL == 1 + case IRMP_IR60_PROTOCOL: + if (irmp_command != 0x007d) // 0x007d (== 62<<1 + 1) is start instruction frame + { + rtc = TRUE; + } + break; +#endif +#if IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + case IRMP_RCCAR_PROTOCOL: + // frame in irmp_data: + // Bit 12 11 10 9 8 7 6 5 4 3 2 1 0 + // V D7 D6 D5 D4 D3 D2 D1 D0 A1 A0 C1 C0 // 10 9 8 7 6 5 4 3 2 1 0 + irmp_address = (irmp_command & 0x000C) >> 2; // addr: 0 0 0 0 0 0 0 0 0 A1 A0 + irmp_command = ((irmp_command & 0x1000) >> 2) | // V-Bit: V 0 0 0 0 0 0 0 0 0 0 + ((irmp_command & 0x0003) << 8) | // C-Bits: 0 C1 C0 0 0 0 0 0 0 0 0 + ((irmp_command & 0x0FF0) >> 4); // D-Bits: D7 D6 D5 D4 D3 D2 D1 D0 + rtc = TRUE; // Summe: V C1 C0 D7 D6 D5 D4 D3 D2 D1 D0 + break; +#endif + +#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 // squeeze code to 8 bit, upper bit indicates release-key + case IRMP_NETBOX_PROTOCOL: + if (irmp_command & 0x1000) // last bit set? + { + if ((irmp_command & 0x1f) == 0x15) // key pressed: 101 01 (LSB) + { + irmp_command >>= 5; + irmp_command &= 0x7F; + rtc = TRUE; + } + else if ((irmp_command & 0x1f) == 0x10) // key released: 000 01 (LSB) + { + irmp_command >>= 5; + irmp_command |= 0x80; + rtc = TRUE; + } + else + { + ANALYZE_PRINTF("error NETBOX: bit6/7 must be 0/1\n"); + } + } + else + { + ANALYZE_PRINTF("error NETBOX: last bit not set\n"); + } + break; +#endif +#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 + case IRMP_LEGO_PROTOCOL: + { + uint8_t crc = 0x0F ^ ((irmp_command & 0xF000) >> 12) ^ ((irmp_command & 0x0F00) >> 8) ^ ((irmp_command & 0x00F0) >> 4); + + if ((irmp_command & 0x000F) == crc) + { + irmp_command >>= 4; + rtc = TRUE; + } + else + { + ANALYZE_PRINTF("CRC error in LEGO protocol\n"); + rtc = TRUE; + } + break; + } +#endif + default: + rtc = TRUE; + } + + if (rtc) + { + irmp_data_p->protocol = irmp_protocol; + irmp_data_p->address = irmp_address; + irmp_data_p->command = irmp_command; + irmp_data_p->flags = irmp_flags; + irmp_command = 0; + irmp_address = 0; + irmp_flags = 0; + } + + irmp_ir_detected = FALSE; + } + + return rtc; +} + +// uint8_t +// irmp_is_busy (void) +// { +// return irmp_busy_flag; +// } + +#if IRMP_USE_CALLBACK == 1 +void +irmp_set_callback_ptr(void (*cb)(uint8_t)) +{ + irmp_callback_ptr = cb; +} +#endif // IRMP_USE_CALLBACK == 1 + +// these statics must not be volatile, because they are only used by irmp_store_bit(), which is called by irmp_ISR() +static uint16_t irmp_tmp_address; // ir address +static uint16_t irmp_tmp_command; // ir command + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1 +static uint16_t irmp_tmp_address2; // ir address +static uint16_t irmp_tmp_command2; // ir command +#endif + +#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 +static uint16_t irmp_tmp_id; // ir id (only SAMSUNG) +#endif +#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 +static uint8_t xor_check[6]; // check kaseikyo "parity" bits +static uint8_t genre2; // save genre2 bits here, later copied to MSB in flags +#endif + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * store bit + * @details store bit in temp address or temp command + * @param value to store: 0 or 1 + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +// verhindert, dass irmp_store_bit() inline compiliert wird: +// static void irmp_store_bit (uint8_t) __attribute__ ((noinline)); + +static void +irmp_store_bit(uint8_t value) +{ +#if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 + if (irmp_bit == 0 && irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL) + { + first_bit = value; + } + else +#endif + + if (irmp_bit >= irmp_param.address_offset && irmp_bit < irmp_param.address_end) + { + if (irmp_param.lsb_first) + { + irmp_tmp_address |= (((uint16_t)(value)) << (irmp_bit - irmp_param.address_offset)); // CV wants cast + } + else + { + irmp_tmp_address <<= 1; + irmp_tmp_address |= value; + } + } + else if (irmp_bit >= irmp_param.command_offset && irmp_bit < irmp_param.command_end) + { + if (irmp_param.lsb_first) + { + irmp_tmp_command |= (((uint16_t)(value)) << (irmp_bit - irmp_param.command_offset)); // CV wants cast + } + else + { + irmp_tmp_command <<= 1; + irmp_tmp_command |= value; + } + } + +#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 + else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit >= 13 && irmp_bit < 26) + { + irmp_tmp_address2 |= (((uint16_t)(value)) << (irmp_bit - 13)); // CV wants cast + } +#endif + +#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + else if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit >= SAMSUNG_ID_OFFSET && irmp_bit < SAMSUNG_ID_OFFSET + SAMSUNG_ID_LEN) + { + irmp_tmp_id |= (((uint16_t)(value)) << (irmp_bit - SAMSUNG_ID_OFFSET)); // store with LSB first + } +#endif + +#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 + else if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL) + { + if (irmp_bit >= 20 && irmp_bit < 24) + { + irmp_tmp_command |= (((uint16_t)(value)) << (irmp_bit - 8)); // store 4 system bits (genre 1) in upper nibble with LSB first + } + else if (irmp_bit >= 24 && irmp_bit < 28) + { + genre2 |= (((uint8_t)(value)) << (irmp_bit - 20)); // store 4 system bits (genre 2) in upper nibble with LSB first + } + + if (irmp_bit < KASEIKYO_COMPLETE_DATA_LEN) + { + if (value) + { + xor_check[irmp_bit / 8] |= 1 << (irmp_bit % 8); + } + else + { + xor_check[irmp_bit / 8] &= ~(1 << (irmp_bit % 8)); + } + } + } +#endif + + irmp_bit++; +} + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * store bit + * @details store bit in temp address or temp command + * @param value to store: 0 or 1 + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) +static void +irmp_store_bit2(uint8_t value) +{ + uint8_t irmp_bit2; + + if (irmp_param.protocol) + { + irmp_bit2 = irmp_bit - 2; + } + else + { + irmp_bit2 = irmp_bit - 1; + } + + if (irmp_bit2 >= irmp_param2.address_offset && irmp_bit2 < irmp_param2.address_end) + { + irmp_tmp_address2 |= (((uint16_t)(value)) << (irmp_bit2 - irmp_param2.address_offset)); // CV wants cast + } + else if (irmp_bit2 >= irmp_param2.command_offset && irmp_bit2 < irmp_param2.command_end) + { + irmp_tmp_command2 |= (((uint16_t)(value)) << (irmp_bit2 - irmp_param2.command_offset)); // CV wants cast + } +} +#endif // IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * ISR routine + * @details ISR routine, called 10000 times per second + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +uint8_t +irmp_ISR(uint8_t x42) +{ + static uint8_t irmp_start_bit_detected; // flag: start bit detected + static uint8_t wait_for_space; // flag: wait for data bit space + static uint8_t wait_for_start_space; // flag: wait for start bit space + static uint8_t irmp_pulse_time; // count bit time for pulse + static PAUSE_LEN irmp_pause_time; // count bit time for pause + static uint16_t last_irmp_address = 0xFFFF; // save last irmp address to recognize key repetition + static uint16_t last_irmp_command = 0xFFFF; // save last irmp command to recognize key repetition + static uint16_t repetition_len; // SIRCS repeats frame 2-5 times with 45 ms pause + static uint8_t repetition_frame_number; +#if IRMP_SUPPORT_DENON_PROTOCOL == 1 + static uint16_t last_irmp_denon_command; // save last irmp command to recognize DENON frame repetition +#endif +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 + static uint8_t rc5_cmd_bit6; // bit 6 of RC5 command is the inverted 2nd start bit +#endif +#if IRMP_SUPPORT_MANCHESTER == 1 + static PAUSE_LEN last_pause; // last pause value +#endif +#if IRMP_SUPPORT_MANCHESTER == 1 || IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 + static uint8_t last_value; // last bit value +#endif + uint8_t irmp_input; // input value + +#ifdef ANALYZE + time_counter++; +#endif + + irmp_input = input(x42); + +#if IRMP_USE_CALLBACK == 1 + if (irmp_callback_ptr) + { + static uint8_t last_inverted_input; + + if (last_inverted_input != !irmp_input) + { + (*irmp_callback_ptr)(! irmp_input); + last_inverted_input = !irmp_input; + } + } +#endif // IRMP_USE_CALLBACK == 1 + + irmp_log(irmp_input); // log ir signal, if IRMP_LOGGING defined + + if (! irmp_ir_detected) // ir code already detected? + { + // no... + if (! irmp_start_bit_detected) // start bit detected? + { + // no... + if (! irmp_input) // receiving burst? + { + // yes... +// irmp_busy_flag = TRUE; +#ifdef ANALYZE + if (! irmp_pulse_time) + { + ANALYZE_PRINTF("%8.3fms [starting pulse]\n", (double)(time_counter * 1000) / F_INTERRUPTS); + } +#endif + irmp_pulse_time++; // increment counter + } + else + { + // no... + if (irmp_pulse_time) // it's dark.... + { + // set flags for counting the time of darkness... + irmp_start_bit_detected = 1; + wait_for_start_space = 1; + wait_for_space = 0; + irmp_tmp_command = 0; + irmp_tmp_address = 0; +#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 + genre2 = 0; +#endif + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) || IRMP_SUPPORT_NEC42_PROTOCOL == 1 + irmp_tmp_command2 = 0; + irmp_tmp_address2 = 0; +#endif + + irmp_bit = 0xff; + irmp_pause_time = 1; // 1st pause: set to 1, not to 0! +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 + rc5_cmd_bit6 = 0; // fm 2010-03-07: bugfix: reset it after incomplete RC5 frame! +#endif + } + else + { + if (repetition_len < 0xFFFF) // avoid overflow of counter + { + repetition_len++; + } + } + } + } + else + { + if (wait_for_start_space) // we have received start bit... + { + // ...and are counting the time of darkness + if (irmp_input) // still dark? + { + // yes + irmp_pause_time++; // increment counter + +#if IRMP_SUPPORT_NIKON_PROTOCOL == 1 + if (((irmp_pulse_time < NIKON_START_BIT_PULSE_LEN_MIN || irmp_pulse_time > NIKON_START_BIT_PULSE_LEN_MAX) && irmp_pause_time > IRMP_TIMEOUT_LEN) || + irmp_pause_time > IRMP_TIMEOUT_NIKON_LEN) +#else + if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout? +#endif + { + // yes... +#if IRMP_SUPPORT_JVC_PROTOCOL == 1 + if (irmp_protocol == IRMP_JVC_PROTOCOL) // don't show eror if JVC protocol, irmp_pulse_time has been set below! + { + ; + } + else +#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 + { + ANALYZE_PRINTF("%8.3fms error 1: pause after start bit pulse %d too long: %d\n", (double)(time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time); + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); + } +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // reset flags, let's wait for another start bit + irmp_pulse_time = 0; + irmp_pause_time = 0; + } + } + else + { + // receiving first data pulse! + IRMP_PARAMETER *irmp_param_p = (IRMP_PARAMETER *) 0; + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) + irmp_param2.protocol = 0; +#endif + + ANALYZE_PRINTF("%8.3fms [start-bit: pulse = %2d, pause = %2d]\n", (double)(time_counter * 1000) / F_INTERRUPTS, irmp_pulse_time, irmp_pause_time); + +#if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 + if (irmp_pulse_time >= SIRCS_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIRCS_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= SIRCS_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIRCS_START_BIT_PAUSE_LEN_MAX) + { + // it's SIRCS + ANALYZE_PRINTF("protocol = SIRCS, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX, + SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *)(IRMP_PARAMETER *) &sircs_param; + } + else +#endif // IRMP_SUPPORT_SIRCS_PROTOCOL == 1 + +#if IRMP_SUPPORT_JVC_PROTOCOL == 1 + if (irmp_protocol == IRMP_JVC_PROTOCOL && // last protocol was JVC, awaiting repeat frame + irmp_pulse_time >= JVC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= JVC_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= JVC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= JVC_REPEAT_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("protocol = NEC or JVC (type 1) repeat frame, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + JVC_START_BIT_PULSE_LEN_MIN, JVC_START_BIT_PULSE_LEN_MAX, + JVC_REPEAT_START_BIT_PAUSE_LEN_MIN, JVC_REPEAT_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &nec_param; + } + else +#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 + +#if IRMP_SUPPORT_NEC_PROTOCOL == 1 + if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX) + { +#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 + ANALYZE_PRINTF("protocol = NEC42, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, + NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &nec42_param; +#else + ANALYZE_PRINTF("protocol = NEC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, + NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &nec_param; +#endif + + } + else if (irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= NEC_REPEAT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_REPEAT_START_BIT_PAUSE_LEN_MAX) + { + // it's NEC +#if IRMP_SUPPORT_JVC_PROTOCOL == 1 + if (irmp_protocol == IRMP_JVC_PROTOCOL) // last protocol was JVC, awaiting repeat frame + { + // some jvc remote controls use nec repetition frame for jvc repetition frame + ANALYZE_PRINTF("protocol = JVC repeat frame type 2, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, + NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &nec_param; + } + else +#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 + { + ANALYZE_PRINTF("protocol = NEC (repetition frame), start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, + NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX); + + irmp_param_p = (IRMP_PARAMETER *) &nec_rep_param; + } + } + else + +#if IRMP_SUPPORT_JVC_PROTOCOL == 1 + if (irmp_protocol == IRMP_JVC_PROTOCOL && // last protocol was JVC, awaiting repeat frame + irmp_pulse_time >= NEC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NEC_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= NEC_0_PAUSE_LEN_MIN && irmp_pause_time <= NEC_0_PAUSE_LEN_MAX) + { + // it's JVC repetition type 3 + ANALYZE_PRINTF("protocol = JVC repeat frame type 3, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, + NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &nec_param; + } + else +#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 + +#endif // IRMP_SUPPORT_NEC_PROTOCOL == 1 + +#if IRMP_SUPPORT_NIKON_PROTOCOL == 1 + if (irmp_pulse_time >= NIKON_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NIKON_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= NIKON_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NIKON_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("protocol = NIKON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX, + NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &nikon_param; + } + else +#endif // IRMP_SUPPORT_NIKON_PROTOCOL == 1 + +#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + if (irmp_pulse_time >= SAMSUNG_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX) + { + // it's SAMSUNG + ANALYZE_PRINTF("protocol = SAMSUNG, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX, + SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &samsung_param; + } + else +#endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + +#if IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1 + if (irmp_pulse_time >= MATSUSHITA_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= MATSUSHITA_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= MATSUSHITA_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= MATSUSHITA_START_BIT_PAUSE_LEN_MAX) + { + // it's MATSUSHITA + ANALYZE_PRINTF("protocol = MATSUSHITA, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX, + MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &matsushita_param; + } + else +#endif // IRMP_SUPPORT_MATSUSHITA_PROTOCOL == 1 + +#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 + if (irmp_pulse_time >= KASEIKYO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KASEIKYO_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= KASEIKYO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KASEIKYO_START_BIT_PAUSE_LEN_MAX) + { + // it's KASEIKYO + ANALYZE_PRINTF("protocol = KASEIKYO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX, + KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &kaseikyo_param; + } + else +#endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 + +#if IRMP_SUPPORT_RECS80_PROTOCOL == 1 + if (irmp_pulse_time >= RECS80_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= RECS80_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80_START_BIT_PAUSE_LEN_MAX) + { + // it's RECS80 + ANALYZE_PRINTF("protocol = RECS80, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX, + RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &recs80_param; + } + else +#endif // IRMP_SUPPORT_RECS80_PROTOCOL == 1 + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 + if (((irmp_pulse_time >= RC5_START_BIT_LEN_MIN && irmp_pulse_time <= RC5_START_BIT_LEN_MAX) || + (irmp_pulse_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX)) && + ((irmp_pause_time >= RC5_START_BIT_LEN_MIN && irmp_pause_time <= RC5_START_BIT_LEN_MAX) || + (irmp_pause_time >= 2 * RC5_START_BIT_LEN_MIN && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX))) + { + // it's RC5 +#if IRMP_SUPPORT_FDC_PROTOCOL == 1 + if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("protocol = RC5 or FDC\n"); + ANALYZE_PRINTF("FDC start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, + FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX); + ANALYZE_PRINTF("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, + RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX); + memcpy_P(&irmp_param2, &fdc_param, sizeof(IRMP_PARAMETER)); + } + else +#endif // IRMP_SUPPORT_FDC_PROTOCOL == 1 + +#if IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("protocol = RC5 or RCCAR\n"); + ANALYZE_PRINTF("RCCAR start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, + RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX); + ANALYZE_PRINTF("RC5 start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, + RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX); + memcpy_P(&irmp_param2, &rccar_param, sizeof(IRMP_PARAMETER)); + } + else +#endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + { + ANALYZE_PRINTF("protocol = RC5, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or pulse: %3d - %3d, pause: %3d - %3d\n", + RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, + 2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX, + RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, + 2 * RC5_START_BIT_LEN_MIN, 2 * RC5_START_BIT_LEN_MAX); + } + + irmp_param_p = (IRMP_PARAMETER *) &rc5_param; + last_pause = irmp_pause_time; + + if ((irmp_pulse_time > RC5_START_BIT_LEN_MAX && irmp_pulse_time <= 2 * RC5_START_BIT_LEN_MAX) || + (irmp_pause_time > RC5_START_BIT_LEN_MAX && irmp_pause_time <= 2 * RC5_START_BIT_LEN_MAX)) + { + last_value = 0; + rc5_cmd_bit6 = 1 << 6; + } + else + { + last_value = 1; + } + } + else +#endif // IRMP_SUPPORT_RC5_PROTOCOL == 1 + +#if IRMP_SUPPORT_DENON_PROTOCOL == 1 + if ((irmp_pulse_time >= DENON_PULSE_LEN_MIN && irmp_pulse_time <= DENON_PULSE_LEN_MAX) && + ((irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) || + (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX))) + { + // it's DENON + ANALYZE_PRINTF("protocol = DENON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n", + DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, + DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX, + DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &denon_param; + } + else +#endif // IRMP_SUPPORT_DENON_PROTOCOL == 1 + +#if IRMP_SUPPORT_THOMSON_PROTOCOL == 1 + if ((irmp_pulse_time >= THOMSON_PULSE_LEN_MIN && irmp_pulse_time <= THOMSON_PULSE_LEN_MAX) && + ((irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX) || + (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX))) + { + // it's THOMSON + ANALYZE_PRINTF("protocol = THOMSON, start bit timings: pulse: %3d - %3d, pause: %3d - %3d or %3d - %3d\n", + THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, + THOMSON_1_PAUSE_LEN_MIN, THOMSON_1_PAUSE_LEN_MAX, + THOMSON_0_PAUSE_LEN_MIN, THOMSON_0_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &thomson_param; + } + else +#endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1 + +#if IRMP_SUPPORT_RC6_PROTOCOL == 1 + if (irmp_pulse_time >= RC6_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RC6_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= RC6_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RC6_START_BIT_PAUSE_LEN_MAX) + { + // it's RC6 + ANALYZE_PRINTF("protocol = RC6, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX, + RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &rc6_param; + last_pause = 0; + last_value = 1; + } + else +#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 + +#if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1 + if (irmp_pulse_time >= RECS80EXT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RECS80EXT_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= RECS80EXT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RECS80EXT_START_BIT_PAUSE_LEN_MAX) + { + // it's RECS80EXT + ANALYZE_PRINTF("protocol = RECS80EXT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX, + RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &recs80ext_param; + } + else +#endif // IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1 + +#if IRMP_SUPPORT_NUBERT_PROTOCOL == 1 + if (irmp_pulse_time >= NUBERT_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NUBERT_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= NUBERT_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NUBERT_START_BIT_PAUSE_LEN_MAX) + { + // it's NUBERT + ANALYZE_PRINTF("protocol = NUBERT, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX, + NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &nubert_param; + } + else +#endif // IRMP_SUPPORT_NUBERT_PROTOCOL == 1 + +#if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 + if (irmp_pulse_time >= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX && + irmp_pause_time >= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX) + { + // it's BANG_OLUFSEN + ANALYZE_PRINTF("protocol = BANG_OLUFSEN\n"); + ANALYZE_PRINTF("start bit 1 timings: pulse: %3d - %3d, pause: %3d - %3d\n", + BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX, + BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX); + ANALYZE_PRINTF("start bit 2 timings: pulse: %3d - %3d, pause: %3d - %3d\n", + BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX, + BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX); + ANALYZE_PRINTF("start bit 3 timings: pulse: %3d - %3d, pause: %3d - %3d\n", + BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX, + BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX); + ANALYZE_PRINTF("start bit 4 timings: pulse: %3d - %3d, pause: %3d - %3d\n", + BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX, + BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &bang_olufsen_param; + last_value = 0; + } + else +#endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 + +#if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 + if (irmp_pulse_time >= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN && irmp_pulse_time <= GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX && + irmp_pause_time >= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX) + { + // it's GRUNDIG + ANALYZE_PRINTF("protocol = GRUNDIG, pre bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX, + GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &grundig_param; + last_pause = irmp_pause_time; + last_value = 1; + } + else +#endif // IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 + +#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 + if (((irmp_pulse_time >= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX) || + (irmp_pulse_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX)) && + ((irmp_pause_time >= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX) || + (irmp_pause_time >= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX))) + { + // it's RUWIDO or SIEMENS + ANALYZE_PRINTF("protocol = RUWIDO, start bit timings: pulse: %3d - %3d or %3d - %3d, pause: %3d - %3d or %3d - %3d\n", + SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX, + 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX, + SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX, + 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &ruwido_param; + last_pause = irmp_pause_time; + last_value = 1; + } + else +#endif // IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 + +#if IRMP_SUPPORT_GRUNDIG2_PROTOCOL == 1 + if ((irmp_pulse_time >= GRUNDIG2_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= GRUNDIG2_START_BIT_PULSE_LEN_MAX) && + (irmp_pause_time >= GRUNDIG2_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= GRUNDIG2_START_BIT_PAUSE_LEN_MAX)) + { + // it's GRUNDIG2 + ANALYZE_PRINTF("protocol = GRUNDIG2, start bit timings: pulse: %3d - %3d or %3d - %3d, pause: %3d - %3d or %3d - %3d\n", + GRUNDIG2_START_BIT_PULSE_LEN_MIN, GRUNDIG2_START_BIT_PULSE_LEN_MAX, + 2 * GRUNDIG2_START_BIT_PULSE_LEN_MIN, 2 * GRUNDIG2_START_BIT_PULSE_LEN_MAX, + GRUNDIG2_START_BIT_PAUSE_LEN_MIN, GRUNDIG2_START_BIT_PAUSE_LEN_MAX, + 2 * GRUNDIG2_START_BIT_PAUSE_LEN_MIN, 2 * GRUNDIG2_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &grundig2_param; + last_pause = irmp_pause_time; + last_value = 1; + } + else +#endif // IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 + +#if IRMP_SUPPORT_FDC_PROTOCOL == 1 + if (irmp_pulse_time >= FDC_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= FDC_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= FDC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= FDC_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("protocol = FDC, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, + FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &fdc_param; + } + else +#endif // IRMP_SUPPORT_FDC_PROTOCOL == 1 + +#if IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + if (irmp_pulse_time >= RCCAR_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= RCCAR_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("protocol = RCCAR, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, + RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &rccar_param; + } + else +#endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + +#if IRMP_SUPPORT_KATHREIN_PROTOCOL == 1 + if (irmp_pulse_time >= KATHREIN_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX) + { + // it's KATHREIN + ANALYZE_PRINTF("protocol = KATHREIN, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + KATHREIN_START_BIT_PULSE_LEN_MIN, KATHREIN_START_BIT_PULSE_LEN_MAX, + KATHREIN_START_BIT_PAUSE_LEN_MIN, KATHREIN_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &kathrein_param; + } + else +#endif // IRMP_SUPPORT_KATHREIN_PROTOCOL == 1 + +#if IRMP_SUPPORT_NETBOX_PROTOCOL == 1 + if (irmp_pulse_time >= NETBOX_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= NETBOX_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= NETBOX_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NETBOX_START_BIT_PAUSE_LEN_MAX) + { + // it's NETBOX + ANALYZE_PRINTF("protocol = NETBOX, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + NETBOX_START_BIT_PULSE_LEN_MIN, NETBOX_START_BIT_PULSE_LEN_MAX, + NETBOX_START_BIT_PAUSE_LEN_MIN, NETBOX_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &netbox_param; + } + else +#endif // IRMP_SUPPORT_NETBOX_PROTOCOL == 1 + +#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 + if (irmp_pulse_time >= LEGO_START_BIT_PULSE_LEN_MIN && irmp_pulse_time <= LEGO_START_BIT_PULSE_LEN_MAX && + irmp_pause_time >= LEGO_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= LEGO_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("protocol = LEGO, start bit timings: pulse: %3d - %3d, pause: %3d - %3d\n", + LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX, + LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX); + irmp_param_p = (IRMP_PARAMETER *) &lego_param; + } + else +#endif // IRMP_SUPPORT_LEGO_PROTOCOL == 1 + + { + ANALYZE_PRINTF("protocol = UNKNOWN\n"); +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // wait for another start bit... + } + + if (irmp_start_bit_detected) + { + memcpy_P(&irmp_param, irmp_param_p, sizeof(IRMP_PARAMETER)); + +#ifdef ANALYZE + if (!(irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) + { + ANALYZE_PRINTF("pulse_1: %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max); + ANALYZE_PRINTF("pause_1: %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max); + } + else + { + ANALYZE_PRINTF("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_1_len_min, irmp_param.pulse_1_len_max, + 2 * irmp_param.pulse_1_len_min, 2 * irmp_param.pulse_1_len_max); + ANALYZE_PRINTF("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_1_len_min, irmp_param.pause_1_len_max, + 2 * irmp_param.pause_1_len_min, 2 * irmp_param.pause_1_len_max); + } + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) + if (irmp_param2.protocol) + { + ANALYZE_PRINTF("pulse_0: %3d - %3d\n", irmp_param2.pulse_0_len_min, irmp_param2.pulse_0_len_max); + ANALYZE_PRINTF("pause_0: %3d - %3d\n", irmp_param2.pause_0_len_min, irmp_param2.pause_0_len_max); + ANALYZE_PRINTF("pulse_1: %3d - %3d\n", irmp_param2.pulse_1_len_min, irmp_param2.pulse_1_len_max); + ANALYZE_PRINTF("pause_1: %3d - %3d\n", irmp_param2.pause_1_len_min, irmp_param2.pause_1_len_max); + } +#endif + + +#if IRMP_SUPPORT_RC6_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_RC6_PROTOCOL) + { + ANALYZE_PRINTF("pulse_toggle: %3d - %3d\n", RC6_TOGGLE_BIT_LEN_MIN, RC6_TOGGLE_BIT_LEN_MAX); + } +#endif + + if (!(irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) + { + ANALYZE_PRINTF("pulse_0: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max); + ANALYZE_PRINTF("pause_0: %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max); + } + else + { + ANALYZE_PRINTF("pulse: %3d - %3d or %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max, + 2 * irmp_param.pulse_0_len_min, 2 * irmp_param.pulse_0_len_max); + ANALYZE_PRINTF("pause: %3d - %3d or %3d - %3d\n", irmp_param.pause_0_len_min, irmp_param.pause_0_len_max, + 2 * irmp_param.pause_0_len_min, 2 * irmp_param.pause_0_len_max); + } + +#if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL) + { + ANALYZE_PRINTF("pulse_r: %3d - %3d\n", irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max); + ANALYZE_PRINTF("pause_r: %3d - %3d\n", BANG_OLUFSEN_R_PAUSE_LEN_MIN, BANG_OLUFSEN_R_PAUSE_LEN_MAX); + } +#endif + + ANALYZE_PRINTF("command_offset: %2d\n", irmp_param.command_offset); + ANALYZE_PRINTF("command_len: %3d\n", irmp_param.command_end - irmp_param.command_offset); + ANALYZE_PRINTF("complete_len: %3d\n", irmp_param.complete_len); + ANALYZE_PRINTF("stop_bit: %3d\n", irmp_param.stop_bit); +#endif // ANALYZE + } + + irmp_bit = 0; + +#if IRMP_SUPPORT_MANCHESTER == 1 + if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) && + irmp_param.protocol != IRMP_RUWIDO_PROTOCOL && // Manchester, but not RUWIDO + irmp_param.protocol != IRMP_RC6_PROTOCOL) // Manchester, but not RC6 + { + if (irmp_pause_time > irmp_param.pulse_1_len_max && irmp_pause_time <= 2 * irmp_param.pulse_1_len_max) + { + ANALYZE_PRINTF("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double)(time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_PUTCHAR((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1'); + ANALYZE_NEWLINE(); + irmp_store_bit((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1); + } + else if (! last_value) // && irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max) + { + ANALYZE_PRINTF("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double)(time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); + + ANALYZE_PUTCHAR((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0'); + ANALYZE_NEWLINE(); + irmp_store_bit((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0); + } + } + else +#endif // IRMP_SUPPORT_MANCHESTER == 1 + +#if IRMP_SUPPORT_SERIAL == 1 + if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) + { + ; // do nothing + } + else +#endif // IRMP_SUPPORT_SERIAL == 1 + + +#if IRMP_SUPPORT_DENON_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_DENON_PROTOCOL) + { + ANALYZE_PRINTF("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double)(time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); + + if (irmp_pause_time >= DENON_1_PAUSE_LEN_MIN && irmp_pause_time <= DENON_1_PAUSE_LEN_MAX) + { + // pause timings correct for "1"? + ANALYZE_PUTCHAR('1'); // yes, store 1 + ANALYZE_NEWLINE(); + irmp_store_bit(1); + } + else // if (irmp_pause_time >= DENON_0_PAUSE_LEN_MIN && irmp_pause_time <= DENON_0_PAUSE_LEN_MAX) + { + // pause timings correct for "0"? + ANALYZE_PUTCHAR('0'); // yes, store 0 + ANALYZE_NEWLINE(); + irmp_store_bit(0); + } + } + else +#endif // IRMP_SUPPORT_DENON_PROTOCOL == 1 +#if IRMP_SUPPORT_THOMSON_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_THOMSON_PROTOCOL) + { + ANALYZE_PRINTF("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double)(time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); + + if (irmp_pause_time >= THOMSON_1_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_1_PAUSE_LEN_MAX) + { + // pause timings correct for "1"? + ANALYZE_PUTCHAR('1'); // yes, store 1 + ANALYZE_NEWLINE(); + irmp_store_bit(1); + } + else // if (irmp_pause_time >= THOMSON_0_PAUSE_LEN_MIN && irmp_pause_time <= THOMSON_0_PAUSE_LEN_MAX) + { + // pause timings correct for "0"? + ANALYZE_PUTCHAR('0'); // yes, store 0 + ANALYZE_NEWLINE(); + irmp_store_bit(0); + } + } + else +#endif // IRMP_SUPPORT_THOMSON_PROTOCOL == 1 + { + ; // else do nothing + } + + irmp_pulse_time = 1; // set counter to 1, not 0 + irmp_pause_time = 0; + wait_for_start_space = 0; + } + } + else if (wait_for_space) // the data section.... + { + // counting the time of darkness.... + uint8_t got_light = FALSE; + + if (irmp_input) // still dark? + { + // yes... + if (irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 1) + { + if ( +#if IRMP_SUPPORT_MANCHESTER == 1 + (irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) || +#endif +#if IRMP_SUPPORT_SERIAL == 1 + (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) || +#endif + (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max)) + { +#ifdef ANALYZE + if (!(irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) + { + ANALYZE_PRINTF("stop bit detected\n"); + } +#endif + irmp_param.stop_bit = 0; + } + else + { + ANALYZE_PRINTF("error: stop bit timing wrong, irmp_bit = %d, irmp_pulse_time = %d, pulse_0_len_min = %d, pulse_0_len_max = %d\n", + irmp_bit, irmp_pulse_time, irmp_param.pulse_0_len_min, irmp_param.pulse_0_len_max); + +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // wait for another start bit... + irmp_pulse_time = 0; + irmp_pause_time = 0; + } + } + else + { + irmp_pause_time++; // increment counter + +#if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && // Sony has a variable number of bits: + irmp_pause_time > SIRCS_PAUSE_LEN_MAX && // minimum is 12 + irmp_bit >= 12 - 1) // pause too long? + { + // yes, break and close this frame + irmp_param.complete_len = irmp_bit + 1; // set new complete length + got_light = TRUE; // this is a lie, but helps (generates stop bit) + irmp_tmp_address |= (irmp_bit - SIRCS_MINIMUM_DATA_LEN + 1) << 8; // new: store number of additional bits in upper byte of address! + irmp_param.command_end = irmp_param.command_offset + irmp_bit + 1; // correct command length + irmp_pause_time = SIRCS_PAUSE_LEN_MAX - 1; // correct pause length + } + else +#endif +#if IRMP_SUPPORT_SERIAL == 1 + // NETBOX generates no stop bit, here is the timeout condition: + if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) && irmp_param.protocol == IRMP_NETBOX_PROTOCOL && + irmp_pause_time >= NETBOX_PULSE_LEN * (NETBOX_COMPLETE_DATA_LEN - irmp_bit)) + { + got_light = TRUE; // this is a lie, but helps (generates stop bit) + } + else +#endif +#if IRMP_SUPPORT_GRUNDIG_NOKIA_IR60_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && !irmp_param.stop_bit) + { + if (irmp_pause_time > IR60_TIMEOUT_LEN && irmp_bit == 6) + { + ANALYZE_PRINTF("Switching to IR60 protocol\n"); + got_light = TRUE; // this is a lie, but generates a stop bit ;-) + irmp_param.stop_bit = TRUE; // set flag + + irmp_param.protocol = IRMP_IR60_PROTOCOL; // change protocol + irmp_param.complete_len = IR60_COMPLETE_DATA_LEN; // correct complete len + irmp_param.address_offset = IR60_ADDRESS_OFFSET; + irmp_param.address_end = IR60_ADDRESS_OFFSET + IR60_ADDRESS_LEN; + irmp_param.command_offset = IR60_COMMAND_OFFSET; + irmp_param.command_end = IR60_COMMAND_OFFSET + IR60_COMMAND_LEN; + + irmp_tmp_command <<= 1; + irmp_tmp_command |= first_bit; + } + else if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN - 2) + { + // special manchester decoder + irmp_param.complete_len = GRUNDIG_COMPLETE_DATA_LEN; // correct complete len + got_light = TRUE; // this is a lie, but generates a stop bit ;-) + irmp_param.stop_bit = TRUE; // set flag + } + else if (irmp_bit >= GRUNDIG_COMPLETE_DATA_LEN) + { + ANALYZE_PRINTF("Switching to NOKIA protocol\n"); + irmp_param.protocol = IRMP_NOKIA_PROTOCOL; // change protocol + irmp_param.address_offset = NOKIA_ADDRESS_OFFSET; + irmp_param.address_end = NOKIA_ADDRESS_OFFSET + NOKIA_ADDRESS_LEN; + irmp_param.command_offset = NOKIA_COMMAND_OFFSET; + irmp_param.command_end = NOKIA_COMMAND_OFFSET + NOKIA_COMMAND_LEN; + + if (irmp_tmp_command & 0x300) + { + irmp_tmp_address = (irmp_tmp_command >> 8); + irmp_tmp_command &= 0xFF; + } + } + } + else +#endif +#if IRMP_SUPPORT_SIEMENS_OR_RUWIDO_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_RUWIDO_PROTOCOL && !irmp_param.stop_bit) + { + if (irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= RUWIDO_COMPLETE_DATA_LEN - 2) + { + // special manchester decoder + irmp_param.complete_len = RUWIDO_COMPLETE_DATA_LEN; // correct complete len + got_light = TRUE; // this is a lie, but generates a stop bit ;-) + irmp_param.stop_bit = TRUE; // set flag + } + else if (irmp_bit >= RUWIDO_COMPLETE_DATA_LEN) + { + ANALYZE_PRINTF("Switching to SIEMENS protocol\n"); + irmp_param.protocol = IRMP_SIEMENS_PROTOCOL; // change protocol + irmp_param.address_offset = SIEMENS_ADDRESS_OFFSET; + irmp_param.address_end = SIEMENS_ADDRESS_OFFSET + SIEMENS_ADDRESS_LEN; + irmp_param.command_offset = SIEMENS_COMMAND_OFFSET; + irmp_param.command_end = SIEMENS_COMMAND_OFFSET + SIEMENS_COMMAND_LEN; + + // 76543210 + // RUWIDO: AAAAAAAAACCCCCCCp + // SIEMENS: AAAAAAAAAAACCCCCCCCCCp + irmp_tmp_address <<= 2; + irmp_tmp_address |= (irmp_tmp_command >> 6); + irmp_tmp_command &= 0x003F; + irmp_tmp_command <<= 4; + irmp_tmp_command |= last_value; + } + } + else +#endif +#if IRMP_SUPPORT_MANCHESTER == 1 + if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER) && + irmp_pause_time >= 2 * irmp_param.pause_1_len_max && irmp_bit >= irmp_param.complete_len - 2 && !irmp_param.stop_bit) + { + // special manchester decoder + got_light = TRUE; // this is a lie, but generates a stop bit ;-) + irmp_param.stop_bit = TRUE; // set flag + } + else +#endif // IRMP_SUPPORT_MANCHESTER == 1 + if (irmp_pause_time > IRMP_TIMEOUT_LEN) // timeout? + { + // yes... + if (irmp_bit == irmp_param.complete_len - 1 && irmp_param.stop_bit == 0) + { + irmp_bit++; + } +#if IRMP_SUPPORT_JVC_PROTOCOL == 1 + else if (irmp_param.protocol == IRMP_NEC_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17)) // it was a JVC stop bit + { + ANALYZE_PRINTF("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit); + irmp_param.stop_bit = TRUE; // set flag + irmp_param.protocol = IRMP_JVC_PROTOCOL; // switch protocol + irmp_param.complete_len = irmp_bit; // patch length: 16 or 17 + irmp_tmp_command = (irmp_tmp_address >> 4); // set command: upper 12 bits are command bits + irmp_tmp_address = irmp_tmp_address & 0x000F; // lower 4 bits are address bits + irmp_start_bit_detected = 1; // tricky: don't wait for another start bit... + } +#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 + +#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 +#if IRMP_SUPPORT_NEC_PROTOCOL == 1 + else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && irmp_bit == 32) // it was a NEC stop bit + { + ANALYZE_PRINTF("Switching to NEC protocol\n"); + irmp_param.stop_bit = TRUE; // set flag + irmp_param.protocol = IRMP_NEC_PROTOCOL; // switch protocol + irmp_param.complete_len = irmp_bit; // patch length: 16 or 17 + + // 0123456789ABC0123456789ABC0123456701234567 + // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc + // NEC: AAAAAAAAaaaaaaaaCCCCCCCCcccccccc + irmp_tmp_address |= (irmp_tmp_address2 & 0x0007) << 13; // fm 2012-02-13: 12 -> 13 + irmp_tmp_command = (irmp_tmp_address2 >> 3) | (irmp_tmp_command << 10); + } +#endif // IRMP_SUPPORT_NEC_PROTOCOL == 1 +#if IRMP_SUPPORT_JVC_PROTOCOL == 1 + else if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && (irmp_bit == 16 || irmp_bit == 17)) // it was a JVC stop bit + { + ANALYZE_PRINTF("Switching to JVC protocol, irmp_bit = %d\n", irmp_bit); + irmp_param.stop_bit = TRUE; // set flag + irmp_param.protocol = IRMP_JVC_PROTOCOL; // switch protocol + irmp_param.complete_len = irmp_bit; // patch length: 16 or 17 + + // 0123456789ABC0123456789ABC0123456701234567 + // NEC42: AAAAAAAAAAAAAaaaaaaaaaaaaaCCCCCCCCcccccccc + // JVC: AAAACCCCCCCCCCCC + irmp_tmp_command = (irmp_tmp_address >> 4) | (irmp_tmp_address2 << 9); // set command: upper 12 bits are command bits + irmp_tmp_address = irmp_tmp_address & 0x000F; // lower 4 bits are address bits + } +#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 +#endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1 + else + { + ANALYZE_PRINTF("error 2: pause %d after data bit %d too long\n", irmp_pause_time, irmp_bit); + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); + +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // wait for another start bit... + irmp_pulse_time = 0; + irmp_pause_time = 0; + } + } + } + } + else + { + // got light now! + got_light = TRUE; + } + + if (got_light) + { + ANALYZE_PRINTF("%8.3fms [bit %2d: pulse = %3d, pause = %3d] ", (double)(time_counter * 1000) / F_INTERRUPTS, irmp_bit, irmp_pulse_time, irmp_pause_time); + +#if IRMP_SUPPORT_MANCHESTER == 1 + if ((irmp_param.flags & IRMP_PARAM_FLAG_IS_MANCHESTER)) // Manchester + { +#if 1 + if (irmp_pulse_time > irmp_param.pulse_1_len_max /* && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max */) +#else // better, but some IR-RCs use asymmetric timings :-/ + if (irmp_pulse_time > irmp_param.pulse_1_len_max && irmp_pulse_time <= 2 * irmp_param.pulse_1_len_max && + irmp_pause_time <= 2 * irmp_param.pause_1_len_max) +#endif + { +#if IRMP_SUPPORT_RC6_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit + { + ANALYZE_PUTCHAR('T'); + if (irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode 6A + { + irmp_store_bit(1); + last_value = 1; + } + else // RC6 mode 0 + { + irmp_store_bit(0); + last_value = 0; + } + ANALYZE_NEWLINE(); + } + else +#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 + { + ANALYZE_PUTCHAR((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '0' : '1'); + irmp_store_bit((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 0 : 1); + +#if IRMP_SUPPORT_RC6_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 4 && irmp_pulse_time > RC6_TOGGLE_BIT_LEN_MIN) // RC6 toggle bit + { + ANALYZE_PUTCHAR('T'); + irmp_store_bit(1); + + if (irmp_pause_time > 2 * irmp_param.pause_1_len_max) + { + last_value = 0; + } + else + { + last_value = 1; + } + ANALYZE_NEWLINE(); + } + else +#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 + { + ANALYZE_PUTCHAR((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? '1' : '0'); + irmp_store_bit((irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0); +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) + if (! irmp_param2.protocol) +#endif + { + ANALYZE_NEWLINE(); + } + last_value = (irmp_param.flags & IRMP_PARAM_FLAG_1ST_PULSE_IS_1) ? 1 : 0; + } + } + } + else if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max + /* && irmp_pause_time <= 2 * irmp_param.pause_1_len_max */) + { + uint8_t manchester_value; + + if (last_pause > irmp_param.pause_1_len_max && last_pause <= 2 * irmp_param.pause_1_len_max) + { + manchester_value = last_value ? 0 : 1; + last_value = manchester_value; + } + else + { + manchester_value = last_value; + } + + ANALYZE_PUTCHAR(manchester_value + '0'); + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && (IRMP_SUPPORT_FDC_PROTOCOL == 1 || IRMP_SUPPORT_RCCAR_PROTOCOL == 1) + if (! irmp_param2.protocol) +#endif + { + ANALYZE_NEWLINE(); + } + +#if IRMP_SUPPORT_RC6_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_bit == 1 && manchester_value == 1) // RC6 mode != 0 ??? + { + ANALYZE_PRINTF("Switching to RC6A protocol\n"); + irmp_param.complete_len = RC6_COMPLETE_DATA_LEN_LONG; + irmp_param.address_offset = 5; + irmp_param.address_end = irmp_param.address_offset + 15; + irmp_param.command_offset = irmp_param.address_end + 1; // skip 1 system bit, changes like a toggle bit + irmp_param.command_end = irmp_param.command_offset + 16 - 1; + irmp_tmp_address = 0; + } +#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 + + irmp_store_bit(manchester_value); + } + else + { +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1 + if (irmp_param2.protocol == IRMP_FDC_PROTOCOL && + irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX && + ((irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX) || + (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX))) + { + ANALYZE_PUTCHAR('?'); + irmp_param.protocol = 0; // switch to FDC, see below + } + else +#endif // IRMP_SUPPORT_FDC_PROTOCOL == 1 +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL && + irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX && + ((irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX) || + (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX))) + { + ANALYZE_PUTCHAR('?'); + irmp_param.protocol = 0; // switch to RCCAR, see below + } + else +#endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + { + ANALYZE_PUTCHAR('?'); + ANALYZE_NEWLINE(); + ANALYZE_PRINTF("error 3 manchester: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // reset flags and wait for next start bit + irmp_pause_time = 0; + } + } + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_FDC_PROTOCOL == 1 + if (irmp_param2.protocol == IRMP_FDC_PROTOCOL && irmp_pulse_time >= FDC_PULSE_LEN_MIN && irmp_pulse_time <= FDC_PULSE_LEN_MAX) + { + if (irmp_pause_time >= FDC_1_PAUSE_LEN_MIN && irmp_pause_time <= FDC_1_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF(" 1 (FDC)\n"); + irmp_store_bit2(1); + } + else if (irmp_pause_time >= FDC_0_PAUSE_LEN_MIN && irmp_pause_time <= FDC_0_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF(" 0 (FDC)\n"); + irmp_store_bit2(0); + } + + if (! irmp_param.protocol) + { + ANALYZE_PRINTF("Switching to FDC protocol\n"); + memcpy(&irmp_param, &irmp_param2, sizeof(IRMP_PARAMETER)); + irmp_param2.protocol = 0; + irmp_tmp_address = irmp_tmp_address2; + irmp_tmp_command = irmp_tmp_command2; + } + } +#endif // IRMP_SUPPORT_FDC_PROTOCOL == 1 +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 && IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + if (irmp_param2.protocol == IRMP_RCCAR_PROTOCOL && irmp_pulse_time >= RCCAR_PULSE_LEN_MIN && irmp_pulse_time <= RCCAR_PULSE_LEN_MAX) + { + if (irmp_pause_time >= RCCAR_1_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_1_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF(" 1 (RCCAR)\n"); + irmp_store_bit2(1); + } + else if (irmp_pause_time >= RCCAR_0_PAUSE_LEN_MIN && irmp_pause_time <= RCCAR_0_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF(" 0 (RCCAR)\n"); + irmp_store_bit2(0); + } + + if (! irmp_param.protocol) + { + ANALYZE_PRINTF("Switching to RCCAR protocol\n"); + memcpy(&irmp_param, &irmp_param2, sizeof(IRMP_PARAMETER)); + irmp_param2.protocol = 0; + irmp_tmp_address = irmp_tmp_address2; + irmp_tmp_command = irmp_tmp_command2; + } + } +#endif // IRMP_SUPPORT_RCCAR_PROTOCOL == 1 + + last_pause = irmp_pause_time; + wait_for_space = 0; + } + else +#endif // IRMP_SUPPORT_MANCHESTER == 1 + +#if IRMP_SUPPORT_SERIAL == 1 + if (irmp_param.flags & IRMP_PARAM_FLAG_IS_SERIAL) + { + while (irmp_bit < irmp_param.complete_len && irmp_pulse_time > irmp_param.pulse_1_len_max) + { + ANALYZE_PUTCHAR('1'); + irmp_store_bit(1); + + if (irmp_pulse_time >= irmp_param.pulse_1_len_min) + { + irmp_pulse_time -= irmp_param.pulse_1_len_min; + } + else + { + irmp_pulse_time = 0; + } + } + + while (irmp_bit < irmp_param.complete_len && irmp_pause_time > irmp_param.pause_1_len_max) + { + ANALYZE_PUTCHAR('0'); + irmp_store_bit(0); + + if (irmp_pause_time >= irmp_param.pause_1_len_min) + { + irmp_pause_time -= irmp_param.pause_1_len_min; + } + else + { + irmp_pause_time = 0; + } + } + ANALYZE_NEWLINE(); + wait_for_space = 0; + } + else +#endif // IRMP_SUPPORT_SERIAL == 1 + +#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_SAMSUNG_PROTOCOL && irmp_bit == 16) // Samsung: 16th bit + { + if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX && + irmp_pause_time >= SAMSUNG_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("SYNC\n"); + wait_for_space = 0; + irmp_tmp_id = 0; + irmp_bit++; + } + else if (irmp_pulse_time >= SAMSUNG_PULSE_LEN_MIN && irmp_pulse_time <= SAMSUNG_PULSE_LEN_MAX) + { + irmp_param.protocol = IRMP_SAMSUNG32_PROTOCOL; + irmp_param.command_offset = SAMSUNG32_COMMAND_OFFSET; + irmp_param.command_end = SAMSUNG32_COMMAND_OFFSET + SAMSUNG32_COMMAND_LEN; + irmp_param.complete_len = SAMSUNG32_COMPLETE_DATA_LEN; + + if (irmp_pause_time >= SAMSUNG_1_PAUSE_LEN_MIN && irmp_pause_time <= SAMSUNG_1_PAUSE_LEN_MAX) + { + ANALYZE_PUTCHAR('1'); + ANALYZE_NEWLINE(); + irmp_store_bit(1); + wait_for_space = 0; + } + else + { + ANALYZE_PUTCHAR('0'); + ANALYZE_NEWLINE(); + irmp_store_bit(0); + wait_for_space = 0; + } + + ANALYZE_PRINTF("Switching to SAMSUNG32 protocol\n"); + } + else + { + // timing incorrect! + ANALYZE_PRINTF("error 3 Samsung: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // reset flags and wait for next start bit + irmp_pause_time = 0; + } + } + else +#endif // IRMP_SUPPORT_SAMSUNG_PROTOCOL + +#if IRMP_SUPPORT_NEC16_PROTOCOL +#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_NEC42_PROTOCOL && +#else // IRMP_SUPPORT_NEC_PROTOCOL instead + if (irmp_param.protocol == IRMP_NEC_PROTOCOL && +#endif // IRMP_SUPPORT_NEC42_PROTOCOL == 1 + irmp_bit == 8 && irmp_pause_time >= NEC_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= NEC_START_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("Switching to NEC16 protocol\n"); + irmp_param.protocol = IRMP_NEC16_PROTOCOL; + irmp_param.address_offset = NEC16_ADDRESS_OFFSET; + irmp_param.address_end = NEC16_ADDRESS_OFFSET + NEC16_ADDRESS_LEN; + irmp_param.command_offset = NEC16_COMMAND_OFFSET; + irmp_param.command_end = NEC16_COMMAND_OFFSET + NEC16_COMMAND_LEN; + irmp_param.complete_len = NEC16_COMPLETE_DATA_LEN; + wait_for_space = 0; + } + else +#endif // IRMP_SUPPORT_NEC16_PROTOCOL + +#if IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_BANG_OLUFSEN_PROTOCOL) + { + if (irmp_pulse_time >= BANG_OLUFSEN_PULSE_LEN_MIN && irmp_pulse_time <= BANG_OLUFSEN_PULSE_LEN_MAX) + { + if (irmp_bit == 1) // Bang & Olufsen: 3rd bit + { + if (irmp_pause_time >= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("3rd start bit\n"); + wait_for_space = 0; + irmp_bit++; + } + else + { + // timing incorrect! + ANALYZE_PRINTF("error 3a B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // reset flags and wait for next start bit + irmp_pause_time = 0; + } + } + else if (irmp_bit == 19) // Bang & Olufsen: trailer bit + { + if (irmp_pause_time >= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_TRAILER_BIT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("trailer bit\n"); + wait_for_space = 0; + irmp_bit++; + } + else + { + // timing incorrect! + ANALYZE_PRINTF("error 3b B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // reset flags and wait for next start bit + irmp_pause_time = 0; + } + } + else + { + if (irmp_pause_time >= BANG_OLUFSEN_1_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_1_PAUSE_LEN_MAX) + { + // pulse & pause timings correct for "1"? + ANALYZE_PUTCHAR('1'); + ANALYZE_NEWLINE(); + irmp_store_bit(1); + last_value = 1; + wait_for_space = 0; + } + else if (irmp_pause_time >= BANG_OLUFSEN_0_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_0_PAUSE_LEN_MAX) + { + // pulse & pause timings correct for "0"? + ANALYZE_PUTCHAR('0'); + ANALYZE_NEWLINE(); + irmp_store_bit(0); + last_value = 0; + wait_for_space = 0; + } + else if (irmp_pause_time >= BANG_OLUFSEN_R_PAUSE_LEN_MIN && irmp_pause_time <= BANG_OLUFSEN_R_PAUSE_LEN_MAX) + { + ANALYZE_PUTCHAR(last_value + '0'); + ANALYZE_NEWLINE(); + irmp_store_bit(last_value); + wait_for_space = 0; + } + else + { + // timing incorrect! + ANALYZE_PRINTF("error 3c B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // reset flags and wait for next start bit + irmp_pause_time = 0; + } + } + } + else + { + // timing incorrect! + ANALYZE_PRINTF("error 3d B&O: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // reset flags and wait for next start bit + irmp_pause_time = 0; + } + } + else +#endif // IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL + + if (irmp_pulse_time >= irmp_param.pulse_1_len_min && irmp_pulse_time <= irmp_param.pulse_1_len_max && + irmp_pause_time >= irmp_param.pause_1_len_min && irmp_pause_time <= irmp_param.pause_1_len_max) + { + // pulse & pause timings correct for "1"? + ANALYZE_PUTCHAR('1'); + ANALYZE_NEWLINE(); + irmp_store_bit(1); + wait_for_space = 0; + } + else if (irmp_pulse_time >= irmp_param.pulse_0_len_min && irmp_pulse_time <= irmp_param.pulse_0_len_max && + irmp_pause_time >= irmp_param.pause_0_len_min && irmp_pause_time <= irmp_param.pause_0_len_max) + { + // pulse & pause timings correct for "0"? + ANALYZE_PUTCHAR('0'); + ANALYZE_NEWLINE(); + irmp_store_bit(0); + wait_for_space = 0; + } + else +#if IRMP_SUPPORT_KATHREIN_PROTOCOL + + if (irmp_param.protocol == IRMP_KATHREIN_PROTOCOL && + irmp_pulse_time >= KATHREIN_1_PULSE_LEN_MIN && irmp_pulse_time <= KATHREIN_1_PULSE_LEN_MAX && + (((irmp_bit == 8 || irmp_bit == 6) && + irmp_pause_time >= KATHREIN_SYNC_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_SYNC_BIT_PAUSE_LEN_MAX) || + (irmp_bit == 12 && + irmp_pause_time >= KATHREIN_START_BIT_PAUSE_LEN_MIN && irmp_pause_time <= KATHREIN_START_BIT_PAUSE_LEN_MAX))) + + { + if (irmp_bit == 8) + { + irmp_bit++; + ANALYZE_PUTCHAR('S'); + ANALYZE_NEWLINE(); + irmp_tmp_command <<= 1; + } + else + { + ANALYZE_PUTCHAR('S'); + ANALYZE_NEWLINE(); + irmp_store_bit(1); + } + wait_for_space = 0; + } + else +#endif // IRMP_SUPPORT_KATHREIN_PROTOCOL + { + // timing incorrect! + ANALYZE_PRINTF("error 3: timing not correct: data bit %d, pulse: %d, pause: %d\n", irmp_bit, irmp_pulse_time, irmp_pause_time); + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // reset flags and wait for next start bit + irmp_pause_time = 0; + } + + irmp_pulse_time = 1; // set counter to 1, not 0 + } + } + else + { + // counting the pulse length ... + if (! irmp_input) // still light? + { + // yes... + irmp_pulse_time++; // increment counter + } + else + { + // now it's dark! + wait_for_space = 1; // let's count the time (see above) + irmp_pause_time = 1; // set pause counter to 1, not 0 + } + } + + if (irmp_start_bit_detected && irmp_bit == irmp_param.complete_len && irmp_param.stop_bit == 0) // enough bits received? + { + if (last_irmp_command == irmp_tmp_command && repetition_len < AUTO_FRAME_REPETITION_LEN) + { + repetition_frame_number++; + } + else + { + repetition_frame_number = 0; + } + +#if IRMP_SUPPORT_SIRCS_PROTOCOL == 1 + // if SIRCS protocol and the code will be repeated within 50 ms, we will ignore 2nd and 3rd repetition frame + if (irmp_param.protocol == IRMP_SIRCS_PROTOCOL && (repetition_frame_number == 1 || repetition_frame_number == 2)) + { + ANALYZE_PRINTF("code skipped: SIRCS auto repetition frame #%d, counter = %d, auto repetition len = %d\n", + repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); + repetition_len = 0; + } + else +#endif + +#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 + // if KASEIKYO protocol and the code will be repeated within 50 ms, we will ignore 2nd repetition frame + if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL && repetition_frame_number == 1) + { + ANALYZE_PRINTF("code skipped: KASEIKYO auto repetition frame #%d, counter = %d, auto repetition len = %d\n", + repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); + repetition_len = 0; + } + else +#endif + +#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + // if SAMSUNG32 protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame + if (irmp_param.protocol == IRMP_SAMSUNG32_PROTOCOL && (repetition_frame_number & 0x01)) + { + ANALYZE_PRINTF("code skipped: SAMSUNG32 auto repetition frame #%d, counter = %d, auto repetition len = %d\n", + repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); + repetition_len = 0; + } + else +#endif + +#if IRMP_SUPPORT_NUBERT_PROTOCOL == 1 + // if NUBERT protocol and the code will be repeated within 50 ms, we will ignore every 2nd frame + if (irmp_param.protocol == IRMP_NUBERT_PROTOCOL && (repetition_frame_number & 0x01)) + { + ANALYZE_PRINTF("code skipped: NUBERT auto repetition frame #%d, counter = %d, auto repetition len = %d\n", + repetition_frame_number + 1, repetition_len, AUTO_FRAME_REPETITION_LEN); + repetition_len = 0; + } + else +#endif + + { + ANALYZE_PRINTF("%8.3fms code detected, length = %d\n", (double)(time_counter * 1000) / F_INTERRUPTS, irmp_bit); + irmp_ir_detected = TRUE; + +#if IRMP_SUPPORT_DENON_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_DENON_PROTOCOL) + { + // check for repetition frame + if ((~irmp_tmp_command & 0x3FF) == last_irmp_denon_command) // command bits must be inverted + { + irmp_tmp_command = last_irmp_denon_command; // use command received before! + + irmp_protocol = irmp_param.protocol; // store protocol + irmp_address = irmp_tmp_address; // store address + irmp_command = irmp_tmp_command ; // store command + } + else + { + ANALYZE_PRINTF("waiting for inverted command repetition\n"); + irmp_ir_detected = FALSE; + last_irmp_denon_command = irmp_tmp_command; + } + } + else +#endif // IRMP_SUPPORT_DENON_PROTOCOL + +#if IRMP_SUPPORT_GRUNDIG_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_GRUNDIG_PROTOCOL && irmp_tmp_command == 0x01ff) + { + // Grundig start frame? + ANALYZE_PRINTF("Detected GRUNDIG start frame, ignoring it\n"); + irmp_ir_detected = FALSE; + } + else +#endif // IRMP_SUPPORT_GRUNDIG_PROTOCOL + +#if IRMP_SUPPORT_NOKIA_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_NOKIA_PROTOCOL && irmp_tmp_address == 0x00ff && irmp_tmp_command == 0x00fe) + { + // Nokia start frame? + ANALYZE_PRINTF("Detected NOKIA start frame, ignoring it\n"); + irmp_ir_detected = FALSE; + } + else +#endif // IRMP_SUPPORT_NOKIA_PROTOCOL + { +#if IRMP_SUPPORT_NEC_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_NEC_PROTOCOL && irmp_bit == 0) // repetition frame + { + if (repetition_len < NEC_FRAME_REPEAT_PAUSE_LEN_MAX) + { + ANALYZE_PRINTF("Detected NEC repetition frame, repetition_len = %d\n", repetition_len); + irmp_tmp_address = last_irmp_address; // address is last address + irmp_tmp_command = last_irmp_command; // command is last command + irmp_flags |= IRMP_FLAG_REPETITION; + repetition_len = 0; + } + else + { + ANALYZE_PRINTF("Detected NEC repetition frame, ignoring it: timeout occured, repetition_len = %d > %d\n", + repetition_len, NEC_FRAME_REPEAT_PAUSE_LEN_MAX); + irmp_ir_detected = FALSE; + } + } +#endif // IRMP_SUPPORT_NEC_PROTOCOL + +#if IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_KASEIKYO_PROTOCOL) + { + uint8_t xor; + // ANALYZE_PRINTF ("0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", + // xor_check[0], xor_check[1], xor_check[2], xor_check[3], xor_check[4], xor_check[5]); + + xor = (xor_check[0] & 0x0F) ^ ((xor_check[0] & 0xF0) >> 4) ^ (xor_check[1] & 0x0F) ^ ((xor_check[1] & 0xF0) >> 4); + + if (xor != (xor_check[2] & 0x0F)) + { + ANALYZE_PRINTF("error 4: wrong XOR check for customer id: 0x%1x 0x%1x\n", xor, xor_check[2] & 0x0F); + irmp_ir_detected = FALSE; + } + + xor = xor_check[2] ^ xor_check[3] ^ xor_check[4]; + + if (xor != xor_check[5]) + { + ANALYZE_PRINTF("error 4: wrong XOR check for data bits: 0x%02x 0x%02x\n", xor, xor_check[5]); + irmp_ir_detected = FALSE; + } + + irmp_flags |= genre2; // write the genre2 bits into MSB of the flag byte + } +#endif // IRMP_SUPPORT_KASEIKYO_PROTOCOL == 1 + +#if IRMP_SUPPORT_RC6_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_RC6_PROTOCOL && irmp_param.complete_len == RC6_COMPLETE_DATA_LEN_LONG) // RC6 mode = 6? + { + irmp_protocol = IRMP_RC6A_PROTOCOL; + } + else +#endif // IRMP_SUPPORT_RC6_PROTOCOL == 1 + + irmp_protocol = irmp_param.protocol; + +#if IRMP_SUPPORT_FDC_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_FDC_PROTOCOL) + { + if (irmp_tmp_command & 0x000F) // released key? + { + irmp_tmp_command = (irmp_tmp_command >> 4) | 0x80; // yes, set bit 7 + } + else + { + irmp_tmp_command >>= 4; // no, it's a pressed key + } + irmp_tmp_command |= (irmp_tmp_address << 2) & 0x0F00; // 000000CCCCAAAAAA -> 0000CCCC00000000 + irmp_tmp_address &= 0x003F; + } +#endif + + irmp_address = irmp_tmp_address; // store address +#if IRMP_SUPPORT_NEC_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_NEC_PROTOCOL) + { + last_irmp_address = irmp_tmp_address; // store as last address, too + } +#endif + +#if IRMP_SUPPORT_RC5_PROTOCOL == 1 + if (irmp_param.protocol == IRMP_RC5_PROTOCOL) + { + irmp_tmp_command |= rc5_cmd_bit6; // store bit 6 + } +#endif + irmp_command = irmp_tmp_command; // store command + +#if IRMP_SUPPORT_SAMSUNG_PROTOCOL == 1 + irmp_id = irmp_tmp_id; +#endif + } + } + + if (irmp_ir_detected) + { + if (last_irmp_command == irmp_tmp_command && + last_irmp_address == irmp_tmp_address && + repetition_len < IRMP_KEY_REPETITION_LEN) + { + irmp_flags |= IRMP_FLAG_REPETITION; + } + + last_irmp_address = irmp_tmp_address; // store as last address, too + last_irmp_command = irmp_tmp_command; // store as last command, too + + repetition_len = 0; + } + else + { + ANALYZE_ONLY_NORMAL_PUTCHAR('\n'); + } + +// irmp_busy_flag = FALSE; + irmp_start_bit_detected = 0; // and wait for next start bit + irmp_tmp_command = 0; + irmp_pulse_time = 0; + irmp_pause_time = 0; + +#if IRMP_SUPPORT_JVC_PROTOCOL == 1 + if (irmp_protocol == IRMP_JVC_PROTOCOL) // the stop bit of JVC frame is also start bit of next frame + { + // set pulse time here! + irmp_pulse_time = ((uint8_t)(F_INTERRUPTS * JVC_START_BIT_PULSE_TIME)); + } +#endif // IRMP_SUPPORT_JVC_PROTOCOL == 1 + } + } + } + return (irmp_ir_detected); +} + +#ifdef ANALYZE + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * main functions - for Unix/Linux + Windows only! + * + * AVR: see main.c! + * + * Compile it under linux with: + * cc irmp.c -o irmp + * + * usage: ./irmp [-v|-s|-a|-l|-p] < file + * + * options: + * -v verbose + * -s silent + * -a analyze + * -l list pulse/pauses + * -p print timings + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ + +#ifndef IRMP_EMBED +static void +print_timings(void) +{ + printf("IRMP_TIMEOUT_LEN: %d [%d byte(s)]\n", IRMP_TIMEOUT_LEN, sizeof(PAUSE_LEN)); + printf("IRMP_KEY_REPETITION_LEN %d\n", IRMP_KEY_REPETITION_LEN); + puts(""); + printf("PROTOCOL S S-PULSE S-PAUSE PULSE-0 PAUSE-0 PULSE-1 PAUSE-1\n"); + printf("====================================================================================\n"); + printf("SIRCS 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + SIRCS_START_BIT_PULSE_LEN_MIN, SIRCS_START_BIT_PULSE_LEN_MAX, SIRCS_START_BIT_PAUSE_LEN_MIN, SIRCS_START_BIT_PAUSE_LEN_MAX, + SIRCS_0_PULSE_LEN_MIN, SIRCS_0_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX, + SIRCS_1_PULSE_LEN_MIN, SIRCS_1_PULSE_LEN_MAX, SIRCS_PAUSE_LEN_MIN, SIRCS_PAUSE_LEN_MAX); + + printf("NEC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_START_BIT_PAUSE_LEN_MIN, NEC_START_BIT_PAUSE_LEN_MAX, + NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX, + NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX); + + printf("NEC (rep) 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + NEC_START_BIT_PULSE_LEN_MIN, NEC_START_BIT_PULSE_LEN_MAX, NEC_REPEAT_START_BIT_PAUSE_LEN_MIN, NEC_REPEAT_START_BIT_PAUSE_LEN_MAX, + NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_0_PAUSE_LEN_MIN, NEC_0_PAUSE_LEN_MAX, + NEC_PULSE_LEN_MIN, NEC_PULSE_LEN_MAX, NEC_1_PAUSE_LEN_MIN, NEC_1_PAUSE_LEN_MAX); + + printf("SAMSUNG 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + SAMSUNG_START_BIT_PULSE_LEN_MIN, SAMSUNG_START_BIT_PULSE_LEN_MAX, SAMSUNG_START_BIT_PAUSE_LEN_MIN, SAMSUNG_START_BIT_PAUSE_LEN_MAX, + SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_0_PAUSE_LEN_MIN, SAMSUNG_0_PAUSE_LEN_MAX, + SAMSUNG_PULSE_LEN_MIN, SAMSUNG_PULSE_LEN_MAX, SAMSUNG_1_PAUSE_LEN_MIN, SAMSUNG_1_PAUSE_LEN_MAX); + + printf("MATSUSHITA 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + MATSUSHITA_START_BIT_PULSE_LEN_MIN, MATSUSHITA_START_BIT_PULSE_LEN_MAX, MATSUSHITA_START_BIT_PAUSE_LEN_MIN, MATSUSHITA_START_BIT_PAUSE_LEN_MAX, + MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_0_PAUSE_LEN_MIN, MATSUSHITA_0_PAUSE_LEN_MAX, + MATSUSHITA_PULSE_LEN_MIN, MATSUSHITA_PULSE_LEN_MAX, MATSUSHITA_1_PAUSE_LEN_MIN, MATSUSHITA_1_PAUSE_LEN_MAX); + + printf("KASEIKYO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + KASEIKYO_START_BIT_PULSE_LEN_MIN, KASEIKYO_START_BIT_PULSE_LEN_MAX, KASEIKYO_START_BIT_PAUSE_LEN_MIN, KASEIKYO_START_BIT_PAUSE_LEN_MAX, + KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_0_PAUSE_LEN_MIN, KASEIKYO_0_PAUSE_LEN_MAX, + KASEIKYO_PULSE_LEN_MIN, KASEIKYO_PULSE_LEN_MAX, KASEIKYO_1_PAUSE_LEN_MIN, KASEIKYO_1_PAUSE_LEN_MAX); + + printf("RECS80 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + RECS80_START_BIT_PULSE_LEN_MIN, RECS80_START_BIT_PULSE_LEN_MAX, RECS80_START_BIT_PAUSE_LEN_MIN, RECS80_START_BIT_PAUSE_LEN_MAX, + RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_0_PAUSE_LEN_MIN, RECS80_0_PAUSE_LEN_MAX, + RECS80_PULSE_LEN_MIN, RECS80_PULSE_LEN_MAX, RECS80_1_PAUSE_LEN_MIN, RECS80_1_PAUSE_LEN_MAX); + + printf("RC5 1 %3d - %3d %3d - %3d %3d - %3d\n", + RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, RC5_START_BIT_LEN_MIN, RC5_START_BIT_LEN_MAX, + RC5_BIT_LEN_MIN, RC5_BIT_LEN_MAX); + + printf("DENON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, + DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_0_PAUSE_LEN_MIN, DENON_0_PAUSE_LEN_MAX, + DENON_PULSE_LEN_MIN, DENON_PULSE_LEN_MAX, DENON_1_PAUSE_LEN_MIN, DENON_1_PAUSE_LEN_MAX); + + printf("THOMSON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, + THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, THOMSON_0_PAUSE_LEN_MIN, THOMSON_0_PAUSE_LEN_MAX, + THOMSON_PULSE_LEN_MIN, THOMSON_PULSE_LEN_MAX, THOMSON_1_PAUSE_LEN_MIN, THOMSON_1_PAUSE_LEN_MAX); + + printf("RC6 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + RC6_START_BIT_PULSE_LEN_MIN, RC6_START_BIT_PULSE_LEN_MAX, RC6_START_BIT_PAUSE_LEN_MIN, RC6_START_BIT_PAUSE_LEN_MAX, + RC6_BIT_PULSE_LEN_MIN, RC6_BIT_PULSE_LEN_MAX, RC6_BIT_PAUSE_LEN_MIN, RC6_BIT_PAUSE_LEN_MAX); + + printf("RECS80EXT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + RECS80EXT_START_BIT_PULSE_LEN_MIN, RECS80EXT_START_BIT_PULSE_LEN_MAX, RECS80EXT_START_BIT_PAUSE_LEN_MIN, RECS80EXT_START_BIT_PAUSE_LEN_MAX, + RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_0_PAUSE_LEN_MIN, RECS80EXT_0_PAUSE_LEN_MAX, + RECS80EXT_PULSE_LEN_MIN, RECS80EXT_PULSE_LEN_MAX, RECS80EXT_1_PAUSE_LEN_MIN, RECS80EXT_1_PAUSE_LEN_MAX); + + printf("NUBERT 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + NUBERT_START_BIT_PULSE_LEN_MIN, NUBERT_START_BIT_PULSE_LEN_MAX, NUBERT_START_BIT_PAUSE_LEN_MIN, NUBERT_START_BIT_PAUSE_LEN_MAX, + NUBERT_0_PULSE_LEN_MIN, NUBERT_0_PULSE_LEN_MAX, NUBERT_0_PAUSE_LEN_MIN, NUBERT_0_PAUSE_LEN_MAX, + NUBERT_1_PULSE_LEN_MIN, NUBERT_1_PULSE_LEN_MAX, NUBERT_1_PAUSE_LEN_MIN, NUBERT_1_PAUSE_LEN_MAX); + + printf("BANG_OLUFSEN 1 %3d - %3d %3d - %3d\n", + BANG_OLUFSEN_START_BIT1_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PULSE_LEN_MAX, + BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT1_PAUSE_LEN_MAX); + + printf("BANG_OLUFSEN 2 %3d - %3d %3d - %3d\n", + BANG_OLUFSEN_START_BIT2_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PULSE_LEN_MAX, + BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT2_PAUSE_LEN_MAX); + + printf("BANG_OLUFSEN 3 %3d - %3d %3d - %3d\n", + BANG_OLUFSEN_START_BIT3_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PULSE_LEN_MAX, + BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT3_PAUSE_LEN_MAX); + + printf("BANG_OLUFSEN 4 %3d - %3d %3d - %3d\n", + BANG_OLUFSEN_START_BIT4_PULSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PULSE_LEN_MAX, + BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MIN, BANG_OLUFSEN_START_BIT4_PAUSE_LEN_MAX); + + printf("BANG_OLUFSEN - %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_0_PAUSE_LEN_MIN, BANG_OLUFSEN_0_PAUSE_LEN_MAX, + BANG_OLUFSEN_PULSE_LEN_MIN, BANG_OLUFSEN_PULSE_LEN_MAX, BANG_OLUFSEN_1_PAUSE_LEN_MIN, BANG_OLUFSEN_1_PAUSE_LEN_MAX); + + printf("GRUNDIG/NOKIA 1 %3d - %3d %3d - %3d %3d - %3d\n", + GRUNDIG_NOKIA_IR60_START_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_START_BIT_LEN_MAX, + GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MIN, GRUNDIG_NOKIA_IR60_PRE_PAUSE_LEN_MAX, + GRUNDIG_NOKIA_IR60_BIT_LEN_MIN, GRUNDIG_NOKIA_IR60_BIT_LEN_MAX); + + printf("SIEMENS/RUWIDO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PULSE_LEN_MAX, + SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_START_BIT_PAUSE_LEN_MAX, + SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX, + SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX, + 2 * SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_BIT_PULSE_LEN_MAX, + 2 * SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MIN, 2 * SIEMENS_OR_RUWIDO_BIT_PAUSE_LEN_MAX); + + printf("GRUNDIG2 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + GRUNDIG2_START_BIT_PULSE_LEN_MIN, GRUNDIG2_START_BIT_PULSE_LEN_MAX, + GRUNDIG2_START_BIT_PAUSE_LEN_MIN, GRUNDIG2_START_BIT_PAUSE_LEN_MAX, + GRUNDIG2_BIT_PULSE_LEN_MIN, GRUNDIG2_BIT_PULSE_LEN_MAX, + GRUNDIG2_BIT_PAUSE_LEN_MIN, GRUNDIG2_BIT_PAUSE_LEN_MAX, + 2 * GRUNDIG2_BIT_PULSE_LEN_MIN, 2 * GRUNDIG2_BIT_PULSE_LEN_MAX, + 2 * GRUNDIG2_BIT_PAUSE_LEN_MIN, 2 * GRUNDIG2_BIT_PAUSE_LEN_MAX); + + printf("FDC 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + FDC_START_BIT_PULSE_LEN_MIN, FDC_START_BIT_PULSE_LEN_MAX, FDC_START_BIT_PAUSE_LEN_MIN, FDC_START_BIT_PAUSE_LEN_MAX, + FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_0_PAUSE_LEN_MIN, FDC_0_PAUSE_LEN_MAX, + FDC_PULSE_LEN_MIN, FDC_PULSE_LEN_MAX, FDC_1_PAUSE_LEN_MIN, FDC_1_PAUSE_LEN_MAX); + + printf("RCCAR 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + RCCAR_START_BIT_PULSE_LEN_MIN, RCCAR_START_BIT_PULSE_LEN_MAX, RCCAR_START_BIT_PAUSE_LEN_MIN, RCCAR_START_BIT_PAUSE_LEN_MAX, + RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_0_PAUSE_LEN_MIN, RCCAR_0_PAUSE_LEN_MAX, + RCCAR_PULSE_LEN_MIN, RCCAR_PULSE_LEN_MAX, RCCAR_1_PAUSE_LEN_MIN, RCCAR_1_PAUSE_LEN_MAX); + + printf("NIKON 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + NIKON_START_BIT_PULSE_LEN_MIN, NIKON_START_BIT_PULSE_LEN_MAX, NIKON_START_BIT_PAUSE_LEN_MIN, NIKON_START_BIT_PAUSE_LEN_MAX, + NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_0_PAUSE_LEN_MIN, NIKON_0_PAUSE_LEN_MAX, + NIKON_PULSE_LEN_MIN, NIKON_PULSE_LEN_MAX, NIKON_1_PAUSE_LEN_MIN, NIKON_1_PAUSE_LEN_MAX); + + printf("LEGO 1 %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d %3d - %3d\n", + LEGO_START_BIT_PULSE_LEN_MIN, LEGO_START_BIT_PULSE_LEN_MAX, LEGO_START_BIT_PAUSE_LEN_MIN, LEGO_START_BIT_PAUSE_LEN_MAX, + LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_0_PAUSE_LEN_MIN, LEGO_0_PAUSE_LEN_MAX, + LEGO_PULSE_LEN_MIN, LEGO_PULSE_LEN_MAX, LEGO_1_PAUSE_LEN_MIN, LEGO_1_PAUSE_LEN_MAX); + +} + +void +print_spectrum(char *text, int *buf, int is_pulse) +{ + int i; + int j; + int min; + int max; + int max_value = 0; + int value; + int sum = 0; + int counter = 0; + double average = 0; + double tolerance; + + puts("-------------------------------------------------------------------------------"); + printf("%s:\n", text); + + for (i = 0; i < 256; i++) + { + if (buf[i] > max_value) + { + max_value = buf[i]; + } + } + + for (i = 1; i < 100; i++) + { + if (buf[i] > 0) + { + printf("%3d ", i); + value = (buf[i] * 60) / max_value; + + for (j = 0; j < value; j++) + { + putchar('o'); + } + printf(" %d\n", buf[i]); + + sum += i * buf[i]; + counter += buf[i]; + } + else + { + max = i - 1; + + if (counter > 0) + { + average = (float) sum / (float) counter; + + if (is_pulse) + { + printf("pulse "); + } + else + { + printf("pause "); + } + + printf("avg: %4.1f=%6.1f us, ", average, (1000000. * average) / (float) F_INTERRUPTS); + printf("min: %2d=%6.1f us, ", min, (1000000. * min) / (float) F_INTERRUPTS); + printf("max: %2d=%6.1f us, ", max, (1000000. * max) / (float) F_INTERRUPTS); + + tolerance = (max - average); + + if (average - min > tolerance) + { + tolerance = average - min; + } + + tolerance = tolerance * 100 / average; + printf("tol: %4.1f%%\n", tolerance); + } + + counter = 0; + sum = 0; + min = i + 1; + } + } +} +#endif + +#define STATE_LEFT_SHIFT 0x01 +#define STATE_RIGHT_SHIFT 0x02 +#define STATE_LEFT_CTRL 0x04 +#define STATE_LEFT_ALT 0x08 +#define STATE_RIGHT_ALT 0x10 + +#define KEY_ESCAPE 0x1B // keycode = 0x006e +#define KEY_MENUE 0x80 // keycode = 0x0070 +#define KEY_BACK 0x81 // keycode = 0x0071 +#define KEY_FORWARD 0x82 // keycode = 0x0072 +#define KEY_ADDRESS 0x83 // keycode = 0x0073 +#define KEY_WINDOW 0x84 // keycode = 0x0074 +#define KEY_1ST_PAGE 0x85 // keycode = 0x0075 +#define KEY_STOP 0x86 // keycode = 0x0076 +#define KEY_MAIL 0x87 // keycode = 0x0077 +#define KEY_FAVORITES 0x88 // keycode = 0x0078 +#define KEY_NEW_PAGE 0x89 // keycode = 0x0079 +#define KEY_SETUP 0x8A // keycode = 0x007a +#define KEY_FONT 0x8B // keycode = 0x007b +#define KEY_PRINT 0x8C // keycode = 0x007c +#define KEY_ON_OFF 0x8E // keycode = 0x007c + +#define KEY_INSERT 0x90 // keycode = 0x004b +#define KEY_DELETE 0x91 // keycode = 0x004c +#define KEY_LEFT 0x92 // keycode = 0x004f +#define KEY_HOME 0x93 // keycode = 0x0050 +#define KEY_END 0x94 // keycode = 0x0051 +#define KEY_UP 0x95 // keycode = 0x0053 +#define KEY_DOWN 0x96 // keycode = 0x0054 +#define KEY_PAGE_UP 0x97 // keycode = 0x0055 +#define KEY_PAGE_DOWN 0x98 // keycode = 0x0056 +#define KEY_RIGHT 0x99 // keycode = 0x0059 +#define KEY_MOUSE_1 0x9E // keycode = 0x0400 +#define KEY_MOUSE_2 0x9F // keycode = 0x0800 + +#ifndef LIRC_IRMP +static uint8_t +get_fdc_key(uint16_t cmd) +{ + static uint8_t key_table[128] = + { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0, '^', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'ß', '´', 0, '\b', + '\t', 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 'ü', '+', 0, 0, 'a', + 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'ö', 'ä', '#', '\r', 0, '<', 'y', 'x', + 'c', 'v', 'b', 'n', 'm', ',', '.', '-', 0, 0, 0, 0, 0, ' ', 0, 0, + + 0, '°', '!', '"', '§', '$', '%', '&', '/', '(', ')', '=', '?', '`', 0, '\b', + '\t', 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 'Ü', '*', 0, 0, 'A', + 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Ö', 'Ä', '\'', '\r', 0, '>', 'Y', 'X', + 'C', 'V', 'B', 'N', 'M', ';', ':', '_', 0, 0, 0, 0, 0, ' ', 0, 0 + }; + static uint8_t state; + + uint8_t key = 0; + + switch (cmd) + { + case 0x002C: + state |= STATE_LEFT_SHIFT; + break; // pressed left shift + case 0x00AC: + state &= ~STATE_LEFT_SHIFT; + break; // released left shift + case 0x0039: + state |= STATE_RIGHT_SHIFT; + break; // pressed right shift + case 0x00B9: + state &= ~STATE_RIGHT_SHIFT; + break; // released right shift + case 0x003A: + state |= STATE_LEFT_CTRL; + break; // pressed left ctrl + case 0x00BA: + state &= ~STATE_LEFT_CTRL; + break; // released left ctrl + case 0x003C: + state |= STATE_LEFT_ALT; + break; // pressed left alt + case 0x00BC: + state &= ~STATE_LEFT_ALT; + break; // released left alt + case 0x003E: + state |= STATE_RIGHT_ALT; + break; // pressed left alt + case 0x00BE: + state &= ~STATE_RIGHT_ALT; + break; // released left alt + + case 0x006e: + key = KEY_ESCAPE; + break; + case 0x004b: + key = KEY_INSERT; + break; + case 0x004c: + key = KEY_DELETE; + break; + case 0x004f: + key = KEY_LEFT; + break; + case 0x0050: + key = KEY_HOME; + break; + case 0x0051: + key = KEY_END; + break; + case 0x0053: + key = KEY_UP; + break; + case 0x0054: + key = KEY_DOWN; + break; + case 0x0055: + key = KEY_PAGE_UP; + break; + case 0x0056: + key = KEY_PAGE_DOWN; + break; + case 0x0059: + key = KEY_RIGHT; + break; + case 0x0400: + key = KEY_MOUSE_1; + break; + case 0x0800: + key = KEY_MOUSE_2; + break; + + default: + { + if (!(cmd & 0x80)) // pressed key + { + if (cmd >= 0x70 && cmd <= 0x7F) // function keys + { + key = cmd + 0x10; // 7x -> 8x + } + else if (cmd < 64) // key listed in key_table + { + if (state & (STATE_LEFT_ALT | STATE_RIGHT_ALT)) + { + switch (cmd) + { + case 0x0003: + key = '²'; + break; + case 0x0008: + key = '{'; + break; + case 0x0009: + key = '['; + break; + case 0x000A: + key = ']'; + break; + case 0x000B: + key = '}'; + break; + case 0x000C: + key = '\\'; + break; + case 0x001C: + key = '~'; + break; + case 0x002D: + key = '|'; + break; + case 0x0034: + key = 0xB5; + break; // Mu + } + } + else if (state & (STATE_LEFT_CTRL)) + { + if (key_table[cmd] >= 'a' && key_table[cmd] <= 'z') + { + key = key_table[cmd] - 'a' + 1; + } + else + { + key = key_table[cmd]; + } + } + else + { + int idx = cmd + ((state & (STATE_LEFT_SHIFT | STATE_RIGHT_SHIFT)) ? 64 : 0); + + if (key_table[idx]) + { + key = key_table[idx]; + } + } + } + } + break; + } + } + + return (key); +} + +static int analyze = FALSE; +static int list = FALSE; +static IRMP_DATA irmp_data; + +static void +next_tick(void) +{ + if (! analyze && ! list) + { + (void) irmp_ISR(); + + if (irmp_get_data(&irmp_data)) + { + uint8_t key; + + ANALYZE_ONLY_NORMAL_PUTCHAR(' '); + + if (verbose) + { + printf("%8.3fms ", (double)(time_counter * 1000) / F_INTERRUPTS); + } + + if (irmp_data.protocol == IRMP_FDC_PROTOCOL && (key = get_fdc_key(irmp_data.command)) != 0) + { + if ((key >= 0x20 && key < 0x7F) || key >= 0xA0) + { + printf("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = '%c'\n", + irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, key); + } + else if (key == '\r' || key == '\t' || key == KEY_ESCAPE || (key >= 0x80 && key <= 0x9F)) // function keys + { + char *p = (char *) NULL; + + switch (key) + { + case '\t' : + p = "TAB"; + break; + case '\r' : + p = "CR"; + break; + case KEY_ESCAPE : + p = "ESCAPE"; + break; + case KEY_MENUE : + p = "MENUE"; + break; + case KEY_BACK : + p = "BACK"; + break; + case KEY_FORWARD : + p = "FORWARD"; + break; + case KEY_ADDRESS : + p = "ADDRESS"; + break; + case KEY_WINDOW : + p = "WINDOW"; + break; + case KEY_1ST_PAGE : + p = "1ST_PAGE"; + break; + case KEY_STOP : + p = "STOP"; + break; + case KEY_MAIL : + p = "MAIL"; + break; + case KEY_FAVORITES : + p = "FAVORITES"; + break; + case KEY_NEW_PAGE : + p = "NEW_PAGE"; + break; + case KEY_SETUP : + p = "SETUP"; + break; + case KEY_FONT : + p = "FONT"; + break; + case KEY_PRINT : + p = "PRINT"; + break; + case KEY_ON_OFF : + p = "ON_OFF"; + break; + + case KEY_INSERT : + p = "INSERT"; + break; + case KEY_DELETE : + p = "DELETE"; + break; + case KEY_LEFT : + p = "LEFT"; + break; + case KEY_HOME : + p = "HOME"; + break; + case KEY_END : + p = "END"; + break; + case KEY_UP : + p = "UP"; + break; + case KEY_DOWN : + p = "DOWN"; + break; + case KEY_PAGE_UP : + p = "PAGE_UP"; + break; + case KEY_PAGE_DOWN : + p = "PAGE_DOWN"; + break; + case KEY_RIGHT : + p = "RIGHT"; + break; + case KEY_MOUSE_1 : + p = "KEY_MOUSE_1"; + break; + case KEY_MOUSE_2 : + p = "KEY_MOUSE_2"; + break; + default : + p = ""; + break; + } + + printf("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x, key = %s\n", + irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key, p); + } + else + { + printf("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x, asc = 0x%02x\n", + irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, key); + } + } + else + { + printf("p = %2d, a = 0x%04x, c = 0x%04x, f = 0x%02x\n", + irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags); + } + } + } +} +#endif + +#ifndef LIRC_IRMP +int +main(int argc, char **argv) +{ + int i; + int ch; + int last_ch = 0; + int pulse = 0; + int pause = 0; + + int start_pulses[256]; + int start_pauses[256]; + int pulses[256]; + int pauses[256]; + + int first_pulse = TRUE; + int first_pause = TRUE; + + if (argc == 2) + { + if (! strcmp(argv[1], "-v")) + { + verbose = TRUE; + } + else if (! strcmp(argv[1], "-l")) + { + list = TRUE; + } + else if (! strcmp(argv[1], "-a")) + { + analyze = TRUE; + } + else if (! strcmp(argv[1], "-s")) + { + silent = TRUE; + } + else if (! strcmp(argv[1], "-p")) + { + print_timings(); + return (0); + } + } + + for (i = 0; i < 256; i++) + { + start_pulses[i] = 0; + start_pauses[i] = 0; + pulses[i] = 0; + pauses[i] = 0; + } + + IRMP_PIN = 0xFF; + + while ((ch = getchar()) != EOF) + { + if (ch == '_' || ch == '0') + { + if (last_ch != ch) + { + if (pause > 0) + { + if (list) + { + printf("pause: %d\n", pause); + } + + if (analyze) + { + if (first_pause) + { + if (pause < 256) + { + start_pauses[pause]++; + } + first_pause = FALSE; + } + else + { + if (pause < 256) + { + pauses[pause]++; + } + } + } + } + pause = 0; + } + pulse++; + IRMP_PIN = 0x00; + } + else if (ch == 0xaf || ch == '-' || ch == '1') + { + if (last_ch != ch) + { + if (list) + { + printf("pulse: %d ", pulse); + } + + if (analyze) + { + if (first_pulse) + { + if (pulse < 256) + { + start_pulses[pulse]++; + } + first_pulse = FALSE; + } + else + { + if (pulse < 256) + { + pulses[pulse]++; + } + } + } + pulse = 0; + } + + pause++; + IRMP_PIN = 0xff; + } + else if (ch == '\n') + { + IRMP_PIN = 0xff; + + if (list && pause > 0) + { + printf("pause: %d\n", pause); + } + pause = 0; + + if (! analyze) + { + for (i = 0; i < (int)((8000.0 * F_INTERRUPTS) / 10000); i++) // newline: long pause of 800 msec + { + next_tick(); + } + } + first_pulse = TRUE; + first_pause = TRUE; + } + else if (ch == '#') + { + if (analyze) + { + while ((ch = getchar()) != '\n' && ch != EOF) + { + ; + } + } + else + { + puts("-------------------------------------------------------------------"); + putchar(ch); + + while ((ch = getchar()) != '\n' && ch != EOF) + { + if (ch != '\r') // ignore CR in DOS/Windows files + { + putchar(ch); + } + } + putchar('\n'); + } + + } + + last_ch = ch; + + next_tick(); + } + + if (analyze) + { + print_spectrum("START PULSES", start_pulses, TRUE); + print_spectrum("START PAUSES", start_pauses, FALSE); + print_spectrum("PULSES", pulses, TRUE); + print_spectrum("PAUSES", pauses, FALSE); + puts("-------------------------------------------------------------------------------"); + } + return 0; +} +#else +#ifndef IRMP_EMBED +/* 50 ms. This should be longer than the longest light pulse */ +#define POLL_MS (50 * 1000) +#define LIRC_PULSE 0x01000000 +#define LIRC_PULSE_MASK 0x00FFFFFF + +int main(int argc, char **argv) +{ + int fd; + int pulse; + int last_pulse = 1; + uint32_t lircdata; /* lirc_t to be correct... */ + unsigned int count = 0; /* how many timeouts? */ + IRMP_DATA d; + + silent = TRUE; + + if (argc == 2) + { + if (! strcmp(argv[1], "-v")) + { + verbose = TRUE; + silent = FALSE; + } + else if (! strcmp(argv[1], "-p")) + { + print_timings(); + return (0); + } + } + + IRMP_PIN = 0xFF; + fd = open("/dev/lirc", O_RDONLY); + if (fd < 0) + { + perror("open /dev/lirc"); + return 1; + } + /* TODO: ioctl to find out if we have a compatible LIRC_MODE2 device */ + + while (1) + { + fd_set fds; + struct timeval tv; + int ret; + + FD_ZERO(&fds); + FD_SET(fd, &fds); + tv.tv_sec = 0; + tv.tv_usec = POLL_MS; + /* any singal can interrupt select. we rely on the linux-only feature + * that the timeout is automatcally recalculated in this case! */ + do + { + ret = select(fd + 1, &fds, NULL, NULL, &tv); + } + while (ret == -1 && errno == EINTR); + + if (ret == -1) + { + /* errno != EINTR... */ + perror("lirmp: select"); + break; + } + + if (ret == 0) + { + count++; + lircdata = POLL_MS; /* timeout */ + pulse = !last_pulse; /* lirc sends data on signal change */ + } + else + { + if (read(fd, &lircdata, sizeof(lircdata)) != sizeof(lircdata)) + { + perror("read"); + break; + } + pulse = (lircdata & LIRC_PULSE); /* we got light... */ + last_pulse = pulse; + lircdata &= LIRC_PULSE_MASK; /* how long the pulse was in microseconds */ + } + + if (ret && count) + { + if (count * POLL_MS > lircdata) + lircdata = 0; + else + lircdata -= count * POLL_MS; + count = 0; + } + //printf("lircdata: ret:%d c:%d %d\n", ret, ch - '0', lircdata); + lircdata /= (1000000 / F_INTERRUPTS); + + if (pulse) + IRMP_PIN = 0x00; + else + IRMP_PIN = 0xff; + + do + { + (void) irmp_ISR(); + if (irmp_get_data(&d)) + { + printf("protocol: %2d address: 0x%04x command: 0x%04x flags: %d\n", + d.protocol, d.address, d.command, d.flags); + + /* do something else here... */ + + /* todo: do we need to complete the loop if we already + * detected the singal in this pulse? */ + } + } + while (lircdata-- > 0); + } + return 0; +} +#endif // IRMP_EMBED +#endif // LIRC_IRMP +#endif // ANALYZE diff --git a/libspark/irmp.h b/libspark/irmp.h index 1e3852b..19ddfbc 100644 --- a/libspark/irmp.h +++ b/libspark/irmp.h @@ -1,528 +1,528 @@ -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * irmp.h - * - * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de - * - * $Id: irmp.h,v 1.70 2012/02/21 08:41:46 fm Exp $ - * - * ATMEGA88 @ 8 MHz - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ - -#ifndef _WC_IRMP_H_ -#define _WC_IRMP_H_ - -#if defined(__18CXX) // Microchip C18 declaration of missing typedef -typedef unsigned char uint8_t; -typedef unsigned int uint16_t; -#endif //Microchip C18 - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * timing constants: - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -// fm 22.09.2011: may not be more than 16000L, otherwise some JVC codes will not be accepted -#define IRMP_TIMEOUT_TIME 15500.0e-6 // timeout after 15.5 ms darkness -#define IRMP_TIMEOUT_TIME_MS 15500L // timeout after 15.5 ms darkness - -#if IRMP_SUPPORT_NIKON_PROTOCOL == 1 -#define IRMP_TIMEOUT_NIKON_TIME 29500.0e-6 // 2nd timeout after 29.5 ms darkness (only for NIKON!) -#define IRMP_TIMEOUT_NIKON_TIME_MS 29500L // 2nd timeout after 29.5 ms darkness -typedef uint16_t PAUSE_LEN; -#define IRMP_TIMEOUT_NIKON_LEN (PAUSE_LEN)(F_INTERRUPTS * IRMP_TIMEOUT_NIKON_TIME + 0.5) -#else -#if (F_INTERRUPTS * IRMP_TIMEOUT_TIME_MS) / 1000000 >= 254 -typedef uint16_t PAUSE_LEN; -#else -typedef uint8_t PAUSE_LEN; -#endif -#endif - -#define IRMP_TIMEOUT_LEN (PAUSE_LEN)(F_INTERRUPTS * IRMP_TIMEOUT_TIME + 0.5) - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * IR protocols - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#define IRMP_SIRCS_PROTOCOL 1 // Sony -#define IRMP_NEC_PROTOCOL 2 // NEC, Pioneer, JVC, Toshiba, NoName etc. -#define IRMP_SAMSUNG_PROTOCOL 3 // Samsung -#define IRMP_MATSUSHITA_PROTOCOL 4 // Matsushita -#define IRMP_KASEIKYO_PROTOCOL 5 // Kaseikyo (Panasonic etc) -#define IRMP_RECS80_PROTOCOL 6 // Philips, Thomson, Nordmende, Telefunken, Saba -#define IRMP_RC5_PROTOCOL 7 // Philips etc -#define IRMP_DENON_PROTOCOL 8 // Denon, Sharp -#define IRMP_RC6_PROTOCOL 9 // Philips etc -#define IRMP_SAMSUNG32_PROTOCOL 10 // Samsung32: no sync pulse at bit 16, length 32 instead of 37 -#define IRMP_APPLE_PROTOCOL 11 // Apple, very similar to NEC -#define IRMP_RECS80EXT_PROTOCOL 12 // Philips, Technisat, Thomson, Nordmende, Telefunken, Saba -#define IRMP_NUBERT_PROTOCOL 13 // Nubert -#define IRMP_BANG_OLUFSEN_PROTOCOL 14 // Bang & Olufsen -#define IRMP_GRUNDIG_PROTOCOL 15 // Grundig -#define IRMP_NOKIA_PROTOCOL 16 // Nokia -#define IRMP_SIEMENS_PROTOCOL 17 // Siemens, e.g. Gigaset -#define IRMP_FDC_PROTOCOL 18 // FDC keyboard -#define IRMP_RCCAR_PROTOCOL 19 // RC Car -#define IRMP_JVC_PROTOCOL 20 // JVC (NEC with 16 bits) -#define IRMP_RC6A_PROTOCOL 21 // RC6A, e.g. Kathrein, XBOX -#define IRMP_NIKON_PROTOCOL 22 // Nikon -#define IRMP_RUWIDO_PROTOCOL 23 // Ruwido, e.g. T-Home Mediareceiver -#define IRMP_IR60_PROTOCOL 24 // IR60 (SAB2008) -#define IRMP_KATHREIN_PROTOCOL 25 // Kathrein -#define IRMP_NETBOX_PROTOCOL 26 // Netbox keyboard (bitserial) -#define IRMP_NEC16_PROTOCOL 27 // NEC with 16 bits (incl. sync) -#define IRMP_NEC42_PROTOCOL 28 // NEC with 42 bits -#define IRMP_LEGO_PROTOCOL 29 // LEGO Power Functions RC -#define IRMP_THOMSON_PROTOCOL 30 // Thomson -#define IRMP_GRUNDIG2_PROTOCOL 31 // Grundig, e.g. TP400 - -#define IRMP_N_PROTOCOLS 31 // number of supported protocols - -// some flags of struct IRMP_PARAMETER: -#define IRMP_PARAM_FLAG_IS_MANCHESTER 0x01 -#define IRMP_PARAM_FLAG_1ST_PULSE_IS_1 0x02 -#define IRMP_PARAM_FLAG_IS_SERIAL 0x04 - -#define SIRCS_START_BIT_PULSE_TIME 2400.0e-6 // 2400 usec pulse -#define SIRCS_START_BIT_PAUSE_TIME 600.0e-6 // 600 usec pause -#define SIRCS_1_PULSE_TIME 1200.0e-6 // 1200 usec pulse -#define SIRCS_0_PULSE_TIME 600.0e-6 // 600 usec pulse -#define SIRCS_PAUSE_TIME 600.0e-6 // 600 usec pause -#define SIRCS_FRAMES 3 // SIRCS sends each frame 3 times -#define SIRCS_AUTO_REPETITION_PAUSE_TIME 25.0e-3 // auto repetition after 25ms -#define SIRCS_FRAME_REPEAT_PAUSE_TIME 25.0e-3 // frame repeat after 25ms -#define SIRCS_ADDRESS_OFFSET 15 // skip 15 bits -#define SIRCS_ADDRESS_LEN 5 // read up to 5 address bits -#define SIRCS_COMMAND_OFFSET 0 // skip 0 bits -#define SIRCS_COMMAND_LEN 15 // read 12-15 command bits -#define SIRCS_MINIMUM_DATA_LEN 12 // minimum data length -#define SIRCS_COMPLETE_DATA_LEN 20 // complete length - may be up to 20 -#define SIRCS_STOP_BIT 0 // has no stop bit -#define SIRCS_LSB 1 // LSB...MSB -#define SIRCS_FLAGS 0 // flags - -#define NEC_START_BIT_PULSE_TIME 9000.0e-6 // 9000 usec pulse -#define NEC_START_BIT_PAUSE_TIME 4500.0e-6 // 4500 usec pause -#define NEC_REPEAT_START_BIT_PAUSE_TIME 2250.0e-6 // 2250 usec pause -#define NEC_PULSE_TIME 560.0e-6 // 560 usec pulse -#define NEC_1_PAUSE_TIME 1690.0e-6 // 1690 usec pause -#define NEC_0_PAUSE_TIME 560.0e-6 // 560 usec pause -#define NEC_FRAME_REPEAT_PAUSE_TIME 40.0e-3 // frame repeat after 40ms -#define NEC_ADDRESS_OFFSET 0 // skip 0 bits -#define NEC_ADDRESS_LEN 16 // read 16 address bits -#define NEC_COMMAND_OFFSET 16 // skip 16 bits (8 address + 8 /address) -#define NEC_COMMAND_LEN 16 // read 16 bits (8 command + 8 /command) -#define NEC_COMPLETE_DATA_LEN 32 // complete length -#define NEC_STOP_BIT 1 // has stop bit -#define NEC_LSB 1 // LSB...MSB -#define NEC_FLAGS 0 // flags - -#define NEC42_ADDRESS_OFFSET 0 // skip 0 bits -#define NEC42_ADDRESS_LEN 13 // read 13 address bits -#define NEC42_COMMAND_OFFSET 26 // skip 26 bits (2 x 13 address bits) -#define NEC42_COMMAND_LEN 8 // read 8 command bits -#define NEC42_COMPLETE_DATA_LEN 42 // complete length (2 x 13 + 2 x 8) - -#define NEC16_ADDRESS_OFFSET 0 // skip 0 bits -#define NEC16_ADDRESS_LEN 8 // read 8 address bits -#define NEC16_COMMAND_OFFSET 8 // skip 8 bits (8 address) -#define NEC16_COMMAND_LEN 8 // read 8 bits (8 command) -#define NEC16_COMPLETE_DATA_LEN 16 // complete length - -#define SAMSUNG_START_BIT_PULSE_TIME 4500.0e-6 // 4500 usec pulse -#define SAMSUNG_START_BIT_PAUSE_TIME 4500.0e-6 // 4500 usec pause -#define SAMSUNG_PULSE_TIME 550.0e-6 // 550 usec pulse -#define SAMSUNG_1_PAUSE_TIME 1650.0e-6 // 1650 usec pause -#define SAMSUNG_0_PAUSE_TIME 550.0e-6 // 550 usec pause - -#define SAMSUNG_FRAME_REPEAT_PAUSE_TIME 25.0e-3 // frame repeat after 25ms -#define SAMSUNG_ADDRESS_OFFSET 0 // skip 0 bits -#define SAMSUNG_ADDRESS_LEN 16 // read 16 address bits -#define SAMSUNG_ID_OFFSET 17 // skip 16 + 1 sync bit -#define SAMSUNG_ID_LEN 4 // read 4 id bits -#define SAMSUNG_COMMAND_OFFSET 21 // skip 16 + 1 sync + 4 data bits -#define SAMSUNG_COMMAND_LEN 16 // read 16 command bits -#define SAMSUNG_COMPLETE_DATA_LEN 37 // complete length -#define SAMSUNG_STOP_BIT 1 // has stop bit -#define SAMSUNG_LSB 1 // LSB...MSB? -#define SAMSUNG_FLAGS 0 // flags - -#define SAMSUNG32_COMMAND_OFFSET 16 // skip 16 bits -#define SAMSUNG32_COMMAND_LEN 16 // read 16 command bits -#define SAMSUNG32_COMPLETE_DATA_LEN 32 // complete length -#define SAMSUNG32_FRAMES 1 // SAMSUNG32 sends each frame 1 times -#define SAMSUNG32_AUTO_REPETITION_PAUSE_TIME 47.0e-3 // repetition after 47 ms -#define SAMSUNG32_FRAME_REPEAT_PAUSE_TIME 47.0e-3 // frame repeat after 47ms - -#define MATSUSHITA_START_BIT_PULSE_TIME 3488.0e-6 // 3488 usec pulse -#define MATSUSHITA_START_BIT_PAUSE_TIME 3488.0e-6 // 3488 usec pause -#define MATSUSHITA_PULSE_TIME 872.0e-6 // 872 usec pulse -#define MATSUSHITA_1_PAUSE_TIME 2616.0e-6 // 2616 usec pause -#define MATSUSHITA_0_PAUSE_TIME 872.0e-6 // 872 usec pause -#define MATSUSHITA_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms -#define MATSUSHITA_ADDRESS_OFFSET 12 // skip 12 bits -#define MATSUSHITA_ADDRESS_LEN 12 // read 12 address bits -#define MATSUSHITA_COMMAND_OFFSET 0 // skip 0 bits -#define MATSUSHITA_COMMAND_LEN 12 // read 12 bits (6 custom + 6 command) -#define MATSUSHITA_COMPLETE_DATA_LEN 24 // complete length -#define MATSUSHITA_STOP_BIT 1 // has stop bit -#define MATSUSHITA_LSB 1 // LSB...MSB? -#define MATSUSHITA_FLAGS 0 // flags - -#define KASEIKYO_START_BIT_PULSE_TIME 3380.0e-6 // 3380 usec pulse -#define KASEIKYO_START_BIT_PAUSE_TIME 1690.0e-6 // 1690 usec pause -#define KASEIKYO_PULSE_TIME 423.0e-6 // 525 usec pulse -#define KASEIKYO_1_PAUSE_TIME 1269.0e-6 // 525 usec pause -#define KASEIKYO_0_PAUSE_TIME 423.0e-6 // 1690 usec pause -#define KASEIKYO_AUTO_REPETITION_PAUSE_TIME 74.0e-3 // repetition after 74 ms -#define KASEIKYO_FRAME_REPEAT_PAUSE_TIME 74.0e-3 // frame repeat after 74 ms -#define KASEIKYO_ADDRESS_OFFSET 0 // skip 0 bits -#define KASEIKYO_ADDRESS_LEN 16 // read 16 address bits -#define KASEIKYO_COMMAND_OFFSET 28 // skip 28 bits (16 manufacturer & 4 parity & 8 genre) -#define KASEIKYO_COMMAND_LEN 12 // read 12 command bits (10 real command & 2 id) -#define KASEIKYO_COMPLETE_DATA_LEN 48 // complete length -#define KASEIKYO_STOP_BIT 1 // has stop bit -#define KASEIKYO_LSB 1 // LSB...MSB? -#define KASEIKYO_FRAMES 2 // KASEIKYO sends 1st frame 2 times -#define KASEIKYO_FLAGS 0 // flags - -#define RECS80_START_BIT_PULSE_TIME 158.0e-6 // 158 usec pulse -#define RECS80_START_BIT_PAUSE_TIME 7432.0e-6 // 7432 usec pause -#define RECS80_PULSE_TIME 158.0e-6 // 158 usec pulse -#define RECS80_1_PAUSE_TIME 7432.0e-6 // 7432 usec pause -#define RECS80_0_PAUSE_TIME 4902.0e-6 // 4902 usec pause -#define RECS80_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms -#define RECS80_ADDRESS_OFFSET 1 // skip 1 bit (toggle bit) -#define RECS80_ADDRESS_LEN 3 // read 3 address bits -#define RECS80_COMMAND_OFFSET 4 // skip 4 bits (1 toggle + 3 address) -#define RECS80_COMMAND_LEN 6 // read 6 command bits -#define RECS80_COMPLETE_DATA_LEN 10 // complete length -#define RECS80_STOP_BIT 1 // has stop bit -#define RECS80_LSB 0 // MSB...LSB -#define RECS80_FLAGS 0 // flags - -#define RC5_BIT_TIME 889.0e-6 // 889 usec pulse/pause -#define RC5_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms - -#define RC5_ADDRESS_OFFSET 1 // skip 1 bit (2nd start) -#define RC5_ADDRESS_LEN 6 // read 1 toggle bit (for key repetition detection) + 5 address bits -#define RC5_COMMAND_OFFSET 7 // skip 5 bits (2nd start + 1 toggle + 5 address) -#define RC5_COMMAND_LEN 6 // read 6 command bits -#define RC5_COMPLETE_DATA_LEN 13 // complete length -#define RC5_STOP_BIT 0 // has no stop bit -#define RC5_LSB 0 // MSB...LSB -#define RC5_FLAGS IRMP_PARAM_FLAG_IS_MANCHESTER // flags - -#define DENON_PULSE_TIME 310.0e-6 // 310 usec pulse in practice, 275 in theory -#define DENON_1_PAUSE_TIME 1780.0e-6 // 1780 usec pause in practice, 1900 in theory -#define DENON_0_PAUSE_TIME 745.0e-6 // 745 usec pause in practice, 775 in theory -#define DENON_FRAMES 2 // DENON sends each frame 2 times -#define DENON_AUTO_REPETITION_PAUSE_TIME 65.0e-3 // inverted repetition after 65ms -#define DENON_FRAME_REPEAT_PAUSE_TIME 65.0e-3 // frame repeat after 65ms -#define DENON_ADDRESS_OFFSET 0 // skip 0 bits -#define DENON_ADDRESS_LEN 5 // read 5 address bits -#define DENON_COMMAND_OFFSET 5 // skip 5 -#define DENON_COMMAND_LEN 10 // read 10 command bits -#define DENON_COMPLETE_DATA_LEN 15 // complete length -#define DENON_STOP_BIT 1 // has stop bit -#define DENON_LSB 0 // MSB...LSB -#define DENON_FLAGS 0 // flags - -#define RC6_START_BIT_PULSE_TIME 2666.0e-6 // 2.666 msec pulse -#define RC6_START_BIT_PAUSE_TIME 889.0e-6 // 889 usec pause -#define RC6_TOGGLE_BIT_TIME 889.0e-6 // 889 msec pulse/pause -#define RC6_BIT_TIME 444.0e-6 // 889 usec pulse/pause -#define RC6_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms -#define RC6_ADDRESS_OFFSET 5 // skip "1" + 3 mode bits + 1 toggle bit -#define RC6_ADDRESS_LEN 8 // read 8 address bits -#define RC6_COMMAND_OFFSET 13 // skip 12 bits ("1" + 3 mode + 1 toggle + 8 address) -#define RC6_COMMAND_LEN 8 // read 8 command bits -#define RC6_COMPLETE_DATA_LEN_SHORT 21 // complete length -#define RC6_COMPLETE_DATA_LEN_LONG 36 // complete length -#define RC6_STOP_BIT 0 // has no stop bit -#define RC6_LSB 0 // MSB...LSB -#define RC6_FLAGS (IRMP_PARAM_FLAG_IS_MANCHESTER | IRMP_PARAM_FLAG_1ST_PULSE_IS_1) // flags - -#define RECS80EXT_START_BIT_PULSE_TIME 158.0e-6 // 158 usec pulse -#define RECS80EXT_START_BIT_PAUSE_TIME 3637.0e-6 // 3637 usec pause -#define RECS80EXT_PULSE_TIME 158.0e-6 // 158 usec pulse -#define RECS80EXT_1_PAUSE_TIME 7432.0e-6 // 7432 usec pause -#define RECS80EXT_0_PAUSE_TIME 4902.0e-6 // 4902 usec pause -#define RECS80EXT_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms -#define RECS80EXT_ADDRESS_OFFSET 2 // skip 2 bits (2nd start + 1 toggle) -#define RECS80EXT_ADDRESS_LEN 4 // read 4 address bits -#define RECS80EXT_COMMAND_OFFSET 6 // skip 6 bits (2nd start + 1 toggle + 4 address) -#define RECS80EXT_COMMAND_LEN 6 // read 6 command bits -#define RECS80EXT_COMPLETE_DATA_LEN 12 // complete length -#define RECS80EXT_STOP_BIT 1 // has stop bit -#define RECS80EXT_LSB 0 // MSB...LSB -#define RECS80EXT_FLAGS 0 // flags - -#define NUBERT_START_BIT_PULSE_TIME 1340.0e-6 // 1340 usec pulse -#define NUBERT_START_BIT_PAUSE_TIME 340.0e-6 // 340 usec pause -#define NUBERT_1_PULSE_TIME 1340.0e-6 // 1340 usec pulse -#define NUBERT_1_PAUSE_TIME 340.0e-6 // 340 usec pause -#define NUBERT_0_PULSE_TIME 500.0e-6 // 500 usec pulse -#define NUBERT_0_PAUSE_TIME 1300.0e-6 // 1300 usec pause -#define NUBERT_FRAMES 2 // Nubert sends 2 frames -#define NUBERT_AUTO_REPETITION_PAUSE_TIME 35.0e-3 // auto repetition after 35ms -#define NUBERT_FRAME_REPEAT_PAUSE_TIME 35.0e-3 // frame repeat after 45ms -#define NUBERT_ADDRESS_OFFSET 0 // skip 0 bits -#define NUBERT_ADDRESS_LEN 0 // read 0 address bits -#define NUBERT_COMMAND_OFFSET 0 // skip 0 bits -#define NUBERT_COMMAND_LEN 10 // read 10 bits -#define NUBERT_COMPLETE_DATA_LEN 10 // complete length -#define NUBERT_STOP_BIT 1 // has stop bit -#define NUBERT_LSB 0 // MSB? -#define NUBERT_FLAGS 0 // flags - -#define BANG_OLUFSEN_START_BIT1_PULSE_TIME 200.0e-6 // 200 usec pulse -#define BANG_OLUFSEN_START_BIT1_PAUSE_TIME 3125.0e-6 // 3125 usec pause -#define BANG_OLUFSEN_START_BIT2_PULSE_TIME 200.0e-6 // 200 usec pulse -#define BANG_OLUFSEN_START_BIT2_PAUSE_TIME 3125.0e-6 // 3125 usec pause -#define BANG_OLUFSEN_START_BIT3_PULSE_TIME 200.0e-6 // 200 usec pulse -#define BANG_OLUFSEN_START_BIT3_PAUSE_TIME 15625.0e-6 // 15625 usec pause -#define BANG_OLUFSEN_START_BIT4_PULSE_TIME 200.0e-6 // 200 usec pulse -#define BANG_OLUFSEN_START_BIT4_PAUSE_TIME 3125.0e-6 // 3125 usec pause -#define BANG_OLUFSEN_PULSE_TIME 200.0e-6 // 200 usec pulse -#define BANG_OLUFSEN_1_PAUSE_TIME 9375.0e-6 // 9375 usec pause -#define BANG_OLUFSEN_0_PAUSE_TIME 3125.0e-6 // 3125 usec pause -#define BANG_OLUFSEN_R_PAUSE_TIME 6250.0e-6 // 6250 usec pause (repeat last bit) -#define BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME 12500.0e-6 // 12500 usec pause (trailer bit) -#define BANG_OLUFSEN_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms -#define BANG_OLUFSEN_ADDRESS_OFFSET 0 // no address bits -#define BANG_OLUFSEN_ADDRESS_LEN 0 // no address bits -#define BANG_OLUFSEN_COMMAND_OFFSET 3 // skip startbits 2, 3, 4 -#define BANG_OLUFSEN_COMMAND_LEN 16 // read 16 command bits -#define BANG_OLUFSEN_COMPLETE_DATA_LEN 20 // complete length: startbits 2, 3, 4 + 16 data bits + trailer bit -#define BANG_OLUFSEN_STOP_BIT 1 // has stop bit -#define BANG_OLUFSEN_LSB 0 // MSB...LSB -#define BANG_OLUFSEN_FLAGS 0 // flags - -#define GRUNDIG_NOKIA_IR60_BIT_TIME 528.0e-6 // 528 usec pulse/pause -#define GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME 2639.0e-6 // 2639 usec pause after pre bit -#define GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_TIME 117.76e-3 // info frame repeat after 117.76 ms -#define GRUNDIG_NOKIA_IR60_STOP_BIT 0 // has no stop bit -#define GRUNDIG_NOKIA_IR60_LSB 1 // MSB...LSB -#define GRUNDIG_NOKIA_IR60_FLAGS (IRMP_PARAM_FLAG_IS_MANCHESTER | IRMP_PARAM_FLAG_1ST_PULSE_IS_1) // flags - -#define GRUNDIG_FRAMES 2 // GRUNDIG sends each frame 1+1 times -#define GRUNDIG_AUTO_REPETITION_PAUSE_TIME 20.0e-3 // repetition after 20ms -#define GRUNDIG_ADDRESS_OFFSET 0 // no address -#define GRUNDIG_ADDRESS_LEN 0 // no address -#define GRUNDIG_COMMAND_OFFSET 1 // skip 1 start bit -#define GRUNDIG_COMMAND_LEN 9 // read 9 command bits -#define GRUNDIG_COMPLETE_DATA_LEN 10 // complete length: 1 start bit + 9 data bits - -#define NOKIA_FRAMES 3 // NOKIA sends each frame 1 + 1 + 1 times -#define NOKIA_AUTO_REPETITION_PAUSE_TIME 20.0e-3 // repetition after 20ms -#define NOKIA_ADDRESS_OFFSET 9 // skip 9 bits (1 start bit + 8 data bits) -#define NOKIA_ADDRESS_LEN 8 // 7 address bits -#define NOKIA_COMMAND_OFFSET 1 // skip 1 bit (1 start bit) -#define NOKIA_COMMAND_LEN 8 // read 8 command bits -#define NOKIA_COMPLETE_DATA_LEN 17 // complete length: 1 start bit + 8 address bits + 8 command bits - -#define IR60_TIMEOUT_TIME 5000.0e-6 // timeout grundig frame, switch to IR60 -#define IR60_ADDRESS_OFFSET 0 // skip 1 bits -#define IR60_ADDRESS_LEN 0 // read 0 address bits -#define IR60_COMMAND_OFFSET 0 // skip 1 bit (start bit after pre bit, always 1) -#define IR60_COMMAND_LEN 7 // read 6 command bits -#define IR60_COMPLETE_DATA_LEN 7 // complete length - -#define SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME 275.0e-6 // 275 usec pulse -#define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME 550.0e-6 // 550 usec pause -#define SIEMENS_OR_RUWIDO_BIT_PULSE_TIME 275.0e-6 // 275 usec short pulse -#define SIEMENS_OR_RUWIDO_BIT_PULSE_TIME_2 550.0e-6 // 550 usec long pulse -#define SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME 275.0e-6 // 275 usec short pause -#define SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME_2 550.0e-6 // 550 usec long pause -#define SIEMENS_OR_RUWIDO_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms -#define SIEMENS_OR_RUWIDO_STOP_BIT 0 // has no stop bit -#define SIEMENS_OR_RUWIDO_LSB 0 // MSB...LSB -#define SIEMENS_OR_RUWIDO_FLAGS (IRMP_PARAM_FLAG_IS_MANCHESTER | IRMP_PARAM_FLAG_1ST_PULSE_IS_1) // flags - -#define RUWIDO_ADDRESS_OFFSET 0 // skip 0 bits -#define RUWIDO_ADDRESS_LEN 9 // read 9 address bits -#define RUWIDO_COMMAND_OFFSET 9 // skip 9 bits -#define RUWIDO_COMMAND_LEN 8 // read 7 + 1 command bits, last bit is only check bit -#define RUWIDO_COMPLETE_DATA_LEN 17 // complete length - -#define SIEMENS_ADDRESS_OFFSET 0 // skip 0 bits -#define SIEMENS_ADDRESS_LEN 11 // read 11 bits -#define SIEMENS_COMMAND_OFFSET 11 // skip 11 bits -#define SIEMENS_COMMAND_LEN 11 // read 10 + 1 command bits, last bit is only check bit -#define SIEMENS_COMPLETE_DATA_LEN 22 // complete length - -#define FDC_START_BIT_PULSE_TIME 2085.0e-6 // 2085 usec pulse -#define FDC_START_BIT_PAUSE_TIME 966.0e-6 // 966 usec pause -#define FDC_PULSE_TIME 300.0e-6 // 300 usec pulse -#define FDC_1_PAUSE_TIME 715.0e-6 // 715 usec pause -#define FDC_0_PAUSE_TIME 220.0e-6 // 220 usec pause -#define FDC_FRAME_REPEAT_PAUSE_TIME 60.0e-3 // frame repeat after 60ms -#define FDC_ADDRESS_OFFSET 0 // skip 0 bits -#define FDC_ADDRESS_LEN 14 // read 14 address bits, but use only 6, shift 8 into command -#define FDC_COMMAND_OFFSET 20 // skip 20 bits -#define FDC_COMMAND_LEN 12 // read 12 bits -#define FDC_COMPLETE_DATA_LEN 40 // complete length -#define FDC_STOP_BIT 1 // has stop bit -#define FDC_LSB 1 // LSB...MSB -#define FDC_FLAGS 0 // flags - -#define RCCAR_START_BIT_PULSE_TIME 2000.0e-6 // 2000 usec pulse -#define RCCAR_START_BIT_PAUSE_TIME 2000.0e-6 // 2000 usec pause -#define RCCAR_PULSE_TIME 600.0e-6 // 360 usec pulse -#define RCCAR_1_PAUSE_TIME 450.0e-6 // 650 usec pause -#define RCCAR_0_PAUSE_TIME 900.0e-6 // 180 usec pause -#define RCCAR_FRAME_REPEAT_PAUSE_TIME 40.0e-3 // frame repeat after 40ms -#define RCCAR_ADDRESS_OFFSET 0 // skip 0 bits -#define RCCAR_ADDRESS_LEN 0 // read 0 address bits -#define RCCAR_COMMAND_OFFSET 0 // skip 0 bits -#define RCCAR_COMMAND_LEN 13 // read 13 bits -#define RCCAR_COMPLETE_DATA_LEN 13 // complete length -#define RCCAR_STOP_BIT 1 // has stop bit -#define RCCAR_LSB 1 // LSB...MSB -#define RCCAR_FLAGS 0 // flags - -#define JVC_START_BIT_PULSE_TIME 9000.0e-6 // 9000 usec pulse -#define JVC_START_BIT_PAUSE_TIME 4500.0e-6 // 4500 usec pause -#define JVC_PULSE_TIME 560.0e-6 // 560 usec pulse -#define JVC_1_PAUSE_TIME 1690.0e-6 // 1690 usec pause -#define JVC_0_PAUSE_TIME 560.0e-6 // 560 usec pause -#define JVC_FRAME_REPEAT_PAUSE_TIME 22.0e-3 // frame repeat after 22ms -#define JVC_ADDRESS_OFFSET 0 // skip 0 bits -#define JVC_ADDRESS_LEN 4 // read 4 address bits -#define JVC_COMMAND_OFFSET 4 // skip 4 bits -#define JVC_COMMAND_LEN 12 // read 12 bits -#define JVC_COMPLETE_DATA_LEN 16 // complete length -#define JVC_STOP_BIT 1 // has stop bit -#define JVC_LSB 1 // LSB...MSB -#define JVC_FLAGS 0 // flags - -#define NIKON_START_BIT_PULSE_TIME 2200.0e-6 // 2200 usec pulse -#define NIKON_START_BIT_PAUSE_TIME 27100.0e-6 // 27100 usec pause -#define NIKON_PULSE_TIME 500.0e-6 // 500 usec pulse -#define NIKON_1_PAUSE_TIME 3500.0e-6 // 3500 usec pause -#define NIKON_0_PAUSE_TIME 1500.0e-6 // 1500 usec pause -#define NIKON_FRAME_REPEAT_PAUSE_TIME 60.0e-3 // frame repeat after 60ms -#define NIKON_ADDRESS_OFFSET 0 // skip 0 bits -#define NIKON_ADDRESS_LEN 0 // read 0 address bits -#define NIKON_COMMAND_OFFSET 0 // skip 0 bits -#define NIKON_COMMAND_LEN 2 // read 2 bits -#define NIKON_COMPLETE_DATA_LEN 2 // complete length -#define NIKON_STOP_BIT 1 // has stop bit -#define NIKON_LSB 0 // LSB...MSB -#define NIKON_FLAGS 0 // flags - -#define KATHREIN_START_BIT_PULSE_TIME 210.0e-6 // 1340 usec pulse -#define KATHREIN_START_BIT_PAUSE_TIME 6218.0e-6 // 340 usec pause -#define KATHREIN_1_PULSE_TIME 210.0e-6 // 1340 usec pulse -#define KATHREIN_1_PAUSE_TIME 3000.0e-6 // 340 usec pause -#define KATHREIN_0_PULSE_TIME 210.0e-6 // 500 usec pulse -#define KATHREIN_0_PAUSE_TIME 1400.0e-6 // 1300 usec pause -#define KATHREIN_SYNC_BIT_PAUSE_LEN_TIME 4600.0e-6 // 4600 usec sync (on 6th and/or 8th bit) -#define KATHREIN_FRAMES 1 // Kathrein sends 1 frame -#define KATHREIN_AUTO_REPETITION_PAUSE_TIME 35.0e-3 // auto repetition after 35ms -#define KATHREIN_FRAME_REPEAT_PAUSE_TIME 35.0e-3 // frame repeat after 35ms -#define KATHREIN_ADDRESS_OFFSET 1 // skip 1 bits -#define KATHREIN_ADDRESS_LEN 4 // read 4 address bits -#define KATHREIN_COMMAND_OFFSET 5 // skip 5 bits -#define KATHREIN_COMMAND_LEN 7 // read 7 bits -#define KATHREIN_COMPLETE_DATA_LEN 13 // complete length -#define KATHREIN_STOP_BIT 1 // has stop bit -#define KATHREIN_LSB 0 // MSB -#define KATHREIN_FLAGS 0 // flags - -#define NETBOX_START_BIT_PULSE_TIME 2400.0e-6 // 2400 usec pulse -#define NETBOX_START_BIT_PAUSE_TIME 800.0e-6 // 800 usec pause -#define NETBOX_PULSE_TIME 800.0e-6 // 800 usec pulse -#define NETBOX_PAUSE_TIME 800.0e-6 // 800 usec pause -#define NETBOX_FRAMES 1 // Netbox sends 1 frame -#define NETBOX_AUTO_REPETITION_PAUSE_TIME 35.0e-3 // auto repetition after 35ms -#define NETBOX_FRAME_REPEAT_PAUSE_TIME 35.0e-3 // frame repeat after 35ms -#define NETBOX_ADDRESS_OFFSET 0 // skip 0 bits -#define NETBOX_ADDRESS_LEN 3 // read 3 address bits -#define NETBOX_COMMAND_OFFSET 3 // skip 3 bits -#define NETBOX_COMMAND_LEN 13 // read 13 bits -#define NETBOX_COMPLETE_DATA_LEN 16 // complete length -#define NETBOX_STOP_BIT 0 // has no stop bit -#define NETBOX_LSB 1 // LSB -#define NETBOX_FLAGS IRMP_PARAM_FLAG_IS_SERIAL // flags - -#define LEGO_START_BIT_PULSE_TIME 158.0e-6 // 158 usec pulse ( 6 x 1/38kHz) -#define LEGO_START_BIT_PAUSE_TIME 1026.0e-6 // 1026 usec pause (39 x 1/38kHz) -#define LEGO_PULSE_TIME 158.0e-6 // 158 usec pulse ( 6 x 1/38kHz) -#define LEGO_1_PAUSE_TIME 553.0e-6 // 553 usec pause (21 x 1/38kHz) -#define LEGO_0_PAUSE_TIME 263.0e-6 // 263 usec pause (10 x 1/38kHz) -#define LEGO_FRAME_REPEAT_PAUSE_TIME 40.0e-3 // frame repeat after 40ms -#define LEGO_ADDRESS_OFFSET 0 // skip 0 bits -#define LEGO_ADDRESS_LEN 0 // read 0 address bits -#define LEGO_COMMAND_OFFSET 0 // skip 0 bits -#define LEGO_COMMAND_LEN 16 // read 16 bits (12 command + 4 CRC) -#define LEGO_COMPLETE_DATA_LEN 16 // complete length -#define LEGO_STOP_BIT 1 // has stop bit -#define LEGO_LSB 0 // MSB...LSB -#define LEGO_FLAGS 0 // flags - -#define THOMSON_PULSE_TIME 550.0e-6 // 550 usec pulse -#define THOMSON_1_PAUSE_TIME 4500.0e-6 // 4500 usec pause -#define THOMSON_0_PAUSE_TIME 2000.0e-6 // 2000 usec pause -#define THOMSON_FRAMES 1 // THOMSON sends 1 frame -#define THOMSON_AUTO_REPETITION_PAUSE_TIME 65.0e-3 // repetition after 65ms -#define THOMSON_FRAME_REPEAT_PAUSE_TIME 65.0e-3 // frame repeat after 65ms -#define THOMSON_ADDRESS_OFFSET 0 // skip 0 bits -#define THOMSON_ADDRESS_LEN 4 // read 4 address bits -#define THOMSON_COMMAND_OFFSET 5 // skip 4 address bits + 1 toggle bit -#define THOMSON_COMMAND_LEN 7 // read 7 command bits -#define THOMSON_COMPLETE_DATA_LEN 12 // complete length -#define THOMSON_STOP_BIT 1 // has stop bit -#define THOMSON_LSB 0 // MSB...LSB -#define THOMSON_FLAGS 0 // flags - -#define GRUNDIG2_START_BIT_PULSE_TIME 550.0e-6 // 550 usec pulse -#define GRUNDIG2_START_BIT_PAUSE_TIME 2700.0e-6 // 2700 usec pause -#define GRUNDIG2_BIT_PULSE_TIME 550.0e-6 // 550 usec short pulse -#define GRUNDIG2_BIT_PAUSE_TIME 550.0e-6 // 550 usec short pause -#define GRUNDIG2_FRAME_REPEAT_PAUSE_TIME 100.0e-3 // frame repeat after 100ms -#define GRUNDIG2_STOP_BIT 0 // has no stop bit -#define GRUNDIG2_LSB 1 // MSB...LSB -#define GRUNDIG2_FLAGS (IRMP_PARAM_FLAG_IS_MANCHESTER | IRMP_PARAM_FLAG_1ST_PULSE_IS_1) // flags -#define GRUNDIG2_ADDRESS_OFFSET 0 // skip 0 bits -#define GRUNDIG2_ADDRESS_LEN 0 // read 0 bits -#define GRUNDIG2_COMMAND_OFFSET 0 // skip 0 bits -#define GRUNDIG2_COMMAND_LEN 7 // read 6 + 1 command bits, last bit is always 1 -#define GRUNDIG2_COMPLETE_DATA_LEN 7 // complete length - -#define AUTO_FRAME_REPETITION_TIME 80.0e-3 // SIRCS/SAMSUNG32/NUBERT: automatic repetition after 25-50ms - // KASEIKYO: automatic repetition after 75ms - -#define TRUE 1 -#define FALSE 0 - -#define IRMP_FLAG_REPETITION 0x01 - -typedef struct -{ - uint8_t protocol; // protocol, i.e. NEC_PROTOCOL - uint16_t address; // address - uint16_t command; // command - uint8_t flags; // flags, e.g. repetition -} IRMP_DATA; - -extern void irmp_init (void); -extern uint8_t irmp_get_data (IRMP_DATA *); -extern uint8_t irmp_is_busy (void); -extern uint8_t irmp_ISR (uint8_t); - -#if IRMP_PROTOCOL_NAMES == 1 -extern char * irmp_protocol_names[IRMP_N_PROTOCOLS + 1]; -#endif - -#if IRMP_USE_CALLBACK == 1 -extern void irmp_set_callback_ptr (void (*cb)(uint8_t)); -#endif // IRSND_USE_CALLBACK == 1 - -#endif /* _WC_IRMP_H_ */ +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * irmp.h + * + * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de + * + * $Id: irmp.h,v 1.70 2012/02/21 08:41:46 fm Exp $ + * + * ATMEGA88 @ 8 MHz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ + +#ifndef _WC_IRMP_H_ +#define _WC_IRMP_H_ + +#if defined(__18CXX) // Microchip C18 declaration of missing typedef +typedef unsigned char uint8_t; +typedef unsigned int uint16_t; +#endif //Microchip C18 + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * timing constants: + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +// fm 22.09.2011: may not be more than 16000L, otherwise some JVC codes will not be accepted +#define IRMP_TIMEOUT_TIME 15500.0e-6 // timeout after 15.5 ms darkness +#define IRMP_TIMEOUT_TIME_MS 15500L // timeout after 15.5 ms darkness + +#if IRMP_SUPPORT_NIKON_PROTOCOL == 1 +#define IRMP_TIMEOUT_NIKON_TIME 29500.0e-6 // 2nd timeout after 29.5 ms darkness (only for NIKON!) +#define IRMP_TIMEOUT_NIKON_TIME_MS 29500L // 2nd timeout after 29.5 ms darkness +typedef uint16_t PAUSE_LEN; +#define IRMP_TIMEOUT_NIKON_LEN (PAUSE_LEN)(F_INTERRUPTS * IRMP_TIMEOUT_NIKON_TIME + 0.5) +#else +#if (F_INTERRUPTS * IRMP_TIMEOUT_TIME_MS) / 1000000 >= 254 +typedef uint16_t PAUSE_LEN; +#else +typedef uint8_t PAUSE_LEN; +#endif +#endif + +#define IRMP_TIMEOUT_LEN (PAUSE_LEN)(F_INTERRUPTS * IRMP_TIMEOUT_TIME + 0.5) + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * IR protocols + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#define IRMP_SIRCS_PROTOCOL 1 // Sony +#define IRMP_NEC_PROTOCOL 2 // NEC, Pioneer, JVC, Toshiba, NoName etc. +#define IRMP_SAMSUNG_PROTOCOL 3 // Samsung +#define IRMP_MATSUSHITA_PROTOCOL 4 // Matsushita +#define IRMP_KASEIKYO_PROTOCOL 5 // Kaseikyo (Panasonic etc) +#define IRMP_RECS80_PROTOCOL 6 // Philips, Thomson, Nordmende, Telefunken, Saba +#define IRMP_RC5_PROTOCOL 7 // Philips etc +#define IRMP_DENON_PROTOCOL 8 // Denon, Sharp +#define IRMP_RC6_PROTOCOL 9 // Philips etc +#define IRMP_SAMSUNG32_PROTOCOL 10 // Samsung32: no sync pulse at bit 16, length 32 instead of 37 +#define IRMP_APPLE_PROTOCOL 11 // Apple, very similar to NEC +#define IRMP_RECS80EXT_PROTOCOL 12 // Philips, Technisat, Thomson, Nordmende, Telefunken, Saba +#define IRMP_NUBERT_PROTOCOL 13 // Nubert +#define IRMP_BANG_OLUFSEN_PROTOCOL 14 // Bang & Olufsen +#define IRMP_GRUNDIG_PROTOCOL 15 // Grundig +#define IRMP_NOKIA_PROTOCOL 16 // Nokia +#define IRMP_SIEMENS_PROTOCOL 17 // Siemens, e.g. Gigaset +#define IRMP_FDC_PROTOCOL 18 // FDC keyboard +#define IRMP_RCCAR_PROTOCOL 19 // RC Car +#define IRMP_JVC_PROTOCOL 20 // JVC (NEC with 16 bits) +#define IRMP_RC6A_PROTOCOL 21 // RC6A, e.g. Kathrein, XBOX +#define IRMP_NIKON_PROTOCOL 22 // Nikon +#define IRMP_RUWIDO_PROTOCOL 23 // Ruwido, e.g. T-Home Mediareceiver +#define IRMP_IR60_PROTOCOL 24 // IR60 (SAB2008) +#define IRMP_KATHREIN_PROTOCOL 25 // Kathrein +#define IRMP_NETBOX_PROTOCOL 26 // Netbox keyboard (bitserial) +#define IRMP_NEC16_PROTOCOL 27 // NEC with 16 bits (incl. sync) +#define IRMP_NEC42_PROTOCOL 28 // NEC with 42 bits +#define IRMP_LEGO_PROTOCOL 29 // LEGO Power Functions RC +#define IRMP_THOMSON_PROTOCOL 30 // Thomson +#define IRMP_GRUNDIG2_PROTOCOL 31 // Grundig, e.g. TP400 + +#define IRMP_N_PROTOCOLS 31 // number of supported protocols + +// some flags of struct IRMP_PARAMETER: +#define IRMP_PARAM_FLAG_IS_MANCHESTER 0x01 +#define IRMP_PARAM_FLAG_1ST_PULSE_IS_1 0x02 +#define IRMP_PARAM_FLAG_IS_SERIAL 0x04 + +#define SIRCS_START_BIT_PULSE_TIME 2400.0e-6 // 2400 usec pulse +#define SIRCS_START_BIT_PAUSE_TIME 600.0e-6 // 600 usec pause +#define SIRCS_1_PULSE_TIME 1200.0e-6 // 1200 usec pulse +#define SIRCS_0_PULSE_TIME 600.0e-6 // 600 usec pulse +#define SIRCS_PAUSE_TIME 600.0e-6 // 600 usec pause +#define SIRCS_FRAMES 3 // SIRCS sends each frame 3 times +#define SIRCS_AUTO_REPETITION_PAUSE_TIME 25.0e-3 // auto repetition after 25ms +#define SIRCS_FRAME_REPEAT_PAUSE_TIME 25.0e-3 // frame repeat after 25ms +#define SIRCS_ADDRESS_OFFSET 15 // skip 15 bits +#define SIRCS_ADDRESS_LEN 5 // read up to 5 address bits +#define SIRCS_COMMAND_OFFSET 0 // skip 0 bits +#define SIRCS_COMMAND_LEN 15 // read 12-15 command bits +#define SIRCS_MINIMUM_DATA_LEN 12 // minimum data length +#define SIRCS_COMPLETE_DATA_LEN 20 // complete length - may be up to 20 +#define SIRCS_STOP_BIT 0 // has no stop bit +#define SIRCS_LSB 1 // LSB...MSB +#define SIRCS_FLAGS 0 // flags + +#define NEC_START_BIT_PULSE_TIME 9000.0e-6 // 9000 usec pulse +#define NEC_START_BIT_PAUSE_TIME 4500.0e-6 // 4500 usec pause +#define NEC_REPEAT_START_BIT_PAUSE_TIME 2250.0e-6 // 2250 usec pause +#define NEC_PULSE_TIME 560.0e-6 // 560 usec pulse +#define NEC_1_PAUSE_TIME 1690.0e-6 // 1690 usec pause +#define NEC_0_PAUSE_TIME 560.0e-6 // 560 usec pause +#define NEC_FRAME_REPEAT_PAUSE_TIME 40.0e-3 // frame repeat after 40ms +#define NEC_ADDRESS_OFFSET 0 // skip 0 bits +#define NEC_ADDRESS_LEN 16 // read 16 address bits +#define NEC_COMMAND_OFFSET 16 // skip 16 bits (8 address + 8 /address) +#define NEC_COMMAND_LEN 16 // read 16 bits (8 command + 8 /command) +#define NEC_COMPLETE_DATA_LEN 32 // complete length +#define NEC_STOP_BIT 1 // has stop bit +#define NEC_LSB 1 // LSB...MSB +#define NEC_FLAGS 0 // flags + +#define NEC42_ADDRESS_OFFSET 0 // skip 0 bits +#define NEC42_ADDRESS_LEN 13 // read 13 address bits +#define NEC42_COMMAND_OFFSET 26 // skip 26 bits (2 x 13 address bits) +#define NEC42_COMMAND_LEN 8 // read 8 command bits +#define NEC42_COMPLETE_DATA_LEN 42 // complete length (2 x 13 + 2 x 8) + +#define NEC16_ADDRESS_OFFSET 0 // skip 0 bits +#define NEC16_ADDRESS_LEN 8 // read 8 address bits +#define NEC16_COMMAND_OFFSET 8 // skip 8 bits (8 address) +#define NEC16_COMMAND_LEN 8 // read 8 bits (8 command) +#define NEC16_COMPLETE_DATA_LEN 16 // complete length + +#define SAMSUNG_START_BIT_PULSE_TIME 4500.0e-6 // 4500 usec pulse +#define SAMSUNG_START_BIT_PAUSE_TIME 4500.0e-6 // 4500 usec pause +#define SAMSUNG_PULSE_TIME 550.0e-6 // 550 usec pulse +#define SAMSUNG_1_PAUSE_TIME 1650.0e-6 // 1650 usec pause +#define SAMSUNG_0_PAUSE_TIME 550.0e-6 // 550 usec pause + +#define SAMSUNG_FRAME_REPEAT_PAUSE_TIME 25.0e-3 // frame repeat after 25ms +#define SAMSUNG_ADDRESS_OFFSET 0 // skip 0 bits +#define SAMSUNG_ADDRESS_LEN 16 // read 16 address bits +#define SAMSUNG_ID_OFFSET 17 // skip 16 + 1 sync bit +#define SAMSUNG_ID_LEN 4 // read 4 id bits +#define SAMSUNG_COMMAND_OFFSET 21 // skip 16 + 1 sync + 4 data bits +#define SAMSUNG_COMMAND_LEN 16 // read 16 command bits +#define SAMSUNG_COMPLETE_DATA_LEN 37 // complete length +#define SAMSUNG_STOP_BIT 1 // has stop bit +#define SAMSUNG_LSB 1 // LSB...MSB? +#define SAMSUNG_FLAGS 0 // flags + +#define SAMSUNG32_COMMAND_OFFSET 16 // skip 16 bits +#define SAMSUNG32_COMMAND_LEN 16 // read 16 command bits +#define SAMSUNG32_COMPLETE_DATA_LEN 32 // complete length +#define SAMSUNG32_FRAMES 1 // SAMSUNG32 sends each frame 1 times +#define SAMSUNG32_AUTO_REPETITION_PAUSE_TIME 47.0e-3 // repetition after 47 ms +#define SAMSUNG32_FRAME_REPEAT_PAUSE_TIME 47.0e-3 // frame repeat after 47ms + +#define MATSUSHITA_START_BIT_PULSE_TIME 3488.0e-6 // 3488 usec pulse +#define MATSUSHITA_START_BIT_PAUSE_TIME 3488.0e-6 // 3488 usec pause +#define MATSUSHITA_PULSE_TIME 872.0e-6 // 872 usec pulse +#define MATSUSHITA_1_PAUSE_TIME 2616.0e-6 // 2616 usec pause +#define MATSUSHITA_0_PAUSE_TIME 872.0e-6 // 872 usec pause +#define MATSUSHITA_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms +#define MATSUSHITA_ADDRESS_OFFSET 12 // skip 12 bits +#define MATSUSHITA_ADDRESS_LEN 12 // read 12 address bits +#define MATSUSHITA_COMMAND_OFFSET 0 // skip 0 bits +#define MATSUSHITA_COMMAND_LEN 12 // read 12 bits (6 custom + 6 command) +#define MATSUSHITA_COMPLETE_DATA_LEN 24 // complete length +#define MATSUSHITA_STOP_BIT 1 // has stop bit +#define MATSUSHITA_LSB 1 // LSB...MSB? +#define MATSUSHITA_FLAGS 0 // flags + +#define KASEIKYO_START_BIT_PULSE_TIME 3380.0e-6 // 3380 usec pulse +#define KASEIKYO_START_BIT_PAUSE_TIME 1690.0e-6 // 1690 usec pause +#define KASEIKYO_PULSE_TIME 423.0e-6 // 525 usec pulse +#define KASEIKYO_1_PAUSE_TIME 1269.0e-6 // 525 usec pause +#define KASEIKYO_0_PAUSE_TIME 423.0e-6 // 1690 usec pause +#define KASEIKYO_AUTO_REPETITION_PAUSE_TIME 74.0e-3 // repetition after 74 ms +#define KASEIKYO_FRAME_REPEAT_PAUSE_TIME 74.0e-3 // frame repeat after 74 ms +#define KASEIKYO_ADDRESS_OFFSET 0 // skip 0 bits +#define KASEIKYO_ADDRESS_LEN 16 // read 16 address bits +#define KASEIKYO_COMMAND_OFFSET 28 // skip 28 bits (16 manufacturer & 4 parity & 8 genre) +#define KASEIKYO_COMMAND_LEN 12 // read 12 command bits (10 real command & 2 id) +#define KASEIKYO_COMPLETE_DATA_LEN 48 // complete length +#define KASEIKYO_STOP_BIT 1 // has stop bit +#define KASEIKYO_LSB 1 // LSB...MSB? +#define KASEIKYO_FRAMES 2 // KASEIKYO sends 1st frame 2 times +#define KASEIKYO_FLAGS 0 // flags + +#define RECS80_START_BIT_PULSE_TIME 158.0e-6 // 158 usec pulse +#define RECS80_START_BIT_PAUSE_TIME 7432.0e-6 // 7432 usec pause +#define RECS80_PULSE_TIME 158.0e-6 // 158 usec pulse +#define RECS80_1_PAUSE_TIME 7432.0e-6 // 7432 usec pause +#define RECS80_0_PAUSE_TIME 4902.0e-6 // 4902 usec pause +#define RECS80_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms +#define RECS80_ADDRESS_OFFSET 1 // skip 1 bit (toggle bit) +#define RECS80_ADDRESS_LEN 3 // read 3 address bits +#define RECS80_COMMAND_OFFSET 4 // skip 4 bits (1 toggle + 3 address) +#define RECS80_COMMAND_LEN 6 // read 6 command bits +#define RECS80_COMPLETE_DATA_LEN 10 // complete length +#define RECS80_STOP_BIT 1 // has stop bit +#define RECS80_LSB 0 // MSB...LSB +#define RECS80_FLAGS 0 // flags + +#define RC5_BIT_TIME 889.0e-6 // 889 usec pulse/pause +#define RC5_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms + +#define RC5_ADDRESS_OFFSET 1 // skip 1 bit (2nd start) +#define RC5_ADDRESS_LEN 6 // read 1 toggle bit (for key repetition detection) + 5 address bits +#define RC5_COMMAND_OFFSET 7 // skip 5 bits (2nd start + 1 toggle + 5 address) +#define RC5_COMMAND_LEN 6 // read 6 command bits +#define RC5_COMPLETE_DATA_LEN 13 // complete length +#define RC5_STOP_BIT 0 // has no stop bit +#define RC5_LSB 0 // MSB...LSB +#define RC5_FLAGS IRMP_PARAM_FLAG_IS_MANCHESTER // flags + +#define DENON_PULSE_TIME 310.0e-6 // 310 usec pulse in practice, 275 in theory +#define DENON_1_PAUSE_TIME 1780.0e-6 // 1780 usec pause in practice, 1900 in theory +#define DENON_0_PAUSE_TIME 745.0e-6 // 745 usec pause in practice, 775 in theory +#define DENON_FRAMES 2 // DENON sends each frame 2 times +#define DENON_AUTO_REPETITION_PAUSE_TIME 65.0e-3 // inverted repetition after 65ms +#define DENON_FRAME_REPEAT_PAUSE_TIME 65.0e-3 // frame repeat after 65ms +#define DENON_ADDRESS_OFFSET 0 // skip 0 bits +#define DENON_ADDRESS_LEN 5 // read 5 address bits +#define DENON_COMMAND_OFFSET 5 // skip 5 +#define DENON_COMMAND_LEN 10 // read 10 command bits +#define DENON_COMPLETE_DATA_LEN 15 // complete length +#define DENON_STOP_BIT 1 // has stop bit +#define DENON_LSB 0 // MSB...LSB +#define DENON_FLAGS 0 // flags + +#define RC6_START_BIT_PULSE_TIME 2666.0e-6 // 2.666 msec pulse +#define RC6_START_BIT_PAUSE_TIME 889.0e-6 // 889 usec pause +#define RC6_TOGGLE_BIT_TIME 889.0e-6 // 889 msec pulse/pause +#define RC6_BIT_TIME 444.0e-6 // 889 usec pulse/pause +#define RC6_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms +#define RC6_ADDRESS_OFFSET 5 // skip "1" + 3 mode bits + 1 toggle bit +#define RC6_ADDRESS_LEN 8 // read 8 address bits +#define RC6_COMMAND_OFFSET 13 // skip 12 bits ("1" + 3 mode + 1 toggle + 8 address) +#define RC6_COMMAND_LEN 8 // read 8 command bits +#define RC6_COMPLETE_DATA_LEN_SHORT 21 // complete length +#define RC6_COMPLETE_DATA_LEN_LONG 36 // complete length +#define RC6_STOP_BIT 0 // has no stop bit +#define RC6_LSB 0 // MSB...LSB +#define RC6_FLAGS (IRMP_PARAM_FLAG_IS_MANCHESTER | IRMP_PARAM_FLAG_1ST_PULSE_IS_1) // flags + +#define RECS80EXT_START_BIT_PULSE_TIME 158.0e-6 // 158 usec pulse +#define RECS80EXT_START_BIT_PAUSE_TIME 3637.0e-6 // 3637 usec pause +#define RECS80EXT_PULSE_TIME 158.0e-6 // 158 usec pulse +#define RECS80EXT_1_PAUSE_TIME 7432.0e-6 // 7432 usec pause +#define RECS80EXT_0_PAUSE_TIME 4902.0e-6 // 4902 usec pause +#define RECS80EXT_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms +#define RECS80EXT_ADDRESS_OFFSET 2 // skip 2 bits (2nd start + 1 toggle) +#define RECS80EXT_ADDRESS_LEN 4 // read 4 address bits +#define RECS80EXT_COMMAND_OFFSET 6 // skip 6 bits (2nd start + 1 toggle + 4 address) +#define RECS80EXT_COMMAND_LEN 6 // read 6 command bits +#define RECS80EXT_COMPLETE_DATA_LEN 12 // complete length +#define RECS80EXT_STOP_BIT 1 // has stop bit +#define RECS80EXT_LSB 0 // MSB...LSB +#define RECS80EXT_FLAGS 0 // flags + +#define NUBERT_START_BIT_PULSE_TIME 1340.0e-6 // 1340 usec pulse +#define NUBERT_START_BIT_PAUSE_TIME 340.0e-6 // 340 usec pause +#define NUBERT_1_PULSE_TIME 1340.0e-6 // 1340 usec pulse +#define NUBERT_1_PAUSE_TIME 340.0e-6 // 340 usec pause +#define NUBERT_0_PULSE_TIME 500.0e-6 // 500 usec pulse +#define NUBERT_0_PAUSE_TIME 1300.0e-6 // 1300 usec pause +#define NUBERT_FRAMES 2 // Nubert sends 2 frames +#define NUBERT_AUTO_REPETITION_PAUSE_TIME 35.0e-3 // auto repetition after 35ms +#define NUBERT_FRAME_REPEAT_PAUSE_TIME 35.0e-3 // frame repeat after 45ms +#define NUBERT_ADDRESS_OFFSET 0 // skip 0 bits +#define NUBERT_ADDRESS_LEN 0 // read 0 address bits +#define NUBERT_COMMAND_OFFSET 0 // skip 0 bits +#define NUBERT_COMMAND_LEN 10 // read 10 bits +#define NUBERT_COMPLETE_DATA_LEN 10 // complete length +#define NUBERT_STOP_BIT 1 // has stop bit +#define NUBERT_LSB 0 // MSB? +#define NUBERT_FLAGS 0 // flags + +#define BANG_OLUFSEN_START_BIT1_PULSE_TIME 200.0e-6 // 200 usec pulse +#define BANG_OLUFSEN_START_BIT1_PAUSE_TIME 3125.0e-6 // 3125 usec pause +#define BANG_OLUFSEN_START_BIT2_PULSE_TIME 200.0e-6 // 200 usec pulse +#define BANG_OLUFSEN_START_BIT2_PAUSE_TIME 3125.0e-6 // 3125 usec pause +#define BANG_OLUFSEN_START_BIT3_PULSE_TIME 200.0e-6 // 200 usec pulse +#define BANG_OLUFSEN_START_BIT3_PAUSE_TIME 15625.0e-6 // 15625 usec pause +#define BANG_OLUFSEN_START_BIT4_PULSE_TIME 200.0e-6 // 200 usec pulse +#define BANG_OLUFSEN_START_BIT4_PAUSE_TIME 3125.0e-6 // 3125 usec pause +#define BANG_OLUFSEN_PULSE_TIME 200.0e-6 // 200 usec pulse +#define BANG_OLUFSEN_1_PAUSE_TIME 9375.0e-6 // 9375 usec pause +#define BANG_OLUFSEN_0_PAUSE_TIME 3125.0e-6 // 3125 usec pause +#define BANG_OLUFSEN_R_PAUSE_TIME 6250.0e-6 // 6250 usec pause (repeat last bit) +#define BANG_OLUFSEN_TRAILER_BIT_PAUSE_TIME 12500.0e-6 // 12500 usec pause (trailer bit) +#define BANG_OLUFSEN_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms +#define BANG_OLUFSEN_ADDRESS_OFFSET 0 // no address bits +#define BANG_OLUFSEN_ADDRESS_LEN 0 // no address bits +#define BANG_OLUFSEN_COMMAND_OFFSET 3 // skip startbits 2, 3, 4 +#define BANG_OLUFSEN_COMMAND_LEN 16 // read 16 command bits +#define BANG_OLUFSEN_COMPLETE_DATA_LEN 20 // complete length: startbits 2, 3, 4 + 16 data bits + trailer bit +#define BANG_OLUFSEN_STOP_BIT 1 // has stop bit +#define BANG_OLUFSEN_LSB 0 // MSB...LSB +#define BANG_OLUFSEN_FLAGS 0 // flags + +#define GRUNDIG_NOKIA_IR60_BIT_TIME 528.0e-6 // 528 usec pulse/pause +#define GRUNDIG_NOKIA_IR60_PRE_PAUSE_TIME 2639.0e-6 // 2639 usec pause after pre bit +#define GRUNDIG_NOKIA_IR60_FRAME_REPEAT_PAUSE_TIME 117.76e-3 // info frame repeat after 117.76 ms +#define GRUNDIG_NOKIA_IR60_STOP_BIT 0 // has no stop bit +#define GRUNDIG_NOKIA_IR60_LSB 1 // MSB...LSB +#define GRUNDIG_NOKIA_IR60_FLAGS (IRMP_PARAM_FLAG_IS_MANCHESTER | IRMP_PARAM_FLAG_1ST_PULSE_IS_1) // flags + +#define GRUNDIG_FRAMES 2 // GRUNDIG sends each frame 1+1 times +#define GRUNDIG_AUTO_REPETITION_PAUSE_TIME 20.0e-3 // repetition after 20ms +#define GRUNDIG_ADDRESS_OFFSET 0 // no address +#define GRUNDIG_ADDRESS_LEN 0 // no address +#define GRUNDIG_COMMAND_OFFSET 1 // skip 1 start bit +#define GRUNDIG_COMMAND_LEN 9 // read 9 command bits +#define GRUNDIG_COMPLETE_DATA_LEN 10 // complete length: 1 start bit + 9 data bits + +#define NOKIA_FRAMES 3 // NOKIA sends each frame 1 + 1 + 1 times +#define NOKIA_AUTO_REPETITION_PAUSE_TIME 20.0e-3 // repetition after 20ms +#define NOKIA_ADDRESS_OFFSET 9 // skip 9 bits (1 start bit + 8 data bits) +#define NOKIA_ADDRESS_LEN 8 // 7 address bits +#define NOKIA_COMMAND_OFFSET 1 // skip 1 bit (1 start bit) +#define NOKIA_COMMAND_LEN 8 // read 8 command bits +#define NOKIA_COMPLETE_DATA_LEN 17 // complete length: 1 start bit + 8 address bits + 8 command bits + +#define IR60_TIMEOUT_TIME 5000.0e-6 // timeout grundig frame, switch to IR60 +#define IR60_ADDRESS_OFFSET 0 // skip 1 bits +#define IR60_ADDRESS_LEN 0 // read 0 address bits +#define IR60_COMMAND_OFFSET 0 // skip 1 bit (start bit after pre bit, always 1) +#define IR60_COMMAND_LEN 7 // read 6 command bits +#define IR60_COMPLETE_DATA_LEN 7 // complete length + +#define SIEMENS_OR_RUWIDO_START_BIT_PULSE_TIME 275.0e-6 // 275 usec pulse +#define SIEMENS_OR_RUWIDO_START_BIT_PAUSE_TIME 550.0e-6 // 550 usec pause +#define SIEMENS_OR_RUWIDO_BIT_PULSE_TIME 275.0e-6 // 275 usec short pulse +#define SIEMENS_OR_RUWIDO_BIT_PULSE_TIME_2 550.0e-6 // 550 usec long pulse +#define SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME 275.0e-6 // 275 usec short pause +#define SIEMENS_OR_RUWIDO_BIT_PAUSE_TIME_2 550.0e-6 // 550 usec long pause +#define SIEMENS_OR_RUWIDO_FRAME_REPEAT_PAUSE_TIME 45.0e-3 // frame repeat after 45ms +#define SIEMENS_OR_RUWIDO_STOP_BIT 0 // has no stop bit +#define SIEMENS_OR_RUWIDO_LSB 0 // MSB...LSB +#define SIEMENS_OR_RUWIDO_FLAGS (IRMP_PARAM_FLAG_IS_MANCHESTER | IRMP_PARAM_FLAG_1ST_PULSE_IS_1) // flags + +#define RUWIDO_ADDRESS_OFFSET 0 // skip 0 bits +#define RUWIDO_ADDRESS_LEN 9 // read 9 address bits +#define RUWIDO_COMMAND_OFFSET 9 // skip 9 bits +#define RUWIDO_COMMAND_LEN 8 // read 7 + 1 command bits, last bit is only check bit +#define RUWIDO_COMPLETE_DATA_LEN 17 // complete length + +#define SIEMENS_ADDRESS_OFFSET 0 // skip 0 bits +#define SIEMENS_ADDRESS_LEN 11 // read 11 bits +#define SIEMENS_COMMAND_OFFSET 11 // skip 11 bits +#define SIEMENS_COMMAND_LEN 11 // read 10 + 1 command bits, last bit is only check bit +#define SIEMENS_COMPLETE_DATA_LEN 22 // complete length + +#define FDC_START_BIT_PULSE_TIME 2085.0e-6 // 2085 usec pulse +#define FDC_START_BIT_PAUSE_TIME 966.0e-6 // 966 usec pause +#define FDC_PULSE_TIME 300.0e-6 // 300 usec pulse +#define FDC_1_PAUSE_TIME 715.0e-6 // 715 usec pause +#define FDC_0_PAUSE_TIME 220.0e-6 // 220 usec pause +#define FDC_FRAME_REPEAT_PAUSE_TIME 60.0e-3 // frame repeat after 60ms +#define FDC_ADDRESS_OFFSET 0 // skip 0 bits +#define FDC_ADDRESS_LEN 14 // read 14 address bits, but use only 6, shift 8 into command +#define FDC_COMMAND_OFFSET 20 // skip 20 bits +#define FDC_COMMAND_LEN 12 // read 12 bits +#define FDC_COMPLETE_DATA_LEN 40 // complete length +#define FDC_STOP_BIT 1 // has stop bit +#define FDC_LSB 1 // LSB...MSB +#define FDC_FLAGS 0 // flags + +#define RCCAR_START_BIT_PULSE_TIME 2000.0e-6 // 2000 usec pulse +#define RCCAR_START_BIT_PAUSE_TIME 2000.0e-6 // 2000 usec pause +#define RCCAR_PULSE_TIME 600.0e-6 // 360 usec pulse +#define RCCAR_1_PAUSE_TIME 450.0e-6 // 650 usec pause +#define RCCAR_0_PAUSE_TIME 900.0e-6 // 180 usec pause +#define RCCAR_FRAME_REPEAT_PAUSE_TIME 40.0e-3 // frame repeat after 40ms +#define RCCAR_ADDRESS_OFFSET 0 // skip 0 bits +#define RCCAR_ADDRESS_LEN 0 // read 0 address bits +#define RCCAR_COMMAND_OFFSET 0 // skip 0 bits +#define RCCAR_COMMAND_LEN 13 // read 13 bits +#define RCCAR_COMPLETE_DATA_LEN 13 // complete length +#define RCCAR_STOP_BIT 1 // has stop bit +#define RCCAR_LSB 1 // LSB...MSB +#define RCCAR_FLAGS 0 // flags + +#define JVC_START_BIT_PULSE_TIME 9000.0e-6 // 9000 usec pulse +#define JVC_START_BIT_PAUSE_TIME 4500.0e-6 // 4500 usec pause +#define JVC_PULSE_TIME 560.0e-6 // 560 usec pulse +#define JVC_1_PAUSE_TIME 1690.0e-6 // 1690 usec pause +#define JVC_0_PAUSE_TIME 560.0e-6 // 560 usec pause +#define JVC_FRAME_REPEAT_PAUSE_TIME 22.0e-3 // frame repeat after 22ms +#define JVC_ADDRESS_OFFSET 0 // skip 0 bits +#define JVC_ADDRESS_LEN 4 // read 4 address bits +#define JVC_COMMAND_OFFSET 4 // skip 4 bits +#define JVC_COMMAND_LEN 12 // read 12 bits +#define JVC_COMPLETE_DATA_LEN 16 // complete length +#define JVC_STOP_BIT 1 // has stop bit +#define JVC_LSB 1 // LSB...MSB +#define JVC_FLAGS 0 // flags + +#define NIKON_START_BIT_PULSE_TIME 2200.0e-6 // 2200 usec pulse +#define NIKON_START_BIT_PAUSE_TIME 27100.0e-6 // 27100 usec pause +#define NIKON_PULSE_TIME 500.0e-6 // 500 usec pulse +#define NIKON_1_PAUSE_TIME 3500.0e-6 // 3500 usec pause +#define NIKON_0_PAUSE_TIME 1500.0e-6 // 1500 usec pause +#define NIKON_FRAME_REPEAT_PAUSE_TIME 60.0e-3 // frame repeat after 60ms +#define NIKON_ADDRESS_OFFSET 0 // skip 0 bits +#define NIKON_ADDRESS_LEN 0 // read 0 address bits +#define NIKON_COMMAND_OFFSET 0 // skip 0 bits +#define NIKON_COMMAND_LEN 2 // read 2 bits +#define NIKON_COMPLETE_DATA_LEN 2 // complete length +#define NIKON_STOP_BIT 1 // has stop bit +#define NIKON_LSB 0 // LSB...MSB +#define NIKON_FLAGS 0 // flags + +#define KATHREIN_START_BIT_PULSE_TIME 210.0e-6 // 1340 usec pulse +#define KATHREIN_START_BIT_PAUSE_TIME 6218.0e-6 // 340 usec pause +#define KATHREIN_1_PULSE_TIME 210.0e-6 // 1340 usec pulse +#define KATHREIN_1_PAUSE_TIME 3000.0e-6 // 340 usec pause +#define KATHREIN_0_PULSE_TIME 210.0e-6 // 500 usec pulse +#define KATHREIN_0_PAUSE_TIME 1400.0e-6 // 1300 usec pause +#define KATHREIN_SYNC_BIT_PAUSE_LEN_TIME 4600.0e-6 // 4600 usec sync (on 6th and/or 8th bit) +#define KATHREIN_FRAMES 1 // Kathrein sends 1 frame +#define KATHREIN_AUTO_REPETITION_PAUSE_TIME 35.0e-3 // auto repetition after 35ms +#define KATHREIN_FRAME_REPEAT_PAUSE_TIME 35.0e-3 // frame repeat after 35ms +#define KATHREIN_ADDRESS_OFFSET 1 // skip 1 bits +#define KATHREIN_ADDRESS_LEN 4 // read 4 address bits +#define KATHREIN_COMMAND_OFFSET 5 // skip 5 bits +#define KATHREIN_COMMAND_LEN 7 // read 7 bits +#define KATHREIN_COMPLETE_DATA_LEN 13 // complete length +#define KATHREIN_STOP_BIT 1 // has stop bit +#define KATHREIN_LSB 0 // MSB +#define KATHREIN_FLAGS 0 // flags + +#define NETBOX_START_BIT_PULSE_TIME 2400.0e-6 // 2400 usec pulse +#define NETBOX_START_BIT_PAUSE_TIME 800.0e-6 // 800 usec pause +#define NETBOX_PULSE_TIME 800.0e-6 // 800 usec pulse +#define NETBOX_PAUSE_TIME 800.0e-6 // 800 usec pause +#define NETBOX_FRAMES 1 // Netbox sends 1 frame +#define NETBOX_AUTO_REPETITION_PAUSE_TIME 35.0e-3 // auto repetition after 35ms +#define NETBOX_FRAME_REPEAT_PAUSE_TIME 35.0e-3 // frame repeat after 35ms +#define NETBOX_ADDRESS_OFFSET 0 // skip 0 bits +#define NETBOX_ADDRESS_LEN 3 // read 3 address bits +#define NETBOX_COMMAND_OFFSET 3 // skip 3 bits +#define NETBOX_COMMAND_LEN 13 // read 13 bits +#define NETBOX_COMPLETE_DATA_LEN 16 // complete length +#define NETBOX_STOP_BIT 0 // has no stop bit +#define NETBOX_LSB 1 // LSB +#define NETBOX_FLAGS IRMP_PARAM_FLAG_IS_SERIAL // flags + +#define LEGO_START_BIT_PULSE_TIME 158.0e-6 // 158 usec pulse ( 6 x 1/38kHz) +#define LEGO_START_BIT_PAUSE_TIME 1026.0e-6 // 1026 usec pause (39 x 1/38kHz) +#define LEGO_PULSE_TIME 158.0e-6 // 158 usec pulse ( 6 x 1/38kHz) +#define LEGO_1_PAUSE_TIME 553.0e-6 // 553 usec pause (21 x 1/38kHz) +#define LEGO_0_PAUSE_TIME 263.0e-6 // 263 usec pause (10 x 1/38kHz) +#define LEGO_FRAME_REPEAT_PAUSE_TIME 40.0e-3 // frame repeat after 40ms +#define LEGO_ADDRESS_OFFSET 0 // skip 0 bits +#define LEGO_ADDRESS_LEN 0 // read 0 address bits +#define LEGO_COMMAND_OFFSET 0 // skip 0 bits +#define LEGO_COMMAND_LEN 16 // read 16 bits (12 command + 4 CRC) +#define LEGO_COMPLETE_DATA_LEN 16 // complete length +#define LEGO_STOP_BIT 1 // has stop bit +#define LEGO_LSB 0 // MSB...LSB +#define LEGO_FLAGS 0 // flags + +#define THOMSON_PULSE_TIME 550.0e-6 // 550 usec pulse +#define THOMSON_1_PAUSE_TIME 4500.0e-6 // 4500 usec pause +#define THOMSON_0_PAUSE_TIME 2000.0e-6 // 2000 usec pause +#define THOMSON_FRAMES 1 // THOMSON sends 1 frame +#define THOMSON_AUTO_REPETITION_PAUSE_TIME 65.0e-3 // repetition after 65ms +#define THOMSON_FRAME_REPEAT_PAUSE_TIME 65.0e-3 // frame repeat after 65ms +#define THOMSON_ADDRESS_OFFSET 0 // skip 0 bits +#define THOMSON_ADDRESS_LEN 4 // read 4 address bits +#define THOMSON_COMMAND_OFFSET 5 // skip 4 address bits + 1 toggle bit +#define THOMSON_COMMAND_LEN 7 // read 7 command bits +#define THOMSON_COMPLETE_DATA_LEN 12 // complete length +#define THOMSON_STOP_BIT 1 // has stop bit +#define THOMSON_LSB 0 // MSB...LSB +#define THOMSON_FLAGS 0 // flags + +#define GRUNDIG2_START_BIT_PULSE_TIME 550.0e-6 // 550 usec pulse +#define GRUNDIG2_START_BIT_PAUSE_TIME 2700.0e-6 // 2700 usec pause +#define GRUNDIG2_BIT_PULSE_TIME 550.0e-6 // 550 usec short pulse +#define GRUNDIG2_BIT_PAUSE_TIME 550.0e-6 // 550 usec short pause +#define GRUNDIG2_FRAME_REPEAT_PAUSE_TIME 100.0e-3 // frame repeat after 100ms +#define GRUNDIG2_STOP_BIT 0 // has no stop bit +#define GRUNDIG2_LSB 1 // MSB...LSB +#define GRUNDIG2_FLAGS (IRMP_PARAM_FLAG_IS_MANCHESTER | IRMP_PARAM_FLAG_1ST_PULSE_IS_1) // flags +#define GRUNDIG2_ADDRESS_OFFSET 0 // skip 0 bits +#define GRUNDIG2_ADDRESS_LEN 0 // read 0 bits +#define GRUNDIG2_COMMAND_OFFSET 0 // skip 0 bits +#define GRUNDIG2_COMMAND_LEN 7 // read 6 + 1 command bits, last bit is always 1 +#define GRUNDIG2_COMPLETE_DATA_LEN 7 // complete length + +#define AUTO_FRAME_REPETITION_TIME 80.0e-3 // SIRCS/SAMSUNG32/NUBERT: automatic repetition after 25-50ms +// KASEIKYO: automatic repetition after 75ms + +#define TRUE 1 +#define FALSE 0 + +#define IRMP_FLAG_REPETITION 0x01 + +typedef struct +{ + uint8_t protocol; // protocol, i.e. NEC_PROTOCOL + uint16_t address; // address + uint16_t command; // command + uint8_t flags; // flags, e.g. repetition +} IRMP_DATA; + +extern void irmp_init(void); +extern uint8_t irmp_get_data(IRMP_DATA *); +extern uint8_t irmp_is_busy(void); +extern uint8_t irmp_ISR(uint8_t); + +#if IRMP_PROTOCOL_NAMES == 1 +extern char *irmp_protocol_names[IRMP_N_PROTOCOLS + 1]; +#endif + +#if IRMP_USE_CALLBACK == 1 +extern void irmp_set_callback_ptr(void (*cb)(uint8_t)); +#endif // IRSND_USE_CALLBACK == 1 + +#endif /* _WC_IRMP_H_ */ diff --git a/libspark/irmpconfig.h b/libspark/irmpconfig.h index 10b34b7..9fa5162 100644 --- a/libspark/irmpconfig.h +++ b/libspark/irmpconfig.h @@ -1,191 +1,191 @@ -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * irmpconfig.h - * - * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de - * - * $Id: irmpconfig.h,v 1.80 2012/02/21 08:41:46 fm Exp $ - * - * ATMEGA88 @ 8 MHz - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ - -#ifndef _IRMPCONFIG_H_ -#define _IRMPCONFIG_H_ - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Change F_INTERRUPTS if you change the number of interrupts per second, - * Normally, F_INTERRUPTS should be in the range from 10000 to 15000, typical is 15000 - * A value above 15000 costs additional program space, absolute maximum value is 20000. - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#ifndef F_INTERRUPTS -#define F_INTERRUPTS 15000 // interrupts per second, min: 10000, max: 20000, typ: 15000 -#endif - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Change settings from 1 to 0 if you want to disable one or more decoders. - * This saves program space. - * - * 1 enable decoder - * 0 disable decoder - * - * The standard decoders are enabled per default. - * Less common protocols are disabled here, you need to enable them manually. - * - * If you want to use FDC or RCCAR simultaneous with RC5 protocol, additional program space is required. - * If you don't need RC5 when using FDC/RCCAR, you should disable RC5. - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ - -// typical protocols, disable here! Enable Remarks F_INTERRUPTS Program Space -#define IRMP_SUPPORT_SIRCS_PROTOCOL 1 // Sony SIRCS >= 10000 ~150 bytes -#define IRMP_SUPPORT_NEC_PROTOCOL 1 // NEC + APPLE >= 10000 ~300 bytes -#define IRMP_SUPPORT_SAMSUNG_PROTOCOL 1 // Samsung + Samsung32 >= 10000 ~300 bytes -#define IRMP_SUPPORT_MATSUSHITA_PROTOCOL 1 // Matsushita >= 10000 ~50 bytes -#define IRMP_SUPPORT_KASEIKYO_PROTOCOL 1 // Kaseikyo >= 10000 ~250 bytes -#define IRMP_SUPPORT_DENON_PROTOCOL 1 // DENON, Sharp >= 10000 ~250 bytes - -// more protocols, enable here! Enable Remarks F_INTERRUPTS Program Space -#define IRMP_SUPPORT_RC5_PROTOCOL 0 // RC5 >= 10000 ~250 bytes -#define IRMP_SUPPORT_RC6_PROTOCOL 0 // RC6 & RC6A >= 10000 ~250 bytes -#define IRMP_SUPPORT_JVC_PROTOCOL 0 // JVC >= 10000 ~150 bytes -#define IRMP_SUPPORT_NEC16_PROTOCOL 0 // NEC16 >= 10000 ~100 bytes -#define IRMP_SUPPORT_NEC42_PROTOCOL 0 // NEC42 >= 10000 ~300 bytes -#define IRMP_SUPPORT_IR60_PROTOCOL 0 // IR60 (SAB2008) >= 10000 ~300 bytes -#define IRMP_SUPPORT_GRUNDIG_PROTOCOL 0 // Grundig >= 10000 ~300 bytes -#define IRMP_SUPPORT_SIEMENS_PROTOCOL 0 // Siemens Gigaset >= 15000 ~550 bytes -#define IRMP_SUPPORT_NOKIA_PROTOCOL 0 // Nokia >= 10000 ~300 bytes - -// exotic protocols, enable here! Enable Remarks F_INTERRUPTS Program Space -#define IRMP_SUPPORT_GRUNDIG2_PROTOCOL 0 // Grundig TP400 >= 10000 ~300 bytes -#define IRMP_SUPPORT_KATHREIN_PROTOCOL 0 // Kathrein >= 10000 ~200 bytes -#define IRMP_SUPPORT_NUBERT_PROTOCOL 0 // NUBERT >= 10000 ~50 bytes -#define IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL 0 // Bang & Olufsen >= 10000 ~200 bytes -#define IRMP_SUPPORT_RECS80_PROTOCOL 0 // RECS80 (SAA3004) >= 15000 ~50 bytes -#define IRMP_SUPPORT_RECS80EXT_PROTOCOL 0 // RECS80EXT (SAA3008) >= 15000 ~50 bytes -#define IRMP_SUPPORT_THOMSON_PROTOCOL 0 // Thomson >= 10000 ~250 bytes -#define IRMP_SUPPORT_NIKON_PROTOCOL 0 // NIKON camera >= 10000 ~250 bytes -#define IRMP_SUPPORT_NETBOX_PROTOCOL 0 // Netbox keyboard >= 10000 ~400 bytes (PROTOTYPE!) -#define IRMP_SUPPORT_FDC_PROTOCOL 0 // FDC3402 keyboard >= 10000 (better 15000) ~150 bytes (~400 in combination with RC5) -#define IRMP_SUPPORT_RCCAR_PROTOCOL 0 // RC Car >= 10000 (better 15000) ~150 bytes (~500 in combination with RC5) -#define IRMP_SUPPORT_RUWIDO_PROTOCOL 0 // RUWIDO, T-Home >= 15000 ~550 bytes -#define IRMP_SUPPORT_LEGO_PROTOCOL 0 // LEGO Power RC >= 20000 ~150 bytes - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Change hardware pin here: - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#if defined (PIC_C18) // Microchip C18 Compiler -#include // main PIC18 h file -#define IRMP_PIN PORTBbits.RB4 // use RB4 as IR input on PIC -#define input(x) (x) - -#elif defined (PIC_CCS_COMPILER) // PIC CCS Compiler: -#define IRMP_PIN PIN_B4 // use PB4 as IR input on PIC - -#else // AVR: - -#ifndef ARDUINO -#define IRMP_PORT PORTB -#define IRMP_DDR DDRB -#define IRMP_PIN PINB -#define IRMP_BIT 6 // use PB6 as IR input on AVR -#else // ARDUINO -#define IRMP_PIN PIND // use digital pin 2 as IR input -#define IRMP_BIT 2 // on arduino -#endif // ARDUINO - -#define input(x) ((x) & (1 << IRMP_BIT)) -#endif - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Set IRMP_LOGGING to 1 if want to log data to UART with 9600Bd - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#ifndef IRMP_LOGGING -#define IRMP_LOGGING 0 // 1: log IR signal (scan), 0: do not (default) -#endif - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Use external logging routines - * If you enable external logging, you have also to enable IRMP_LOGGING above - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#ifndef IRMP_EXT_LOGGING -#define IRMP_EXT_LOGGING 0 // 1:log, 0: do not log ; -#endif - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Set IRMP_PROTOCOL_NAMES to 1 if want to access protocol names (for logging etc), costs ~300 bytes RAM! - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#define IRMP_PROTOCOL_NAMES 0 // 1: access protocol names, 0: do not (default), - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * Use Callbacks to indicate input signal - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#define IRMP_USE_CALLBACK 0 // flag: 0 = don't use callbacks, 1 = use callbacks, default is 0 - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * DO NOT CHANGE THE FOLLOWING LINES ! - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -#if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1 && F_INTERRUPTS < 15000 -# warning F_INTERRUPTS too low, SIEMENS protocol disabled (should be at least 15000) -# undef IRMP_SUPPORT_SIEMENS_PROTOCOL -# define IRMP_SUPPORT_SIEMENS_PROTOCOL 0 -#endif - -#if IRMP_SUPPORT_RUWIDO_PROTOCOL == 1 && F_INTERRUPTS < 15000 -# warning F_INTERRUPTS too low, RUWIDO protocol disabled (should be at least 15000) -# undef IRMP_SUPPORT_RUWIDO_PROTOCOL -# define IRMP_SUPPORT_RUWIDO_PROTOCOL 0 -#endif - -#if IRMP_SUPPORT_RECS80_PROTOCOL == 1 && F_INTERRUPTS < 15000 -# warning F_INTERRUPTS too low, RECS80 protocol disabled (should be at least 15000) -# undef IRMP_SUPPORT_RECS80_PROTOCOL -# define IRMP_SUPPORT_RECS80_PROTOCOL 0 -#endif - -#if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1 && F_INTERRUPTS < 15000 -# warning F_INTERRUPTS too low, RECS80EXT protocol disabled (should be at least 15000) -# undef IRMP_SUPPORT_RECS80EXT_PROTOCOL -# define IRMP_SUPPORT_RECS80EXT_PROTOCOL 0 -#endif - -#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 && F_INTERRUPTS < 20000 -# warning F_INTERRUPTS too low, LEGO protocol disabled (should be at least 20000) -# undef IRMP_SUPPORT_LEGO_PROTOCOL -# define IRMP_SUPPORT_LEGO_PROTOCOL 0 -#endif - -#if IRMP_SUPPORT_JVC_PROTOCOL == 1 && IRMP_SUPPORT_NEC_PROTOCOL == 0 -# warning JVC protocol needs also NEC protocol, NEC protocol enabled -# undef IRMP_SUPPORT_NEC_PROTOCOL -# define IRMP_SUPPORT_NEC_PROTOCOL 1 -#endif - -#if IRMP_SUPPORT_NEC16_PROTOCOL == 1 && IRMP_SUPPORT_NEC_PROTOCOL == 0 -# warning NEC16 protocol needs also NEC protocol, NEC protocol enabled -# undef IRMP_SUPPORT_NEC_PROTOCOL -# define IRMP_SUPPORT_NEC_PROTOCOL 1 -#endif - -#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 && IRMP_SUPPORT_NEC_PROTOCOL == 0 -# warning NEC42 protocol needs also NEC protocol, NEC protocol enabled -# undef IRMP_SUPPORT_NEC_PROTOCOL -# define IRMP_SUPPORT_NEC_PROTOCOL 1 -#endif - -#if F_INTERRUPTS > 20000 -#error F_INTERRUPTS too high (should be not greater than 20000) -#endif - -#endif /* _WC_IRMPCONFIG_H_ */ +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * irmpconfig.h + * + * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de + * + * $Id: irmpconfig.h,v 1.80 2012/02/21 08:41:46 fm Exp $ + * + * ATMEGA88 @ 8 MHz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ + +#ifndef _IRMPCONFIG_H_ +#define _IRMPCONFIG_H_ + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Change F_INTERRUPTS if you change the number of interrupts per second, + * Normally, F_INTERRUPTS should be in the range from 10000 to 15000, typical is 15000 + * A value above 15000 costs additional program space, absolute maximum value is 20000. + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#ifndef F_INTERRUPTS +#define F_INTERRUPTS 15000 // interrupts per second, min: 10000, max: 20000, typ: 15000 +#endif + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Change settings from 1 to 0 if you want to disable one or more decoders. + * This saves program space. + * + * 1 enable decoder + * 0 disable decoder + * + * The standard decoders are enabled per default. + * Less common protocols are disabled here, you need to enable them manually. + * + * If you want to use FDC or RCCAR simultaneous with RC5 protocol, additional program space is required. + * If you don't need RC5 when using FDC/RCCAR, you should disable RC5. + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ + +// typical protocols, disable here! Enable Remarks F_INTERRUPTS Program Space +#define IRMP_SUPPORT_SIRCS_PROTOCOL 1 // Sony SIRCS >= 10000 ~150 bytes +#define IRMP_SUPPORT_NEC_PROTOCOL 1 // NEC + APPLE >= 10000 ~300 bytes +#define IRMP_SUPPORT_SAMSUNG_PROTOCOL 1 // Samsung + Samsung32 >= 10000 ~300 bytes +#define IRMP_SUPPORT_MATSUSHITA_PROTOCOL 1 // Matsushita >= 10000 ~50 bytes +#define IRMP_SUPPORT_KASEIKYO_PROTOCOL 1 // Kaseikyo >= 10000 ~250 bytes +#define IRMP_SUPPORT_DENON_PROTOCOL 1 // DENON, Sharp >= 10000 ~250 bytes + +// more protocols, enable here! Enable Remarks F_INTERRUPTS Program Space +#define IRMP_SUPPORT_RC5_PROTOCOL 0 // RC5 >= 10000 ~250 bytes +#define IRMP_SUPPORT_RC6_PROTOCOL 0 // RC6 & RC6A >= 10000 ~250 bytes +#define IRMP_SUPPORT_JVC_PROTOCOL 0 // JVC >= 10000 ~150 bytes +#define IRMP_SUPPORT_NEC16_PROTOCOL 0 // NEC16 >= 10000 ~100 bytes +#define IRMP_SUPPORT_NEC42_PROTOCOL 0 // NEC42 >= 10000 ~300 bytes +#define IRMP_SUPPORT_IR60_PROTOCOL 0 // IR60 (SAB2008) >= 10000 ~300 bytes +#define IRMP_SUPPORT_GRUNDIG_PROTOCOL 0 // Grundig >= 10000 ~300 bytes +#define IRMP_SUPPORT_SIEMENS_PROTOCOL 0 // Siemens Gigaset >= 15000 ~550 bytes +#define IRMP_SUPPORT_NOKIA_PROTOCOL 0 // Nokia >= 10000 ~300 bytes + +// exotic protocols, enable here! Enable Remarks F_INTERRUPTS Program Space +#define IRMP_SUPPORT_GRUNDIG2_PROTOCOL 0 // Grundig TP400 >= 10000 ~300 bytes +#define IRMP_SUPPORT_KATHREIN_PROTOCOL 0 // Kathrein >= 10000 ~200 bytes +#define IRMP_SUPPORT_NUBERT_PROTOCOL 0 // NUBERT >= 10000 ~50 bytes +#define IRMP_SUPPORT_BANG_OLUFSEN_PROTOCOL 0 // Bang & Olufsen >= 10000 ~200 bytes +#define IRMP_SUPPORT_RECS80_PROTOCOL 0 // RECS80 (SAA3004) >= 15000 ~50 bytes +#define IRMP_SUPPORT_RECS80EXT_PROTOCOL 0 // RECS80EXT (SAA3008) >= 15000 ~50 bytes +#define IRMP_SUPPORT_THOMSON_PROTOCOL 0 // Thomson >= 10000 ~250 bytes +#define IRMP_SUPPORT_NIKON_PROTOCOL 0 // NIKON camera >= 10000 ~250 bytes +#define IRMP_SUPPORT_NETBOX_PROTOCOL 0 // Netbox keyboard >= 10000 ~400 bytes (PROTOTYPE!) +#define IRMP_SUPPORT_FDC_PROTOCOL 0 // FDC3402 keyboard >= 10000 (better 15000) ~150 bytes (~400 in combination with RC5) +#define IRMP_SUPPORT_RCCAR_PROTOCOL 0 // RC Car >= 10000 (better 15000) ~150 bytes (~500 in combination with RC5) +#define IRMP_SUPPORT_RUWIDO_PROTOCOL 0 // RUWIDO, T-Home >= 15000 ~550 bytes +#define IRMP_SUPPORT_LEGO_PROTOCOL 0 // LEGO Power RC >= 20000 ~150 bytes + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Change hardware pin here: + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#if defined (PIC_C18) // Microchip C18 Compiler +#include // main PIC18 h file +#define IRMP_PIN PORTBbits.RB4 // use RB4 as IR input on PIC +#define input(x) (x) + +#elif defined (PIC_CCS_COMPILER) // PIC CCS Compiler: +#define IRMP_PIN PIN_B4 // use PB4 as IR input on PIC + +#else // AVR: + +#ifndef ARDUINO +#define IRMP_PORT PORTB +#define IRMP_DDR DDRB +#define IRMP_PIN PINB +#define IRMP_BIT 6 // use PB6 as IR input on AVR +#else // ARDUINO +#define IRMP_PIN PIND // use digital pin 2 as IR input +#define IRMP_BIT 2 // on arduino +#endif // ARDUINO + +#define input(x) ((x) & (1 << IRMP_BIT)) +#endif + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Set IRMP_LOGGING to 1 if want to log data to UART with 9600Bd + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#ifndef IRMP_LOGGING +#define IRMP_LOGGING 0 // 1: log IR signal (scan), 0: do not (default) +#endif + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Use external logging routines + * If you enable external logging, you have also to enable IRMP_LOGGING above + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#ifndef IRMP_EXT_LOGGING +#define IRMP_EXT_LOGGING 0 // 1:log, 0: do not log ; +#endif + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Set IRMP_PROTOCOL_NAMES to 1 if want to access protocol names (for logging etc), costs ~300 bytes RAM! + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#define IRMP_PROTOCOL_NAMES 0 // 1: access protocol names, 0: do not (default), + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Use Callbacks to indicate input signal + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#define IRMP_USE_CALLBACK 0 // flag: 0 = don't use callbacks, 1 = use callbacks, default is 0 + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * DO NOT CHANGE THE FOLLOWING LINES ! + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#if IRMP_SUPPORT_SIEMENS_PROTOCOL == 1 && F_INTERRUPTS < 15000 +# warning F_INTERRUPTS too low, SIEMENS protocol disabled (should be at least 15000) +# undef IRMP_SUPPORT_SIEMENS_PROTOCOL +# define IRMP_SUPPORT_SIEMENS_PROTOCOL 0 +#endif + +#if IRMP_SUPPORT_RUWIDO_PROTOCOL == 1 && F_INTERRUPTS < 15000 +# warning F_INTERRUPTS too low, RUWIDO protocol disabled (should be at least 15000) +# undef IRMP_SUPPORT_RUWIDO_PROTOCOL +# define IRMP_SUPPORT_RUWIDO_PROTOCOL 0 +#endif + +#if IRMP_SUPPORT_RECS80_PROTOCOL == 1 && F_INTERRUPTS < 15000 +# warning F_INTERRUPTS too low, RECS80 protocol disabled (should be at least 15000) +# undef IRMP_SUPPORT_RECS80_PROTOCOL +# define IRMP_SUPPORT_RECS80_PROTOCOL 0 +#endif + +#if IRMP_SUPPORT_RECS80EXT_PROTOCOL == 1 && F_INTERRUPTS < 15000 +# warning F_INTERRUPTS too low, RECS80EXT protocol disabled (should be at least 15000) +# undef IRMP_SUPPORT_RECS80EXT_PROTOCOL +# define IRMP_SUPPORT_RECS80EXT_PROTOCOL 0 +#endif + +#if IRMP_SUPPORT_LEGO_PROTOCOL == 1 && F_INTERRUPTS < 20000 +# warning F_INTERRUPTS too low, LEGO protocol disabled (should be at least 20000) +# undef IRMP_SUPPORT_LEGO_PROTOCOL +# define IRMP_SUPPORT_LEGO_PROTOCOL 0 +#endif + +#if IRMP_SUPPORT_JVC_PROTOCOL == 1 && IRMP_SUPPORT_NEC_PROTOCOL == 0 +# warning JVC protocol needs also NEC protocol, NEC protocol enabled +# undef IRMP_SUPPORT_NEC_PROTOCOL +# define IRMP_SUPPORT_NEC_PROTOCOL 1 +#endif + +#if IRMP_SUPPORT_NEC16_PROTOCOL == 1 && IRMP_SUPPORT_NEC_PROTOCOL == 0 +# warning NEC16 protocol needs also NEC protocol, NEC protocol enabled +# undef IRMP_SUPPORT_NEC_PROTOCOL +# define IRMP_SUPPORT_NEC_PROTOCOL 1 +#endif + +#if IRMP_SUPPORT_NEC42_PROTOCOL == 1 && IRMP_SUPPORT_NEC_PROTOCOL == 0 +# warning NEC42 protocol needs also NEC protocol, NEC protocol enabled +# undef IRMP_SUPPORT_NEC_PROTOCOL +# define IRMP_SUPPORT_NEC_PROTOCOL 1 +#endif + +#if F_INTERRUPTS > 20000 +#error F_INTERRUPTS too high (should be not greater than 20000) +#endif + +#endif /* _WC_IRMPCONFIG_H_ */ diff --git a/libspark/lirmp_input.cpp b/libspark/lirmp_input.cpp index b0b917d..eb5ab5d 100644 --- a/libspark/lirmp_input.cpp +++ b/libspark/lirmp_input.cpp @@ -51,23 +51,25 @@ static uint8_t IRMP_PIN; #define hal_info(args...) _hal_info(HAL_DEBUG_INIT, NULL, args) /* same defines as in neutrino's rcinput.h */ -#define KEY_TTTV KEY_FN_1 -#define KEY_TTZOOM KEY_FN_2 -#define KEY_REVEAL KEY_FN_D +#define KEY_TTTV KEY_FN_1 +#define KEY_TTZOOM KEY_FN_2 +#define KEY_REVEAL KEY_FN_D /* only defined in newer kernels / headers... */ #ifndef KEY_ZOOMIN -#define KEY_ZOOMIN KEY_FN_E +#define KEY_ZOOMIN KEY_FN_E #endif #ifndef KEY_ZOOMOUT -#define KEY_ZOOMOUT KEY_FN_F +#define KEY_ZOOMOUT KEY_FN_F #endif -typedef struct { - uint16_t ir; /* IR command */ - int code; /* input key code */ +typedef struct +{ + uint16_t ir; /* IR command */ + int code; /* input key code */ } key_map_t; -static const key_map_t key_map[] = { +static const key_map_t key_map[] = +{ { 0x13, KEY_0 }, { 0x1a, KEY_1 }, { 0x1f, KEY_2 }, @@ -101,15 +103,15 @@ static const key_map_t key_map[] = { { 0x4e, KEY_GREEN }, { 0x11, KEY_YELLOW }, { 0x4a, KEY_BLUE }, - { 0x4c, KEY_TV }, /* TV/Radio */ - { 0x5c, KEY_VIDEO }, /* FIND */ - { 0x19, KEY_AUDIO }, /* FOLDER */ -/* KEY_AUX, - KEY_TEXT, - KEY_TTTV, - KEY_TTZOOM, - KEY_REVEAL, -*/ + { 0x4c, KEY_TV }, /* TV/Radio */ + { 0x5c, KEY_VIDEO }, /* FIND */ + { 0x19, KEY_AUDIO }, /* FOLDER */ + /* KEY_AUX, + KEY_TEXT, + KEY_TTTV, + KEY_TTZOOM, + KEY_REVEAL, + */ { 0x01, KEY_REWIND }, { 0x53, KEY_FORWARD }, { 0x22, KEY_STOP }, @@ -121,7 +123,8 @@ static const key_map_t key_map[] = { { 0x10, KEY_RECORD } }; -static const int key_list[] = { +static const int key_list[] = +{ KEY_0, KEY_1, KEY_2, @@ -191,9 +194,9 @@ static void *input_thread(void *) int i = 0; int last_pulse = 1; int last_code = -1; - uint32_t lircdata; /* lirc_t to be correct... */ - unsigned int count = 0; /* how many timeouts? */ - unsigned int nodec = 0; /* how many timeouts since last decoded? */ + uint32_t lircdata; /* lirc_t to be correct... */ + unsigned int count = 0; /* how many timeouts? */ + unsigned int nodec = 0; /* how many timeouts since last decoded? */ int aotom_fd = -1; IRMP_DATA d; @@ -201,10 +204,12 @@ static void *input_thread(void *) /* modprobe does not complain if the module is already loaded... */ system("/sbin/modprobe uinput"); - do { + do + { usleep(100000); /* mdev needs some time to create the device? */ - uinput = open("/dev/uinput", O_WRONLY|O_NDELAY); - } while (uinput < 0 && ++count < 100); + uinput = open("/dev/uinput", O_WRONLY | O_NDELAY); + } + while (uinput < 0 && ++count < 100); if (uinput < 0) { @@ -253,7 +258,7 @@ static void *input_thread(void *) char newdev[20]; while (getline(&line, &n, f) != -1) { - switch(line[0]) + switch (line[0]) { case 'I': if (strncmp(line, DEVLINE, strlen(DEVLINE)) == 0) @@ -295,10 +300,10 @@ static void *input_thread(void *) } IRMP_PIN = 0xFF; -/* 50 ms. This should be longer than the longest light pulse */ -#define POLL_MS (100 * 1000) -#define LIRC_PULSE 0x01000000 -#define LIRC_PULSE_MASK 0x00FFFFFF + /* 50 ms. This should be longer than the longest light pulse */ +#define POLL_MS (100 * 1000) +#define LIRC_PULSE 0x01000000 +#define LIRC_PULSE_MASK 0x00FFFFFF hal_info("LIRC/IRMP input converter going into main loop...\n"); aotom_fd = open("/dev/vfd", O_RDONLY); @@ -317,11 +322,14 @@ static void *input_thread(void *) tv.tv_usec = POLL_MS; /* any singal can interrupt select. we rely on the linux-only feature * that the timeout is automatcally recalculated in this case! */ - do { + do + { ret = select(lircfd + 1, &fds, NULL, NULL, &tv); - } while (ret == -1 && errno == EINTR); + } + while (ret == -1 && errno == EINTR); - if (ret == -1) { + if (ret == -1) + { /* errno != EINTR... */ hal_info("%s: lirmp: lircfd select: %m\n", __func__); break; @@ -331,13 +339,13 @@ static void *input_thread(void *) { count++; nodec++; - lircdata = POLL_MS; /* timeout */ - pulse = !last_pulse; /* lirc sends data on signal change */ + lircdata = POLL_MS; /* timeout */ + pulse = !last_pulse; /* lirc sends data on signal change */ if (last_code != -1 && nodec > 1) { // fprintf(stderr, "timeout!\n"); u.code = last_code; - u.value = 0; /* release */ + u.value = 0; /* release */ write(uinput, &u, sizeof(u)); last_code = -1; } @@ -349,9 +357,9 @@ static void *input_thread(void *) perror("read"); break; } - pulse = (lircdata & LIRC_PULSE); /* we got light... */ + pulse = (lircdata & LIRC_PULSE); /* we got light... */ last_pulse = pulse; - lircdata &= LIRC_PULSE_MASK; /* how long the pulse was in microseconds */ + lircdata &= LIRC_PULSE_MASK; /* how long the pulse was in microseconds */ } if (ret && count) @@ -370,19 +378,20 @@ static void *input_thread(void *) else IRMP_PIN = 0xff; - do { - (void) irmp_ISR (IRMP_PIN); - if (irmp_get_data (&d)) + do + { + (void) irmp_ISR(IRMP_PIN); + if (irmp_get_data(&d)) { nodec = 0; hal_debug("irmp_get_data proto: %2d addr: 0x%04x cmd: 0x%04x fl: %d\n", - d.protocol, d.address, d.command, d.flags); + d.protocol, d.address, d.command, d.flags); /* todo: do we need to complete the loop if we already * detected the singal in this pulse? */ if (d.protocol == IRMP_NEC_PROTOCOL && d.address == 0xba45) { - for (i = 0; i < (int)(sizeof(key_map)/sizeof(key_map_t)); i++) + for (i = 0; i < (int)(sizeof(key_map) / sizeof(key_map_t)); i++) { if (key_map[i].ir == d.command) { @@ -397,7 +406,8 @@ static void *input_thread(void *) //hal_debug("uinput write: value: %d code: %d\n", u.value, u.code); last_code = u.code; write(uinput, &u, sizeof(u)); - if (aotom_fd > -1) { + if (aotom_fd > -1) + { struct aotom_ioctl_data vfd_data; vfd_data.u.led.led_nr = 1; vfd_data.u.led.on = 10; @@ -408,15 +418,16 @@ static void *input_thread(void *) } } } - } while (lircdata-- > 0); + } + while (lircdata-- > 0); } /* clean up */ - close (lircfd); + close(lircfd); if (aotom_fd > -1) close(aotom_fd); - out: +out: ioctl(uinput, UI_DEV_DESTROY); return NULL; } diff --git a/libspark/playback_libeplayer3.cpp b/libspark/playback_libeplayer3.cpp index 9451381..54a30fd 100644 --- a/libspark/playback_libeplayer3.cpp +++ b/libspark/playback_libeplayer3.cpp @@ -54,7 +54,7 @@ void cPlayback::Close(void) bool cPlayback::Start(std::string filename, std::string headers) { - return Start((char*) filename.c_str(),0,0,0,0,0, headers); + return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers); } bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, int, std::string headers) @@ -77,40 +77,53 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in if ((file.find(":31339/id=") != std::string::npos) || (file.find(":10000") != std::string::npos) || (file.find(":8001/") != std::string::npos)) // for LocalTV and Entertain-TV streaming no_probe = true; - if (file.substr(0, 7) == "file://") { - if (file.substr(file.length() - 3) == ".ts") { + if (file.substr(0, 7) == "file://") + { + if (file.substr(file.length() - 3) == ".ts") + { fn_ts = file.substr(7); fn_xml = file.substr(7, file.length() - 9); fn_xml += "xml"; no_probe = true; } - } else + } + else isHTTP = true; - if (player->Open(file.c_str(), no_probe, headers)) { - if (pm == PLAYMODE_TS) { + if (player->Open(file.c_str(), no_probe, headers)) + { + if (pm == PLAYMODE_TS) + { struct stat64 s; if (!stat64(file.c_str(), &s)) last_size = s.st_size; ret = true; videoDecoder->Stop(false); audioDecoder->Stop(); - } else { + } + else + { std::vector keys, values; int selected_program = 0; - if (vpid || apid) { + if (vpid || apid) + { ; - } else if (GetPrograms(keys, values) && (keys.size() > 1) && ProgramSelectionCallback) { + } + else if (GetPrograms(keys, values) && (keys.size() > 1) && ProgramSelectionCallback) + { const char *key = ProgramSelectionCallback(ProgramSelectionCallbackData, keys, values); - if (!key) { + if (!key) + { player->Close(); return false; } selected_program = atoi(key); - } else if (keys.size() > 0) + } + else if (keys.size() > 0) selected_program = atoi(keys[0].c_str()); - if (!keys.size() || !player->SelectProgram(selected_program)) { + if (!keys.size() || !player->SelectProgram(selected_program)) + { if (apid) SetAPid(apid); if (vpid) @@ -181,27 +194,35 @@ bool cPlayback::SetSpeed(int speed) nPlaybackSpeed = speed; - if (speed > 1) { + if (speed > 1) + { /* direction switch ? */ if (player->isBackWard) player->FastBackward(0); res = player->FastForward(speed); - } else if (speed < 0) { + } + else if (speed < 0) + { /* direction switch ? */ if (player->isForwarding) player->Continue(); res = player->FastBackward(speed); - } else if (speed == 0) { + } + else if (speed == 0) + { /* konfetti: hmmm accessing the member isn't very proper */ if ((player->isForwarding) || (!player->isBackWard)) /* res = */ player->Pause(); else /* res = */ player->FastForward(0); - } else /* speed == 1 */ { + } + else /* speed == 1 */ + { res = player->Continue(); } - if (init_jump > -1) { + if (init_jump > -1) + { SetPosition(init_jump); init_jump = -1; } @@ -252,7 +273,8 @@ bool cPlayback::GetPosition(int &position, int &duration) if (!playing) return false; - if (!player->isPlaying) { + if (!player->isPlaying) + { hal_info("%s !!!!EOF!!!! < -1\n", __func__); position = duration + 1000; // duration = 0; @@ -263,11 +285,14 @@ bool cPlayback::GetPosition(int &position, int &duration) int64_t vpts = 0; player->GetPts(vpts); - if(vpts <= 0) { + if (vpts <= 0) + { //printf("ERROR: vpts==0"); - } else { + } + else + { /* len is in nanoseconds. we have 90 000 pts per second. */ - position = vpts/90; + position = vpts / 90; } if (got_duration) @@ -277,7 +302,7 @@ bool cPlayback::GetPosition(int &position, int &duration) player->GetDuration(length); - if(length <= 0) + if (length <= 0) duration = position + AV_TIME_BASE / 1000; else duration = length * 1000 / AV_TIME_BASE; @@ -308,9 +333,11 @@ void cPlayback::FindAllPids(int *pids, unsigned int *ac3flags, unsigned int *num hal_info("%s\n", __func__); unsigned int i = 0; - if (IsPlaying()) { + if (IsPlaying()) + { std::vector tracks = player->manager.getAudioTracks(); - for (std::vector::iterator it = tracks.begin(); it != tracks.end() && i < *numpids; ++it) { + for (std::vector::iterator it = tracks.begin(); it != tracks.end() && i < *numpids; ++it) + { pids[i] = it->pid; ac3flags[i] = it->ac3flags; language[i] = it->title; @@ -326,7 +353,8 @@ void cPlayback::FindAllSubtitlePids(int *pids, unsigned int *numpids, std::strin unsigned int i = 0; std::vector tracks = player->manager.getSubtitleTracks(); - for (std::vector::iterator it = tracks.begin(); it != tracks.end() && i < *numpids; ++it) { + for (std::vector::iterator it = tracks.begin(); it != tracks.end() && i < *numpids; ++it) + { pids[i] = it->pid; language[i] = it->title; i++; @@ -341,7 +369,8 @@ void cPlayback::FindAllTeletextsubtitlePids(int *pids, unsigned int *numpids, st unsigned int i = 0; std::vector tracks = player->manager.getTeletextTracks(); - for (std::vector::iterator it = tracks.begin(); it != tracks.end() && i < *numpids; ++it) { + for (std::vector::iterator it = tracks.begin(); it != tracks.end() && i < *numpids; ++it) + { if (it->type != 2 && it->type != 5) // return subtitles only continue; pids[i] = it->pid; @@ -357,7 +386,8 @@ void cPlayback::FindAllTeletextsubtitlePids(int *pids, unsigned int *numpids, st int cPlayback::GetFirstTeletextPid(void) { std::vector tracks = player->manager.getTeletextTracks(); - for (std::vector::iterator it = tracks.begin(); it != tracks.end(); ++it) { + for (std::vector::iterator it = tracks.begin(); it != tracks.end(); ++it) + { if (it->type == 1) return it->pid; } @@ -413,17 +443,20 @@ cPlayback::~cPlayback() delete player; } -void cPlayback::RequestAbort() { +void cPlayback::RequestAbort() +{ player->RequestAbort(); while (player->isPlaying) usleep(100000); } -bool cPlayback::IsPlaying() { +bool cPlayback::IsPlaying() +{ return player->isPlaying; } -uint64_t cPlayback::GetReadCount() { +uint64_t cPlayback::GetReadCount() +{ return player->readCount; } diff --git a/libspark/playback_libeplayer3.h b/libspark/playback_libeplayer3.h index f8048fd..dc1d141 100644 --- a/libspark/playback_libeplayer3.h +++ b/libspark/playback_libeplayer3.h @@ -4,7 +4,8 @@ #include #include -typedef enum { +typedef enum +{ PLAYMODE_TS = 0, PLAYMODE_FILE } playmode_t; @@ -14,7 +15,7 @@ struct AVFormatContext; class cPlayback { - friend class CStreamInfo2; + friend class CStreamInfo2; private: bool enabled; @@ -82,10 +83,10 @@ class cPlayback bool GetOffset(off64_t &offset); bool IsPlaying(void) const; bool IsEnabled(void) const; - void * GetHandle(void); - void * GetDmHandle(void); + void *GetHandle(void); + void *GetDmHandle(void); int GetCurrPlaybackSpeed(void) const; - void PlaybackNotify (int Event, void *pData, void *pTag); + void PlaybackNotify(int Event, void *pData, void *pTag); void DMNotify(int Event, void *pTsBuf, void *Tag); #endif }; diff --git a/libspark/record.cpp b/libspark/record.cpp index 4232a3e..3dcb96b 100644 --- a/libspark/record.cpp +++ b/libspark/record.cpp @@ -134,17 +134,21 @@ bool cRecord::ChangePids(unsigned short /*vpid*/, unsigned short *apids, int num bool found; unsigned short pid; hal_info("%s\n", __func__); - if (!dmx) { + if (!dmx) + { hal_info("%s: DMX = NULL\n", __func__); return false; } pids = dmx->pesfds; /* the first PID is the video pid, so start with the second PID... */ - for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) { + for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) + { found = false; pid = (*i).pid; - for (j = 0; j < numapids; j++) { - if (pid == apids[j]) { + for (j = 0; j < numapids; j++) + { + if (pid == apids[j]) + { found = true; break; } @@ -152,10 +156,13 @@ bool cRecord::ChangePids(unsigned short /*vpid*/, unsigned short *apids, int num if (!found) dmx->removePid(pid); } - for (j = 0; j < numapids; j++) { + for (j = 0; j < numapids; j++) + { found = false; - for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) { - if ((*i).pid == apids[j]) { + for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) + { + if ((*i).pid == apids[j]) + { found = true; break; } @@ -170,12 +177,14 @@ bool cRecord::AddPid(unsigned short pid) { std::vector pids; hal_info("%s: \n", __func__); - if (!dmx) { + if (!dmx) + { hal_info("%s: DMX = NULL\n", __func__); return false; } pids = dmx->pesfds; - for (std::vector::const_iterator i = pids.begin(); i != pids.end(); ++i) { + for (std::vector::const_iterator i = pids.begin(); i != pids.end(); ++i) + { if ((*i).pid == pid) return true; /* or is it an error to try to add the same PID twice? */ } @@ -187,14 +196,16 @@ void cRecord::WriterThread() char threadname[17]; strncpy(threadname, "WriterThread", sizeof(threadname)); threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); + prctl(PR_SET_NAME, (unsigned long)&threadname); unsigned int chunk = 0; - while (!sem_wait(&sem)) { + while (!sem_wait(&sem)) + { if (!io_len[chunk]) // empty, assume end of recording return; unsigned char *p_buf = io_buf[chunk]; size_t p_len = io_len[chunk]; - while (p_len) { + while (p_len) + { ssize_t written = write(file_fd, p_buf, p_len); if (written < 0) break; @@ -214,7 +225,7 @@ void cRecord::RecordThread() char threadname[17]; strncpy(threadname, "RecordThread", sizeof(threadname)); threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); + prctl(PR_SET_NAME, (unsigned long)&threadname); int readsize = bufsize / 16; int buf_pos = 0; int count = 0; @@ -235,7 +246,7 @@ void cRecord::RecordThread() } int val = fcntl(file_fd, F_GETFL); - if (fcntl(file_fd, F_SETFL, val|O_APPEND)) + if (fcntl(file_fd, F_SETFL, val | O_APPEND)) hal_info("%s: O_APPEND? (%m)\n", __func__); memset(&a, 0, sizeof(a)); @@ -250,7 +261,8 @@ void cRecord::RecordThread() { if (buf_pos < bufsize) { - if (overflow_count) { + if (overflow_count) + { hal_info("%s: Overflow cleared after %d iterations\n", __func__, overflow_count); overflow_count = 0; } @@ -259,7 +271,7 @@ void cRecord::RecordThread() toread = readsize; ssize_t s = dmx->Read(buf + buf_pos, toread, 50); hal_debug("%s: buf_pos %6d s %6d / %6d\n", __func__, - buf_pos, (int)s, bufsize - buf_pos); + buf_pos, (int)s, bufsize - buf_pos); if (s < 0) { if (errno != EAGAIN && (errno != EOVERFLOW || !overflow)) @@ -362,9 +374,9 @@ void cRecord::RecordThread() eventServer.registerEvent2(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, "/tmp/neutrino.sock"); stream2file_status2_t s; s.status = exit_flag; - strncpy(s.filename,basename(myfilename),512); + strncpy(s.filename, basename(myfilename), 512); s.filename[511] = '\0'; - strncpy(s.dir,dirname(myfilename),100); + strncpy(s.dir, dirname(myfilename), 100); s.dir[99] = '\0'; eventServer.sendEvent(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, &s, sizeof(s)); printf("[stream2file]: pthreads exit code: %i, dir: '%s', filename: '%s' myfilename: '%s'\n", exit_flag, s.dir, s.filename, myfilename); diff --git a/libspark/record_lib.h b/libspark/record_lib.h index 9e554cd..8cde3f6 100644 --- a/libspark/record_lib.h +++ b/libspark/record_lib.h @@ -9,13 +9,14 @@ #define REC_STATUS_OVERFLOW 2 #define REC_STATUS_STOPPED 4 -typedef enum { +typedef enum +{ RECORD_RUNNING, RECORD_STOPPED, - RECORD_FAILED_READ, /* failed to read from DMX */ - RECORD_FAILED_OVERFLOW, /* cannot write fast enough */ - RECORD_FAILED_FILE, /* cannot write to file */ - RECORD_FAILED_MEMORY /* out of memory */ + RECORD_FAILED_READ, /* failed to read from DMX */ + RECORD_FAILED_OVERFLOW, /* cannot write fast enough */ + RECORD_FAILED_FILE, /* cannot write to file */ + RECORD_FAILED_MEMORY /* out of memory */ } record_state_t; class cRecord @@ -38,8 +39,12 @@ class cRecord unsigned char *io_buf[RECORD_WRITER_CHUNKS]; size_t io_len[RECORD_WRITER_CHUNKS]; public: - cRecord(int num = 0, int bs_dmx = 2048 * 1024, int bs = 4096 * 1024); - void setFailureCallback(void (*f)(void *), void *d) { failureCallback = f; failureData = d; } + cRecord(int num = 0, int bs_dmx = 2048 * 1024, int bs = 4096 * 1024); + void setFailureCallback(void (*f)(void *), void *d) + { + failureCallback = f; + failureData = d; + } ~cRecord(); bool Open(); diff --git a/libspark/video.cpp b/libspark/video.cpp index 599fec6..1bebec7 100644 --- a/libspark/video.cpp +++ b/libspark/video.cpp @@ -53,61 +53,69 @@ extern "C" #define hal_debug_c(args...) _hal_debug(HAL_DEBUG_VIDEO, NULL, args) #define hal_info_c(args...) _hal_info(HAL_DEBUG_VIDEO, NULL, args) -#define fop(cmd, args...) ({ \ - int _r; \ - if (fd >= 0) { \ - if ((_r = ::cmd(fd, args)) < 0) \ - hal_info(#cmd"(fd, "#args")\n"); \ - else \ - hal_debug(#cmd"(fd, "#args")\n");\ - } \ - else { _r = fd; } \ - _r; \ -}) +#define fop(cmd, args...) ({ \ + int _r; \ + if (fd >= 0) { \ + if ((_r = ::cmd(fd, args)) < 0) \ + hal_info(#cmd"(fd, "#args")\n"); \ + else \ + hal_debug(#cmd"(fd, "#args")\n");\ + } \ + else { _r = fd; } \ + _r; \ + }) enum -{ ENCODER, +{ + ENCODER, AUX }; -cVideo * videoDecoder = NULL; -cVideo * pipDecoder = NULL; +cVideo *videoDecoder = NULL; +cVideo *pipDecoder = NULL; int system_rev = 0; static bool hdmi_enabled = true; static bool stillpicture = false; -static const char *VDEV[] = { +static const char *VDEV[] = +{ "/dev/dvb/adapter0/video0", "/dev/dvb/adapter0/video1" }; -static const char *VMPEG_aspect[] = { +static const char *VMPEG_aspect[] = +{ "/proc/stb/vmpeg/0/aspect", "/proc/stb/vmpeg/1/aspect" }; -static const char *VMPEG_xres[] = { +static const char *VMPEG_xres[] = +{ "/proc/stb/vmpeg/0/xres", "/proc/stb/vmpeg/1/xres" }; -static const char *VMPEG_yres[] = { +static const char *VMPEG_yres[] = +{ "/proc/stb/vmpeg/0/yres", "/proc/stb/vmpeg/1/yres" }; -static const char *VMPEG_dst_all[] = { +static const char *VMPEG_dst_all[] = +{ "/proc/stb/vmpeg/0/dst_all", "/proc/stb/vmpeg/1/dst_all" }; -static const char *VMPEG_framerate[] = { +static const char *VMPEG_framerate[] = +{ "/proc/stb/vmpeg/0/framerate", "/proc/stb/vmpeg/1/framerate" }; -static const char *VMPEG_visible[] = { +static const char *VMPEG_visible[] = +{ "/proc/stb/vmpeg/0/visible", "/proc/stb/vmpeg/1/visible", "/proc/stb/vmpeg/2/visible", @@ -115,21 +123,22 @@ static const char *VMPEG_visible[] = { }; -static const char *vid_modes[] = { - "pal", // VIDEO_STD_NTSC - "pal", // VIDEO_STD_SECAM - "pal", // VIDEO_STD_PAL - "480p", // VIDEO_STD_480P - "576p50", // VIDEO_STD_576P - "720p60", // VIDEO_STD_720P60 - "1080i60", // VIDEO_STD_1080I60 - "720p50", // VIDEO_STD_720P50 - "1080i50", // VIDEO_STD_1080I50 - "1080p30", // VIDEO_STD_1080P30 - "1080p24", // VIDEO_STD_1080P24 - "1080p25", // VIDEO_STD_1080P25 - "720p50", // VIDEO_STD_AUTO -> not implemented - "1080p50", // VIDEO_STD_1080P50 -> SPARK only +static const char *vid_modes[] = +{ + "pal", // VIDEO_STD_NTSC + "pal", // VIDEO_STD_SECAM + "pal", // VIDEO_STD_PAL + "480p", // VIDEO_STD_480P + "576p50", // VIDEO_STD_576P + "720p60", // VIDEO_STD_720P60 + "1080i60", // VIDEO_STD_1080I60 + "720p50", // VIDEO_STD_720P50 + "1080i50", // VIDEO_STD_1080I50 + "1080p30", // VIDEO_STD_1080P30 + "1080p24", // VIDEO_STD_1080P24 + "1080p25", // VIDEO_STD_1080P25 + "720p50", // VIDEO_STD_AUTO -> not implemented + "1080p50", // VIDEO_STD_1080P50 -> SPARK only NULL }; @@ -177,23 +186,26 @@ out: } -void init_parameters(AVFrame* in_frame, AVCodecContext *codec_context) +void init_parameters(AVFrame *in_frame, AVCodecContext *codec_context) { /* put sample parameters */ codec_context->bit_rate = 400000; /* resolution must be a multiple of two */ - codec_context->width = (in_frame->width/2)*2; - codec_context->height = (in_frame->height/2)*2; + codec_context->width = (in_frame->width / 2) * 2; + codec_context->height = (in_frame->height / 2) * 2; /* frames per second */ - codec_context->time_base = (AVRational ) { 1, 60 }; + codec_context->time_base = (AVRational) + { + 1, 60 + }; codec_context->gop_size = 10; /* emit one intra frame every ten frames */ codec_context->max_b_frames = 1; codec_context->pix_fmt = AV_PIX_FMT_YUV420P; } -void write_frame(AVFrame* in_frame, FILE* fp) +void write_frame(AVFrame *in_frame, FILE *fp) { - if(in_frame == NULL || fp == NULL) + if (in_frame == NULL || fp == NULL) return; AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO); if (codec) @@ -202,24 +214,29 @@ void write_frame(AVFrame* in_frame, FILE* fp) if (codec_context) { init_parameters(in_frame, codec_context); - if (avcodec_open2(codec_context, codec, 0) != -1) { + if (avcodec_open2(codec_context, codec, 0) != -1) + { AVPacket pkt; av_init_packet(&pkt); /* encode the image */ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) int got_output = 0; int ret = avcodec_encode_video2(codec_context, &pkt, in_frame, &got_output); - if (ret != -1) { - if (got_output) { + if (ret != -1) + { + if (got_output) + { fwrite(pkt.data, 1, pkt.size, fp); av_packet_unref(&pkt); } int i = 1; - for (got_output = 1; got_output; i++) { - /* get the delayed frames */ + for (got_output = 1; got_output; i++) + { + /* get the delayed frames */ in_frame->pts = i; ret = avcodec_encode_video2(codec_context, &pkt, 0, &got_output); - if (ret != -1 && got_output) { + if (ret != -1 && got_output) + { fwrite(pkt.data, 1, pkt.size, fp); av_packet_unref(&pkt); } @@ -227,16 +244,19 @@ void write_frame(AVFrame* in_frame, FILE* fp) } #else int ret = avcodec_send_frame(codec_context, in_frame); - if (!ret) { + if (!ret) + { /* signalling end of stream */ ret = avcodec_send_frame(codec_context, NULL); } - if (!ret) { + if (!ret) + { int i = 1; /* get the delayed frames */ in_frame->pts = i; ret = avcodec_receive_packet(codec_context, &pkt); - if (!ret) { + if (!ret) + { fwrite(pkt.data, 1, pkt.size, fp); av_packet_unref(&pkt); } @@ -249,13 +269,15 @@ void write_frame(AVFrame* in_frame, FILE* fp) } } -int decode_frame(AVCodecContext *codecContext,AVPacket &packet, FILE* fp) +int decode_frame(AVCodecContext *codecContext, AVPacket &packet, FILE *fp) { AVFrame *frame = av_frame_alloc(); - if(frame){ + if (frame) + { #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) int decode_ok = 0; - if ((avcodec_decode_video2(codecContext, frame, &decode_ok, &packet)) < 0 || !decode_ok){ + if ((avcodec_decode_video2(codecContext, frame, &decode_ok, &packet)) < 0 || !decode_ok) + { av_frame_free(&frame); return -1; } @@ -264,25 +286,29 @@ int decode_frame(AVCodecContext *codecContext,AVPacket &packet, FILE* fp) ret = avcodec_send_packet(codecContext, &packet); // In particular, we don't expect AVERROR(EAGAIN), because we read all // decoded frames with avcodec_receive_frame() until done. - if (ret < 0) { + if (ret < 0) + { av_frame_free(&frame); return -1; } ret = avcodec_receive_frame(codecContext, frame); - if (ret < 0) { + if (ret < 0) + { av_frame_free(&frame); return -1; } #endif AVFrame *dest_frame = av_frame_alloc(); - if(dest_frame){ - dest_frame->height = (frame->height/2)*2; - dest_frame->width = (frame->width/2)*2; + if (dest_frame) + { + dest_frame->height = (frame->height / 2) * 2; + dest_frame->width = (frame->width / 2) * 2; dest_frame->format = AV_PIX_FMT_YUV420P; av_frame_get_buffer(dest_frame, 32); struct SwsContext *convert = NULL; convert = sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format, dest_frame->width, dest_frame->height, AV_PIX_FMT_YUVJ420P, SWS_FAST_BILINEAR, NULL, NULL, NULL); - if(convert){ + if (convert) + { sws_scale(convert, frame->data, frame->linesize, 0, frame->height, dest_frame->data, dest_frame->linesize); sws_freeContext(convert); } @@ -295,19 +321,23 @@ int decode_frame(AVCodecContext *codecContext,AVPacket &packet, FILE* fp) } -AVCodecContext* open_codec(AVMediaType mediaType, AVFormatContext* formatContext) +AVCodecContext *open_codec(AVMediaType mediaType, AVFormatContext *formatContext) { - AVCodec * codec = NULL; - AVCodecContext * codecContext = NULL; + AVCodec *codec = NULL; + AVCodecContext *codecContext = NULL; int stream_index; #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(57,25,101) stream_index = av_find_best_stream(formatContext, mediaType, -1, -1, NULL, 0); - if (stream_index >=0 ){ + if (stream_index >= 0) + { codecContext = formatContext->streams[stream_index]->codec; - if(codecContext){ + if (codecContext) + { codec = avcodec_find_decoder(codecContext->codec_id); - if(codec){ - if ((avcodec_open2(codecContext, codec, NULL)) != 0){ + if (codec) + { + if ((avcodec_open2(codecContext, codec, NULL)) != 0) + { return NULL; } } @@ -317,13 +347,17 @@ AVCodecContext* open_codec(AVMediaType mediaType, AVFormatContext* formatContext return NULL; #else stream_index = av_find_best_stream(formatContext, mediaType, -1, -1, &codec, 0); - if (stream_index >= 0) { + if (stream_index >= 0) + { codec = avcodec_find_decoder(formatContext->streams[stream_index]->codecpar->codec_id); - if (codec) { + if (codec) + { codecContext = avcodec_alloc_context3(codec); } - if (codecContext) { - if ((avcodec_open2(codecContext, codec, NULL)) != 0) { + if (codecContext) + { + if ((avcodec_open2(codecContext, codec, NULL)) != 0) + { return NULL; } return codecContext; @@ -342,15 +376,20 @@ int image_to_mpeg2(const char *image_name, const char *encode_name) #endif AVFormatContext *formatContext = avformat_alloc_context(); - if (formatContext && (ret = avformat_open_input(&formatContext, image_name, NULL, NULL)) == 0){ + if (formatContext && (ret = avformat_open_input(&formatContext, image_name, NULL, NULL)) == 0) + { AVCodecContext *codecContext = open_codec(AVMEDIA_TYPE_VIDEO, formatContext); - if(codecContext){ + if (codecContext) + { AVPacket packet; av_init_packet(&packet); - if ((ret = av_read_frame(formatContext, &packet)) !=-1){ - FILE* fp = fopen(encode_name, "wb"); - if(fp){ - if(decode_frame(codecContext, packet, fp) != 1){ + if ((ret = av_read_frame(formatContext, &packet)) != -1) + { + FILE *fp = fopen(encode_name, "wb"); + if (fp) + { + if (decode_frame(codecContext, packet, fp) != 1) + { /* add sequence end code to have a real mpeg file */ uint8_t endcode[] = { 0, 0, 1, 0xb7 }; fwrite(endcode, 1, sizeof(endcode), fp); @@ -375,7 +414,8 @@ void cVideo::setAVInput(int val) hal_info("%s not implemented yet - switching to: %s\n", __func__, val == AUX ? "SCART" : "ENCODER"); #if 0 // not working int input_fd = open("/proc/stb/avs/0/input", O_WRONLY); - if(input_fd){ + if (input_fd) + { const char *input[] = {"encoder", "scart"}; write(input_fd, input[val], strlen(input[val])); close(input_fd); @@ -394,10 +434,12 @@ cVideo::cVideo(int, void *, void *, unsigned int unit) scartvoltage = -1; video_standby = 0; - if (unit > 1) { + if (unit > 1) + { hal_info("%s: unit %d out of range, setting to 0\n", __func__, unit); devnum = 0; - } else + } + else devnum = unit; fd = -1; openDevice(); @@ -416,7 +458,7 @@ void cVideo::openDevice(void) if (fd != -1) /* already open */ return; retry: - if ((fd = open(VDEV[devnum], O_RDWR|O_CLOEXEC)) < 0) + if ((fd = open(VDEV[devnum], O_RDWR | O_CLOEXEC)) < 0) { if (errno == EBUSY) { @@ -447,7 +489,7 @@ int cVideo::setAspectRatio(int aspect, int mode) static const char *m[] = { "panscan", "letterbox", "bestfit", "nonlinear", "(unset)" }; int n; - int mo = (mode < 0||mode > 3) ? 4 : mode; + int mo = (mode < 0 || mode > 3) ? 4 : mode; hal_debug("%s: a:%d m:%d %s\n", __func__, aspect, mode, m[mo]); if (aspect > 3 || aspect == 0) @@ -514,7 +556,8 @@ int cVideo::Start(void * /*PcrChannel*/, unsigned short /*PcrPid*/, unsigned sho fop(ioctl, MPEG_VID_CONTINUE); #endif /* implicitly do StopPicture() on video->Start() */ - if (stillpicture) { + if (stillpicture) + { hal_info("%s: stillpicture == true, doing implicit StopPicture()\n", __func__); stillpicture = false; Stop(1); @@ -522,19 +565,23 @@ int cVideo::Start(void * /*PcrChannel*/, unsigned short /*PcrPid*/, unsigned sho playstate = VIDEO_PLAYING; fop(ioctl, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX); int res = fop(ioctl, VIDEO_PLAY); - if (brightness > -1) { + if (brightness > -1) + { SetControl(VIDEO_CONTROL_BRIGHTNESS, brightness); brightness = -1; } - if (contrast > -1) { + if (contrast > -1) + { SetControl(VIDEO_CONTROL_CONTRAST, contrast); contrast = -1; } - if (saturation > -1) { + if (saturation > -1) + { SetControl(VIDEO_CONTROL_SATURATION, saturation); saturation = -1; } - if (hue > -1) { + if (hue > -1) + { SetControl(VIDEO_CONTROL_HUE, hue); hue = -1; } @@ -587,7 +634,7 @@ int cVideo::SetVideoSystem(int video_system, bool remember) stopped = true; } hdmi_out(false); - ret = proc_put("/proc/stb/video/videomode", vid_modes[video_system],strlen(vid_modes[video_system])); + ret = proc_put("/proc/stb/video/videomode", vid_modes[video_system], strlen(vid_modes[video_system])); hdmi_out(true); if (stopped) Start(); @@ -612,10 +659,12 @@ void cVideo::GetVideoSystemFormatName(cs_vs_format_t *format, int system) { if (system == -1) system = GetVideoSystem(); - if (system < 0 || system > VIDEO_STD_1080P50) { + if (system < 0 || system > VIDEO_STD_1080P50) + { hal_info("%s: invalid system %d\n", __func__, system); strcpy(format->format, "invalid"); - } else + } + else strcpy(format->format, vid_modes[system]); } @@ -633,7 +682,7 @@ void cVideo::SetVideoMode(analog_mode_t mode) return; } const char *m; - switch(mode) + switch (mode) { case ANALOG_SD_YPRPB_SCART: m = "yuv"; @@ -649,7 +698,7 @@ void cVideo::SetVideoMode(analog_mode_t mode) proc_put("/proc/stb/avs/0/colorformat", m, strlen(m)); } -bool cVideo::ShowPicture(const char * fname, const char *_destname) +bool cVideo::ShowPicture(const char *fname, const char *_destname) { bool ret = false; hal_debug("%s(%s)\n", __func__, fname); @@ -676,10 +725,12 @@ bool cVideo::ShowPicture(const char * fname, const char *_destname) const char *lastDot = strrchr(fname, '.'); if (lastDot && !strcasecmp(lastDot + 1, "m2v")) strncpy(destname, fname, sizeof(destname)); - else { + else + { if (_destname) strncpy(destname, _destname, sizeof(destname)); - else { + else + { strcpy(destname, "/tmp/cache"); if (stat(fname, &st2)) { @@ -694,7 +745,7 @@ bool cVideo::ShowPicture(const char * fname, const char *_destname) strcat(destname, fname); p = &destname[strlen("/tmp/cache/")]; while ((p = strchr(p, '/')) != NULL) - *p = '.'; + * p = '.'; strcat(destname, ".m2v"); } /* ...then check if it exists already... */ @@ -726,7 +777,7 @@ bool cVideo::ShowPicture(const char * fname, const char *_destname) if (ioctl(fd, VIDEO_SET_FORMAT, VIDEO_FORMAT_16_9) < 0) hal_info("%s: VIDEO_SET_FORMAT failed (%m)\n", __func__); bool seq_end_avail = false; - off_t pos=0; + off_t pos = 0; unsigned char *iframe = (unsigned char *)malloc((st.st_size < 8192) ? 8192 : st.st_size); if (! iframe) { @@ -738,7 +789,7 @@ bool cVideo::ShowPicture(const char * fname, const char *_destname) ioctl(fd, VIDEO_PLAY); ioctl(fd, VIDEO_CONTINUE); ioctl(fd, VIDEO_CLEAR_BUFFER); - while (pos <= (st.st_size-4) && !(seq_end_avail = (!iframe[pos] && !iframe[pos+1] && iframe[pos+2] == 1 && iframe[pos+3] == 0xB7))) + while (pos <= (st.st_size - 4) && !(seq_end_avail = (!iframe[pos] && !iframe[pos + 1] && iframe[pos + 2] == 1 && iframe[pos + 3] == 0xB7))) ++pos; if ((iframe[3] >> 4) != 0xE) // no pes header @@ -752,7 +803,7 @@ bool cVideo::ShowPicture(const char * fname, const char *_destname) free(iframe); ret = true; } - out: +out: close(mfd); return ret; } @@ -953,7 +1004,8 @@ void cVideo::SetSyncMode(AVSYNC_TYPE mode) int cVideo::SetStreamType(VIDEO_FORMAT type) { - static const char *VF[] = { + static const char *VF[] = + { "VIDEO_FORMAT_MPEG2", "VIDEO_FORMAT_MPEG4", "VIDEO_FORMAT_VC1", @@ -1002,27 +1054,30 @@ void cVideo::SetDemux(cDemux *) hal_debug("#%d %s not implemented yet\n", devnum, __func__); } -void cVideo::SetControl(int control, int value) { +void cVideo::SetControl(int control, int value) +{ const char *p = NULL; - switch (control) { - case VIDEO_CONTROL_BRIGHTNESS: - brightness = value; - p = "/proc/stb/video/plane/psi_brightness"; - break; - case VIDEO_CONTROL_CONTRAST: - contrast = value; - p = "/proc/stb/video/plane/psi_contrast"; - break; - case VIDEO_CONTROL_SATURATION: - saturation = value; - p = "/proc/stb/video/plane/psi_saturation"; - break; - case VIDEO_CONTROL_HUE: - hue = value; - p = "/proc/stb/video/plane/psi_tint"; - break; + switch (control) + { + case VIDEO_CONTROL_BRIGHTNESS: + brightness = value; + p = "/proc/stb/video/plane/psi_brightness"; + break; + case VIDEO_CONTROL_CONTRAST: + contrast = value; + p = "/proc/stb/video/plane/psi_contrast"; + break; + case VIDEO_CONTROL_SATURATION: + saturation = value; + p = "/proc/stb/video/plane/psi_saturation"; + break; + case VIDEO_CONTROL_HUE: + hue = value; + p = "/proc/stb/video/plane/psi_tint"; + break; } - if (p) { + if (p) + { char buf[20]; int len = snprintf(buf, sizeof(buf), "%d", value); if (len < (int) sizeof(buf)) @@ -1030,30 +1085,32 @@ void cVideo::SetControl(int control, int value) { } } -void cVideo::SetColorFormat(COLOR_FORMAT color_format) { +void cVideo::SetColorFormat(COLOR_FORMAT color_format) +{ const char *p = NULL; - switch(color_format) { - case COLORFORMAT_RGB: - p = "rgb"; - break; - case COLORFORMAT_YUV: - p = "yuv"; - break; - case COLORFORMAT_CVBS: - p = "cvbs"; - break; - case COLORFORMAT_SVIDEO: - p = "svideo"; - break; - case COLORFORMAT_HDMI_RGB: - p = "hdmi_rgb"; - break; - case COLORFORMAT_HDMI_YCBCR444: - p = "hdmi_yuv"; - break; - case COLORFORMAT_HDMI_YCBCR422: - p = "hdmi_422"; - break; + switch (color_format) + { + case COLORFORMAT_RGB: + p = "rgb"; + break; + case COLORFORMAT_YUV: + p = "yuv"; + break; + case COLORFORMAT_CVBS: + p = "cvbs"; + break; + case COLORFORMAT_SVIDEO: + p = "svideo"; + break; + case COLORFORMAT_HDMI_RGB: + p = "hdmi_rgb"; + break; + case COLORFORMAT_HDMI_YCBCR444: + p = "hdmi_yuv"; + break; + case COLORFORMAT_HDMI_YCBCR422: + p = "hdmi_422"; + break; } if (p) proc_put("/proc/stb/avs/0/colorformat", p, strlen(p)); @@ -1065,7 +1122,8 @@ void cVideo::SetColorFormat(COLOR_FORMAT color_format) { * and the patches for STi support from * https://github.com/Schischu/STLinux.BSP-Duckbox.git */ /* static lookup tables for faster yuv2rgb conversion */ -static const uint32_t yuv2rgbtable_y[256] = { +static const uint32_t yuv2rgbtable_y[256] = +{ 0xFFED5EA0, 0xFFEE88B6, 0xFFEFB2CC, 0xFFF0DCE2, 0xFFF206F8, 0xFFF3310E, 0xFFF45B24, 0xFFF5853A, 0xFFF6AF50, 0xFFF7D966, 0xFFF9037C, 0xFFFA2D92, 0xFFFB57A8, 0xFFFC81BE, 0xFFFDABD4, 0xFFFED5EA, 0x00000000, 0x00012A16, 0x0002542C, 0x00037E42, 0x0004A858, 0x0005D26E, 0x0006FC84, 0x0008269A, @@ -1099,7 +1157,8 @@ static const uint32_t yuv2rgbtable_y[256] = { 0x0104D340, 0x0105FD56, 0x0107276C, 0x01085182, 0x01097B98, 0x010AA5AE, 0x010BCFC4, 0x010CF9DA, 0x010E23F0, 0x010F4E06, 0x0110781C, 0x0111A232, 0x0112CC48, 0x0113F65E, 0x01152074, 0x01164A8A }; -static const uint32_t yuv2rgbtable_ru[256] = { +static const uint32_t yuv2rgbtable_ru[256] = +{ 0xFEFDA500, 0xFEFFA9B6, 0xFF01AE6C, 0xFF03B322, 0xFF05B7D8, 0xFF07BC8E, 0xFF09C144, 0xFF0BC5FA, 0xFF0DCAB0, 0xFF0FCF66, 0xFF11D41C, 0xFF13D8D2, 0xFF15DD88, 0xFF17E23E, 0xFF19E6F4, 0xFF1BEBAA, 0xFF1DF060, 0xFF1FF516, 0xFF21F9CC, 0xFF23FE82, 0xFF260338, 0xFF2807EE, 0xFF2A0CA4, 0xFF2C115A, @@ -1133,7 +1192,8 @@ static const uint32_t yuv2rgbtable_ru[256] = { 0x00E20FA0, 0x00E41456, 0x00E6190C, 0x00E81DC2, 0x00EA2278, 0x00EC272E, 0x00EE2BE4, 0x00F0309A, 0x00F23550, 0x00F43A06, 0x00F63EBC, 0x00F84372, 0x00FA4828, 0x00FC4CDE, 0x00FE5194, 0x00100564A }; -static const uint32_t yuv2rgbtable_gu[256] = { +static const uint32_t yuv2rgbtable_gu[256] = +{ 0xFFCDD300, 0xFFCE375A, 0xFFCE9BB4, 0xFFCF000E, 0xFFCF6468, 0xFFCFC8C2, 0xFFD02D1C, 0xFFD09176, 0xFFD0F5D0, 0xFFD15A2A, 0xFFD1BE84, 0xFFD222DE, 0xFFD28738, 0xFFD2EB92, 0xFFD34FEC, 0xFFD3B446, 0xFFD418A0, 0xFFD47CFA, 0xFFD4E154, 0xFFD545AE, 0xFFD5AA08, 0xFFD60E62, 0xFFD672BC, 0xFFD6D716, @@ -1167,7 +1227,8 @@ static const uint32_t yuv2rgbtable_gu[256] = { 0x002BE760, 0x002C4BBA, 0x002CB014, 0x002D146E, 0x002D78C8, 0x002DDD22, 0x002E417C, 0x002EA5D6, 0x002F0A30, 0x002F6E8A, 0x002FD2E4, 0x0030373E, 0x00309B98, 0x0030FFF2, 0x0031644C, 0x0031C8A6 }; -static const uint32_t yuv2rgbtable_gv[256] = { +static const uint32_t yuv2rgbtable_gv[256] = +{ 0xFF97E900, 0xFF98B92E, 0xFF99895C, 0xFF9A598A, 0xFF9B29B8, 0xFF9BF9E6, 0xFF9CCA14, 0xFF9D9A42, 0xFF9E6A70, 0xFF9F3A9E, 0xFFA00ACC, 0xFFA0DAFA, 0xFFA1AB28, 0xFFA27B56, 0xFFA34B84, 0xFFA41BB2, 0xFFA4EBE0, 0xFFA5BC0E, 0xFFA68C3C, 0xFFA75C6A, 0xFFA82C98, 0xFFA8FCC6, 0xFFA9CCF4, 0xFFAA9D22, @@ -1201,7 +1262,8 @@ static const uint32_t yuv2rgbtable_gv[256] = { 0x005B1420, 0x005BE44E, 0x005CB47C, 0x005D84AA, 0x005E54D8, 0x005F2506, 0x005FF534, 0x0060C562, 0x00619590, 0x006265BE, 0x006335EC, 0x0064061A, 0x0064D648, 0x0065A676, 0x006676A4, 0x006746D2 }; -static const uint32_t yuv2rgbtable_bv[256] = { +static const uint32_t yuv2rgbtable_bv[256] = +{ 0xFF33A280, 0xFF353B3B, 0xFF36D3F6, 0xFF386CB1, 0xFF3A056C, 0xFF3B9E27, 0xFF3D36E2, 0xFF3ECF9D, 0xFF406858, 0xFF420113, 0xFF4399CE, 0xFF453289, 0xFF46CB44, 0xFF4863FF, 0xFF49FCBA, 0xFF4B9575, 0xFF4D2E30, 0xFF4EC6EB, 0xFF505FA6, 0xFF51F861, 0xFF53911C, 0xFF5529D7, 0xFF56C292, 0xFF585B4D, @@ -1272,14 +1334,14 @@ static const uint32_t yuv2rgbtable_bv[256] = { OUT_CH_8A(x + (l/4) * 0x10 + (l%2) * 0x40 + ((l/2)%2?0x00:0x08) + (b?0x04:0x00)); //---- -#define CLAMP(x) ((x < 0) ? 0 : ((x > 255) ? 255 : x)) -#define SWAP(x,y) { x ^= y; y ^= x; x ^= y; } +#define CLAMP(x) ((x < 0) ? 0 : ((x > 255) ? 255 : x)) +#define SWAP(x,y) { x ^= y; y ^= x; x ^= y; } /* TODO: aspect ratio correction and PIP */ -bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool get_video, bool get_osd, bool scale_to_video) +bool cVideo::GetScreenImage(unsigned char *&video, int &xres, int &yres, bool get_video, bool get_osd, bool scale_to_video) { hal_info("%s: get_video: %d get_osd: %d scale_to_video: %d\n", - __func__, get_video, get_osd, scale_to_video); + __func__, get_video, get_osd, scale_to_video); int fbfd = -1, bpafd = -1; int vid_x, vid_y, osd_x, osd_y, aspect; @@ -1293,7 +1355,8 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g hal_info("%s: WARNING, video != NULL?\n", __func__); fbfd = open("/dev/fb0", O_RDWR); - if (fbfd < 0) { + if (fbfd < 0) + { hal_info("%s: cannot open open /dev/fb0 (%m)\n", __func__); return false; } @@ -1303,12 +1366,14 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) hal_info("%s: FBIOGET_VSCREENINFO (%m)\n", __func__); - if (var_screeninfo.bits_per_pixel != 32) { + if (var_screeninfo.bits_per_pixel != 32) + { hal_info("%s: only 32bit framebuffer supported.\n", __func__); close(fbfd); return false; } - if (fix_screeninfo.line_length - (var_screeninfo.xres * 4) != 0) { + if (fix_screeninfo.line_length - (var_screeninfo.xres * 4) != 0) + { hal_info("%s: framebuffer with offset not supported.\n", __func__); close(fbfd); return false; @@ -1326,10 +1391,13 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g if (get_video && get_osd) { - if (scale_to_video) { + if (scale_to_video) + { xres = vid_x; yres = vid_y; - } else { + } + else + { xres = osd_x; yres = osd_y; } @@ -1377,7 +1445,7 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g hal_info("%s: cannot open secondary bpamem device %s: %m\n", __func__, bpa_mem_device); goto error_cleanup; } - bpa = (uint8_t *)mmap(0, bpa_data.mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, bpafd, 0); + bpa = (uint8_t *)mmap(0, bpa_data.mem_size, PROT_WRITE | PROT_READ, MAP_SHARED, bpafd, 0); if (bpa == MAP_FAILED) { hal_info("%s: cannot map from bpamem: %m\n", __func__); @@ -1418,19 +1486,22 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g } fclose(pipe); } - if (vid_phys_addr == 0) { + if (vid_phys_addr == 0) + { hal_info("%s: primary display pane not found in /proc/bpa2\n", __func__); } mfd = open("/dev/mem", O_RDWR | O_CLOEXEC); - if (mfd < 0) { + if (mfd < 0) + { hal_info("%s: cannot open open /dev/mem (%m)\n", __func__); goto error_cleanup; } hal_info("%s: Using bpa2 part LMI_VID - 0x%lx %lu\n", __func__, vid_phys_addr, vid_mem_size); decode_surface = (uint8_t *)mmap(0, vid_mem_size, PROT_READ, MAP_SHARED, mfd, vid_phys_addr); - if (decode_surface == MAP_FAILED) { + if (decode_surface == MAP_FAILED) + { hal_info("%s: cannot mmap /dev/mem for VIDEO (%m)\n", __func__); close(mfd); goto error_cleanup; @@ -1499,21 +1570,21 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g xblock = stride_half >> 3;/// 8; //no roundin //if xblock is not even than we will have to move to the next even value an - yblockoffset = (((xblock + 1) >> 1 /* / 2*/) << 1 /* * 2*/ ) << 8 /* * 64=8x8px * 2=2 block rows * 2=cr cb*/; + yblockoffset = (((xblock + 1) >> 1 /* / 2*/) << 1 /* * 2*/) << 8 /* * 64=8x8px * 2=2 block rows * 2=cr cb*/; OUTITER = 0; OUTITERoffset = 0; OUTINC = 2; out = chroma; - for(cr = 0; cr < 2; cr++) + for (cr = 0; cr < 2; cr++) { - for(even = 0; even < 2; even++) + for (even = 0; even < 2; even++) { offset = layer_offset + (even << 8 /* * 0x100*/); OUTITERoffset = even * (xblock << 7 /* * 128=8x8px * 2*/) + cr; - for (iyblock = even; iyblock < yblock; iyblock+=2) + for (iyblock = even; iyblock < yblock; iyblock += 2) { for (ixblock = 0; ixblock < xblock; ixblock++) { @@ -1527,7 +1598,7 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g } //0x00 0x80 0x200 0x280, ... - offset += (offset%0x100?0x180/*80->200*/:0x80/*0->80*/); + offset += (offset % 0x100 ? 0x180/*80->200*/ : 0x80/*0->80*/); OUTITERoffset += 16/*OUTINC*8=16*/; } OUTITERoffset += (vid_x << 4) - vid_x /* * 15*/; @@ -1545,7 +1616,7 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g const int rgbstride = vid_x * 3; const int scans = vid_y / 2; int y; - for (y=0; y < scans; ++y) + for (y = 0; y < scans; ++y) { int x; int out1 = y * rgbstride * 2; @@ -1566,16 +1637,16 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g int Y = yuv2rgbtable_y[luma[pos]]; //p0:0 - vid[out1 ] = CLAMP((Y + RU)>>16); - vid[out1+1] = CLAMP((Y - GV - GU)>>16); - vid[out1+2] = CLAMP((Y + BV)>>16); + vid[out1 ] = CLAMP((Y + RU) >> 16); + vid[out1 + 1] = CLAMP((Y - GV - GU) >> 16); + vid[out1 + 2] = CLAMP((Y + BV) >> 16); Y = yuv2rgbtable_y[luma[vid_x + pos]]; //p1:0 - vid[out1 +rgbstride] = CLAMP((Y + RU)>>16); - vid[out1+1+rgbstride] = CLAMP((Y - GV - GU)>>16); - vid[out1+2+rgbstride] = CLAMP((Y + BV)>>16); + vid[out1 + rgbstride] = CLAMP((Y + RU) >> 16); + vid[out1 + 1 + rgbstride] = CLAMP((Y - GV - GU) >> 16); + vid[out1 + 2 + rgbstride] = CLAMP((Y + BV) >> 16); out1 += 3; pos++; @@ -1583,16 +1654,16 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g Y = yuv2rgbtable_y[luma[pos]]; //p0:1 - vid[out1 ] = CLAMP((Y + RU)>>16); - vid[out1+1] = CLAMP((Y - GV - GU)>>16); - vid[out1+2] = CLAMP((Y + BV)>>16); + vid[out1 ] = CLAMP((Y + RU) >> 16); + vid[out1 + 1] = CLAMP((Y - GV - GU) >> 16); + vid[out1 + 2] = CLAMP((Y + BV) >> 16); Y = yuv2rgbtable_y[luma[vid_x + pos]]; //p1:1 - vid[out1 +rgbstride] = CLAMP((Y + RU)>>16); - vid[out1+1+rgbstride] = CLAMP((Y - GV - GU)>>16); - vid[out1+2+rgbstride] = CLAMP((Y + BV)>>16); + vid[out1 + rgbstride] = CLAMP((Y + RU) >> 16); + vid[out1 + 1 + rgbstride] = CLAMP((Y - GV - GU) >> 16); + vid[out1 + 2 + rgbstride] = CLAMP((Y + BV) >> 16); out1 += 3; pos++; @@ -1605,8 +1676,9 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g uint8_t *lfb = (uint8_t *)mmap(0, fix_screeninfo.smem_len, PROT_READ, MAP_SHARED, fbfd, 0); if (lfb == MAP_FAILED) hal_info("%s: mmap fb memory failed (%m)\n", __func__); - else { - memcpy(osd, lfb, fix_screeninfo.line_length*var_screeninfo.yres); + else + { + memcpy(osd, lfb, fix_screeninfo.line_length * var_screeninfo.yres); munmap(lfb, fix_screeninfo.smem_len); } } @@ -1620,7 +1692,8 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g int pip_w = xres; int pip_h = yres; bool scale = false; - if (get_osd) { + if (get_osd) + { pip_x = proc_get_hex("/proc/stb/vmpeg/0/dst_left"); pip_y = proc_get_hex("/proc/stb/vmpeg/0/dst_top"); pip_w = proc_get_hex("/proc/stb/vmpeg/0/dst_width"); @@ -1633,15 +1706,20 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g pip_h = pip_h * yres / 576; if (scale == false && aspect == 1) { - pip_w = xres * 9/16*4/3; + pip_w = xres * 9 / 16 * 4 / 3; pip_x = (xres - pip_w) / 2; } } - if (scale || aspect == 1) { + if (scale || aspect == 1) + { /* todo: use the blitter, luke */ uint8_t *p = bpa - 1; - for (int i = 0; i < outmem; i += 4) { - *++p = 0; *++p = 0; *++p = 0; *++p = 0xff; + for (int i = 0; i < outmem; i += 4) + { + *++p = 0; + *++p = 0; + *++p = 0; + *++p = 0xff; } } @@ -1674,7 +1752,7 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g memset(&blt_data, 0, sizeof(STMFBIO_BLT_EXTERN_DATA)); blt_data.operation = BLT_OP_COPY; if (get_video) - blt_data.ulFlags = BLT_OP_FLAGS_BLEND_SRC_ALPHA|BLT_OP_FLAGS_BLEND_DST_MEMORY; + blt_data.ulFlags = BLT_OP_FLAGS_BLEND_SRC_ALPHA | BLT_OP_FLAGS_BLEND_DST_MEMORY; else blt_data.ulFlags = 0; blt_data.srcOffset = 0; @@ -1711,10 +1789,11 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g close(fbfd); return true; - error_cleanup: +error_cleanup: if (bpa != MAP_FAILED) munmap(bpa, bpa_data.mem_size); - if (bpafd > -1) { + if (bpafd > -1) + { ioctl(bpafd, BPAMEMIO_FREEMEM); close(bpafd); } diff --git a/libspark/video_lib.h b/libspark/video_lib.h index 38267ff..8fbea28 100644 --- a/libspark/video_lib.h +++ b/libspark/video_lib.h @@ -10,7 +10,8 @@ typedef struct cs_vs_format_t char format[16]; } cs_vs_format_struct_t; -typedef enum { +typedef enum +{ ANALOG_SD_RGB_CINCH = 0x00, ANALOG_SD_YPRPB_CINCH, ANALOG_HD_RGB_CINCH, @@ -22,7 +23,8 @@ typedef enum { ANALOG_SCART_MASK = 0x10 } analog_mode_t; -typedef enum { +typedef enum +{ COLORFORMAT_RGB = 0x10, // keep compatible with analog_mode_t COLORFORMAT_YUV, COLORFORMAT_CVBS, @@ -32,7 +34,8 @@ typedef enum { COLORFORMAT_HDMI_YCBCR422 } COLOR_FORMAT; -typedef enum { +typedef enum +{ VIDEO_FORMAT_MPEG2 = 0, VIDEO_FORMAT_MPEG4_H264, VIDEO_FORMAT_VC1, @@ -43,7 +46,8 @@ typedef enum { VIDEO_FORMAT_AVS = 16 } VIDEO_FORMAT; -typedef enum { +typedef enum +{ VIDEO_SD = 0, VIDEO_HD, VIDEO_120x60i, @@ -52,7 +56,8 @@ typedef enum { VIDEO_360x288i } VIDEO_DEFINITION; -typedef enum { +typedef enum +{ VIDEO_FRAME_RATE_23_976 = 0, VIDEO_FRAME_RATE_24, VIDEO_FRAME_RATE_25, @@ -63,7 +68,8 @@ typedef enum { VIDEO_FRAME_RATE_60 } VIDEO_FRAME_RATE; -typedef enum { +typedef enum +{ DISPLAY_AR_1_1, DISPLAY_AR_4_3, DISPLAY_AR_14_9, @@ -72,20 +78,23 @@ typedef enum { DISPLAY_AR_RAW } DISPLAY_AR; -typedef enum { +typedef enum +{ DISPLAY_AR_MODE_PANSCAN = 0, DISPLAY_AR_MODE_LETTERBOX, DISPLAY_AR_MODE_NONE, DISPLAY_AR_MODE_PANSCAN2 } DISPLAY_AR_MODE; -typedef enum { +typedef enum +{ VIDEO_DB_DR_NEITHER = 0, VIDEO_DB_ON, VIDEO_DB_DR_BOTH } VIDEO_DB_DR; -typedef enum { +typedef enum +{ VIDEO_PLAY_STILL = 0, VIDEO_PLAY_CLIP, VIDEO_PLAY_TRICK, @@ -93,7 +102,8 @@ typedef enum { VIDEO_PLAY_MOTION_NO_SYNC } VIDEO_PLAY_MODE; -typedef enum { +typedef enum +{ VIDEO_STD_NTSC, VIDEO_STD_SECAM, VIDEO_STD_PAL, @@ -107,12 +117,13 @@ typedef enum { VIDEO_STD_1080P24, VIDEO_STD_1080P25, VIDEO_STD_AUTO, - VIDEO_STD_1080P50, /* SPARK only */ + VIDEO_STD_1080P50, /* SPARK only */ VIDEO_STD_MAX } VIDEO_STD; /* not used, for dummy functions */ -typedef enum { +typedef enum +{ VIDEO_HDMI_CEC_MODE_OFF = 0, VIDEO_HDMI_CEC_MODE_TUNER, VIDEO_HDMI_CEC_MODE_RECORDER @@ -130,8 +141,8 @@ typedef enum class cVideo { - friend class cPlayback; - friend class cDemux; + friend class cPlayback; + friend class cDemux; private: /* video device */ int fd; @@ -164,13 +175,25 @@ class cVideo cVideo(int mode, void *, void *, unsigned int unit = 0); ~cVideo(void); - void open_AVInput_Device(void) { return; }; // Dummy - void close_AVInput_Device(void) { return; }; // Dummy + void open_AVInput_Device(void) + { + return; + }; // Dummy + void close_AVInput_Device(void) + { + return; + }; // Dummy void setAVInput(int val); - void * GetTVEnc() { return NULL; }; - void * GetTVEncSD() { return NULL; }; + void *GetTVEnc() + { + return NULL; + }; + void *GetTVEncSD() + { + return NULL; + }; /* aspect ratio */ int getAspectRatio(void); @@ -195,16 +218,25 @@ class cVideo /* get video system infos */ int GetVideoSystem(void); /* when system = -1 then use current video system */ - void GetVideoSystemFormatName(cs_vs_format_t* format, int system = -1); + void GetVideoSystemFormatName(cs_vs_format_t *format, int system = -1); /* set video_system */ int SetVideoSystem(int video_system, bool remember = true); int SetStreamType(VIDEO_FORMAT type); void SetSyncMode(AVSYNC_TYPE mode); - bool SetCECMode(VIDEO_HDMI_CEC_MODE) { return true; }; - void SetCECAutoView(bool) { return; }; - void SetCECAutoStandby(bool) { return; }; - bool ShowPicture(const char * fname, const char *_destname = NULL); + bool SetCECMode(VIDEO_HDMI_CEC_MODE) + { + return true; + }; + void SetCECAutoView(bool) + { + return; + }; + void SetCECAutoStandby(bool) + { + return; + }; + bool ShowPicture(const char *fname, const char *_destname = NULL); void StopPicture(); void Standby(unsigned int bOn); void ShowPig(int _x); @@ -213,16 +245,37 @@ class cVideo void VideoParamWatchdog(void); void setContrast(int val); void SetVideoMode(analog_mode_t mode); - void SetDBDR(int) { return; }; - void SetAudioHandle(void *) { return; }; - void SetAutoModes(int [VIDEO_STD_MAX]) { return; }; - int OpenVBI(int) { return 0; }; - int CloseVBI(void) { return 0; }; - int StartVBI(unsigned short) { return 0; }; - int StopVBI(void) { return 0; }; + void SetDBDR(int) + { + return; + }; + void SetAudioHandle(void *) + { + return; + }; + void SetAutoModes(int [VIDEO_STD_MAX]) + { + return; + }; + int OpenVBI(int) + { + return 0; + }; + int CloseVBI(void) + { + return 0; + }; + int StartVBI(unsigned short) + { + return 0; + }; + int StopVBI(void) + { + return 0; + }; void SetDemux(cDemux *dmx); void SetColorFormat(COLOR_FORMAT color_format); - bool GetScreenImage(unsigned char * &data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); + bool GetScreenImage(unsigned char *&data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); }; #endif // __VIDEO_LIB_H__ diff --git a/libtest.cpp b/libtest.cpp index fab6ead..9377cad 100644 --- a/libtest.cpp +++ b/libtest.cpp @@ -16,18 +16,19 @@ extern GLFramebuffer *glfb; #define fb_pixel_t uint32_t #endif -int main(int argc __attribute__((unused)), char ** argv __attribute__((unused))) +int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) { hal_api_init(); #if HAVE_GENERIC_HARDWARE int available = glfb->getOSDBuffer()->size(); /* allocated in glfb constructor */ - fb_pixel_t *lfb = reinterpret_cast(glfb->getOSDBuffer()->data()); + fb_pixel_t *lfb = reinterpret_cast(glfb->getOSDBuffer()->data()); int x = 0; #endif - while (1) { + while (1) + { #if HAVE_GENERIC_HARDWARE - fb_pixel_t c = (0xff << (8 * x))|0xff000000; + fb_pixel_t c = (0xff << (8 * x)) | 0xff000000; x++; if (x > 3) x = 0; for (int i = 0; i < available / 4; i++) diff --git a/tools/pic2m2v.c b/tools/pic2m2v.c index 35a1db4..d68cf27 100644 --- a/tools/pic2m2v.c +++ b/tools/pic2m2v.c @@ -58,7 +58,7 @@ int main(int argc, char **argv) strcat(destname, fname); p = &destname[strlen("/var/cache/")]; while ((p = strchr(p, '/')) != NULL) - *p = '.'; + * p = '.'; strcat(destname, ".m2v"); /* ...then check if it exists already... */ if (stat(destname, &st) || (st.st_mtime != st2.st_mtime) || (st.st_size == 0)) @@ -69,7 +69,7 @@ int main(int argc, char **argv) printf("converting %s -> %s\n", fname, destname); /* it does not exist or has a different date, so call ffmpeg... */ sprintf(cmd, "ffmpeg -y -f mjpeg -i '%s' -s %s '%s' tm_mday; date = day - 32076 + - 1461 * (year + 4800 + (month - 14) / 12) / 4 + - 367 * (month - 2 - (month - 14) / 12 * 12) / 12 - - 3 * ((year + 4900 + (month - 14) / 12 ) / 100) / 4; + 1461 * (year + 4800 + (month - 14) / 12) / 4 + + 367 * (month - 2 - (month - 14) / 12 * 12) / 12 - + 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4; date += (t->tm_hour + 12.0) / 24.0; date += (t->tm_min) / 1440.0; @@ -85,7 +85,7 @@ double mod_julian_date(struct tm *t) void time_to_aotom(time_t t, char *dest) { /* from u-boot aotom */ - struct tm* tmp; + struct tm *tmp; tmp = localtime(&t); #if 0 /* this mjd stuff is totally useless: driver only uses dest[2] and dest[3]... */ @@ -147,7 +147,7 @@ int main(int argc, char **argv) } ret = 0; - while ((c = getopt (argc, argv, "gs:tw:Tl:L:P:S:B:i:I:p:")) != -1) + while ((c = getopt(argc, argv, "gs:tw:Tl:L:P:S:B:i:I:p:")) != -1) { switch (c) { @@ -165,7 +165,7 @@ int main(int argc, char **argv) t = atol(optarg); if (t == 0) t = time(NULL), - ret = set_aotom_time(fd, t); + ret = set_aotom_time(fd, t); break; case 't': ret = ioctl(fd, VFDGETTIME, &t); @@ -212,17 +212,17 @@ int main(int argc, char **argv) } tmp = gmtime(&t2); fprintf(stderr, "current time: %04d-%02d-%02d %02d:%02d:%02d\n", tmp->tm_year + 1900, - tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); tmp = gmtime(&t); fprintf(stderr, "wakeup time: %04d-%02d-%02d %02d:%02d:%02d\n", tmp->tm_year + 1900, - tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); ret = ioctl(fd, VFDSETPOWERONTIME, &t); break; case 'P': ret = ioctl(fd, VFDPOWEROFF); break; case 'p': - period = atoi(optarg)/10; + period = atoi(optarg) / 10; break; case 'l': /* LED on */ aotom.u.led.on = period; @@ -261,15 +261,19 @@ int main(int argc, char **argv) case 'S': if (2 == sscanf(optarg, "%d:%lx", &aotom.u.key.key_nr, (long unsigned int *) &aotom.u.key.key)) ioctl(fd, VFDSETSTBYKEY, &aotom); - if (1 == sscanf(optarg, "%d", &aotom.u.key.key_nr)) { + if (1 == sscanf(optarg, "%d", &aotom.u.key.key_nr)) + { ret = ioctl(fd, VFDGETSTBYKEY, &aotom); if (ret) perror("ioctl VFDGETSTBYKEY"); else fprintf(stderr, "stby key %d = %.8x\n", aotom.u.key.key_nr, aotom.u.key.key); - } else { + } + else + { aotom.u.key.key_nr = 0; - while(aotom.u.key.key_nr < 5) { + while (aotom.u.key.key_nr < 5) + { ret = ioctl(fd, VFDGETSTBYKEY, &aotom); if (ret) perror("ioctl VFDGETSTBYKEY"); @@ -282,15 +286,19 @@ int main(int argc, char **argv) case 'B': if (2 == sscanf(optarg, "%d:%lx", &aotom.u.key.key_nr, (long unsigned int *) &aotom.u.key.key)) ioctl(fd, VFDSETBLUEKEY, &aotom); - if (1 == sscanf(optarg, "%d", &aotom.u.key.key_nr)) { + if (1 == sscanf(optarg, "%d", &aotom.u.key.key_nr)) + { ret = ioctl(fd, VFDGETBLUEKEY, &aotom); if (ret) perror("ioctl VFDGETBLUEKEY"); else fprintf(stderr, "blue key %d = %.8x\n", aotom.u.key.key_nr, aotom.u.key.key); - } else { + } + else + { aotom.u.key.key_nr = 0; - while(aotom.u.key.key_nr < 5) { + while (aotom.u.key.key_nr < 5) + { ret = ioctl(fd, VFDGETBLUEKEY, &aotom); if (ret) perror("ioctl VFDGETBLUEKEY");