int main (int argc, char** argv) { int i; uint32_t j; //uint32_t k; uint64_t ii; int bouquet = -1; unsigned int channel = 0; unsigned int count; int diseqcRepeats = -1; int diseqcType = -1; uint64_t satmask = 0xFFFF; int audio = 0; int mute = -1; int volume = -1; int nvod = -1; int arat = -1; int m43 = -1; int lockrc = -1; const char * channelName = NULL; bool playback = false; bool recordmode = false; bool radio = false; bool reload = false; bool register_neutrino = false; bool savebouquets = false; bool show_satellites = false; bool set_pal = false; int set_hd = 0; bool scan = false; bool rezap = false; bool zapByName = false; bool killzapit = false; bool enterStandby = false; bool leaveStandby = false; bool sendMotorCommand = false; bool quiet = false; bool getchannel = false; bool aspectratio = false; bool mode43 = false; uint8_t motorCmdType = 0; uint8_t motorCmd = 0; uint8_t motorNumParameters = 0; uint8_t motorParam1 = 0; uint8_t motorParam2 = 0; uint8_t motorAddr = 0; uint32_t diseqc[5]; unsigned int tmp; int scan_mode = 1; t_channel_id zapsid = 0; /* command line */ for (i = 1; i < argc; i++) { if (!strncmp(argv[i], "-a", 2)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &audio); continue; } } else if (!strncmp(argv[i], "-dr", 3)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &diseqcRepeats); continue; } } else if (!strncmp(argv[i], "-dt", 3)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &diseqcType); continue; } } else if (!strncmp(argv[i], "-q", 2)) { quiet = true; continue; } else if (!strncmp(argv[i], "-c", 2)) { reload = true; continue; } else if (!strncmp(argv[i], "-esb", 4)) { enterStandby = true; continue; } else if (!strncmp(argv[i], "-kill", 5)) { killzapit = true; continue; } else if (!strncmp(argv[i], "-lsb", 4)) { leaveStandby = true; continue; } else if (!strncmp(argv[i], "-rz", 3)) { rezap = true; continue; } else if (!strncmp(argv[i], "-mute", 5)) { mute = 1; continue; } else if (!strncmp(argv[i], "-m", 2)) { if (i < argc - 6) { sscanf(argv[++i], "%x", &tmp); motorCmdType = tmp; sscanf(argv[++i], "%x", &tmp); motorAddr = tmp; sscanf(argv[++i], "%x", &tmp); motorCmd = tmp; sscanf(argv[++i], "%x", &tmp); motorNumParameters = tmp; sscanf(argv[++i], "%x", &tmp); motorParam1 = tmp; sscanf(argv[++i], "%x", &tmp); motorParam2 = tmp; printf("[pzapit] motor command = %x %x %x %x %x %x\n", motorCmdType, motorAddr, motorCmd, motorNumParameters, motorParam1, motorParam2); sendMotorCommand = true; continue; } } else if (!strncmp(argv[i], "-rn", 3)) { register_neutrino = true; continue; } else if (!strncmp(argv[i], "-nvod", 5)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &nvod); continue; } } else if (!strncmp(argv[i], "-n", 2)) { if (i < argc - 1) { zapByName = true; channelName = argv[++i]; continue; } } else if (!strncmp(argv[i], "-p", 2)) { playback = true; continue; } else if (!strncmp(argv[i], "-ra", 3)) { radio = true; continue; } else if (!strncmp(argv[i], "-re", 3)) { recordmode = true; continue; } else if (!strncmp(argv[i], "-var", 4)) { aspectratio = true; if (i < argc - 1) sscanf(argv[++i], "%d", &arat); continue; } else if (!strncmp(argv[i], "-vm43", 5)) { mode43 = true; if (i < argc - 1) { sscanf(argv[++i], "%d", &m43); continue; } #if 0 //FIXME howto read aspect mode back? continue; #endif } else if (!strncmp(argv[i], "-sb", 3)) { savebouquets = true; continue; } else if (!strncmp(argv[i], "-se", 3)) { if (i < argc - 2) { sscanf(argv[++i], "%" SCNd64 "", &satmask); sscanf(argv[++i], "%d", &diseqc[0]); /* diseqc[0] = strlen(argv[i+1]); for (i++, j = 0; j <= diseqc[0]; j++) { diseqc[j+1] = argv[i][j] - 48; } */ continue; } } else if (!strncmp(argv[i], "-sh", 3)) { show_satellites = true; continue; } else if (!strncmp(argv[i], "-st", 3)) { scan = true; if (i < argc - 1) { sscanf(argv[++i], "%d", &scan_mode); } continue; } else if (!strncmp(argv[i], "--pal", 4)) { set_pal = true; continue; } else if (!strncmp(argv[i], "--1080", 6)) { set_hd = 8; continue; } else if (!strncmp(argv[i], "--1083", 6)) { set_hd = 9; continue; } else if (!strncmp(argv[i], "--1082", 6)) { set_hd = 10; continue; } else if (!strncmp(argv[i], "--720", 5)) { set_hd = 7; continue; } else if (!strncmp(argv[i], "-unmute", 7)) { mute = 0; continue; } else if (!strncmp(argv[i], "-vol", 4)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &volume); continue; } } else if (!strncmp(argv[i], "-gi", 3)) { getchannel = true; continue; } else if (!strncmp(argv[i], "-zi", 3)) { if (i < argc - 1) { sscanf(argv[++i], "%" SCNx64 "", &zapsid); continue; } } else if (!strncmp(argv[i], "-lockrc", 7)) { lockrc = 1; continue; } else if (!strncmp(argv[i], "-unlockrc", 9)) { lockrc = 0; continue; } else if (i < argc - 1) { if ((sscanf(argv[i], "%d", &bouquet) > 0) && (sscanf(argv[++i], "%u", &channel) > 0)) continue; } else if (sscanf(argv[i], "%d", &bouquet) > 0) continue; return usage(argv[0]); } /* create zapit client */ CZapitClient zapit; #if 0 TP_params TP; TP.TP_id = 12345; TP.polarization = 1; TP.feparams.Frequency = 11727000; TP.feparams.u.qpsk.SymbolRate = 27500000; TP.feparams.u.qpsk.FEC_inner = (CodeRate) 3; zapit.scan_TP(TP); exit(0); #endif /* send diseqc 1.2 motor command */ if (sendMotorCommand) { zapit.sendMotorCommand(motorCmdType, motorAddr, motorCmd, motorNumParameters, motorParam1, motorParam2); return 0; } /* kill zapit*/ if (killzapit) { zapit.shutdown(); std::cout << "zapit shot down :)" << std::endl; return 0; } if (enterStandby) { zapit.setStandby(true); return 0; } if (leaveStandby) { zapit.setStandby(false); return 0; } /* audio mute */ if (mute != -1) { std::cout << "mute/unmute" << std::endl; zapit.muteAudio(mute); return 0; } if (volume != -1) { std::cout << "set volume" << std::endl; zapit.setVolume(volume, volume); return 0; } if (lockrc != -1) { zapit.lockRc(lockrc); return 0; } if (rezap) { zapit.Rezap(); return 0; } /* reload services */ if (reload) { std::cout << "reloading channels" << std::endl; zapit.reinitChannels(); return 0; } if (register_neutrino) { #define NEUTRINO_UDS_NAME "/tmp/neutrino.sock" std::cout << "registering neutrino" << std::endl; for (int ic = CZapitClient::FIRST_EVENT_MARKER; ic < CZapitClient::LAST_EVENT_MARKER; ic++) zapit.registerEvent(ic, 222, NEUTRINO_UDS_NAME); return 0; } if (diseqcType != -1) { zapit.setDiseqcType((diseqc_t) diseqcType); if (diseqcRepeats == -1) return 0; } if (diseqcRepeats != -1) { zapit.setDiseqcRepeat(diseqcRepeats); return 0; } if (playback) { if (zapit.isPlayBackActive()) zapit.stopPlayBack(); else zapit.startPlayBack(); if (!recordmode) return 0; } if (recordmode) { zapit.setRecordMode(!zapit.isRecordModeActive()); return 0; } if (aspectratio) { if(arat >= 0) zapit.setAspectRatio(arat); else { zapit.getAspectRatio(&arat); printf("%d\n", arat); } return 0; } if (mode43) { if(m43 >= 0) zapit.setMode43(m43); else { zapit.getMode43(&m43); printf("%d\n",m43); } return 0; } if (savebouquets) { zapit.saveBouquets(); return 0; } if (show_satellites) { std::vector<CZapitClient::responseGetSatelliteList> satelliteList; zapit.getScanSatelliteList(satelliteList); std::vector<CZapitClient::responseGetSatelliteList>::const_iterator rI; for ( ii = 0, rI = satelliteList.begin(); rI != satelliteList.end(); ii++, rI++) printf("%" PRId64 " : %s %d\n", ii, rI->satName, rI->satPosition); //std::cout << (1 << ii) << ": " << rI->satName << std::endl; return 0; } else if (satmask != 0xFFFF) { std::vector<CZapitClient::responseGetSatelliteList> satelliteList; zapit.getScanSatelliteList(satelliteList); std::vector<CZapitClient::commandSetScanSatelliteList> newSatelliteList; CZapitClient::commandSetScanSatelliteList item; for (j = 0; j < satelliteList.size(); j++) { if (satmask == j) { std::cout << "diseqc " << diseqc[0] << ": " << satelliteList[j].satName << std::endl; cstrncpy(item.satName, satelliteList[j].satName, sizeof(item.satName) - 1); item.position = diseqc[0]; newSatelliteList.push_back(item); break; } } zapit.setScanSatelliteList(newSatelliteList); return 0; } /* transponderscan */ if (scan) { unsigned int satellite; unsigned int processed_transponder; unsigned int transponder; unsigned int services; printf("Start scan, mode %d\n", scan_mode); zapit.startScan(scan_mode); while (zapit.isScanReady(satellite, processed_transponder, transponder, services) == false) { std::cout << "satellite: " << satellite << ", transponder: " << processed_transponder <<", of: " << transponder << ", services: " << services << std::endl; sleep(1); } return 0; } if (set_pal) { //zapit.stopPlayBack(); zapit.setVideoSystem(2); //zapit.startPlayBack(); return 0; } if (set_hd) { //zapit.stopPlayBack(); zapit.setVideoSystem(set_hd); //zapit.startPlayBack(); return 0; } if (getchannel) { t_channel_id channelid = zapit.getCurrentServiceID(); printf("%" PRIx64 " (%s)\n", channelid, (zapit.getChannelName(channelid)).c_str()); return 0; } /* choose source mode */ zapit.setMode(radio ? CZapitClient::MODE_RADIO : CZapitClient::MODE_TV); if (zapsid > 0) { printf("Zapping to: %" PRIx64 " (%s) ", zapsid, (zapit.getChannelName(zapsid)).c_str()); tmp = zapit.zapTo_serviceID(zapsid); if (!tmp) printf("failed"); printf("\n"); return tmp; } /* set audio channel */ if (audio) { zapit.setAudioChannel(audio - 1); return 0; } if (nvod != -1) { zapit.zaptoNvodSubService(nvod); return 0; } else { std::vector<CZapitClient::responseGetBouquetChannels> channels; if (zapByName) { zapit.getChannels(channels); std::vector<CZapitClient::responseGetBouquetChannels>::const_iterator ch_resp; for (ch_resp = channels.begin(), channel = 1; ch_resp != channels.end(); ch_resp++, ++channel) { if (!strcasecmp(ch_resp->name, channelName)) { std::cout << "found channel number: " << channel << std::endl; goto channel_found; } } std::cout << "channel not found." << std::endl; return 0; } else /* zap by bouquet number and channel number */ { /* read channel list */ if (bouquet != -1) zapit.getBouquetChannels(bouquet - 1, channels, CZapitClient::MODE_CURRENT, true); /* display bouquet list */ else { std::vector<CZapitClient::responseGetBouquets> bouquets; std::vector<CZapitClient::responseGetBouquets>::const_iterator b_resp; zapit.getBouquets(bouquets, false); for (b_resp = bouquets.begin(); b_resp != bouquets.end(); ++b_resp) std::cout << (b_resp->bouquet_nr + 1) << ": " << b_resp->name << std::endl; return 0; } /* display channel list */ if (!channel) { std::vector<CZapitClient::responseGetBouquetChannels>::const_iterator ch_resp; for (ch_resp = channels.begin(), channel = 1; ch_resp != channels.end(); ch_resp++, ++channel) //std::cout << channel << ": " << ch_resp->name << ": " << ch_resp->channel_id<< std::endl; printf("%3d: %s (%04x)\n", channel, ch_resp->name, (short) (ch_resp->channel_id &0xFFFF)); return 0; } } /* zap */ if (channel > channels.size()) { std::cout << "Only " << channels.size() << " channels in bouquet " << bouquet << std::endl; return 0; } channel_found: zapit.zapTo(channels[channel-1].nr); std::cout << "zapped to " << channels[channel-1].name << std::endl; } if (!quiet) { CZapitClient::responseGetPIDs pids; zapit.getPIDS(pids); if (pids.PIDs.vpid) std::cout << " video: 0x" << std::hex << pids.PIDs.vpid << std::endl; if (pids.PIDs.vtxtpid) std::cout << "teletext: 0x" << std::hex << pids.PIDs.vtxtpid << std::endl; if (pids.PIDs.pcrpid) std::cout << " pcr: 0x" << std::hex << pids.PIDs.pcrpid << std::endl; for (count = 0; count < pids.APIDs.size(); count++) { std::cout << " audio " << std::dec << count + 1 << ": 0x" << std::hex << pids.APIDs[count].pid << " (" << pids.APIDs[count].desc; if (pids.APIDs[count].is_ac3) std::cout << ", ac3"; else if (pids.APIDs[count].is_aac) std::cout << ", aac"; else std::cout << ", unknown"; std::cout << ")" << std::endl; } } return 0; }
int main () { unsigned Bouquet; unsigned Channel; unsigned BufNum; int RadioMode; int ExtraPidNum; unsigned ExtraPid[MAX_PID_NUM]; unsigned StoppedDmxReaders, EmptyStreamBuffers; char CmdString[100]; char TcpString[STRING_SIZE]; pthread_t TcpReceiverThread; //pthread_attr_t ThreadAttr; //struct sched_param SchedParam; int RetVal, i; unsigned u, v; mainProcessID = getpid(); // **************************************************** // * INIT // **************************************************** // * - Programm umschalten // * - PID's ermitteln // * - IP-Adresse, Port, MTU ermitteln // **************************************************** // Eingabe parsen ReadLine( TcpString ); RetVal = sscanf( TcpString, "%s %u %u %u %u %s %x %x %x %x %x %x %x %x %x", CmdString, &(Send.Port), &BufNum, &Bouquet, &Channel, ExtraAVString, &(ExtraPid[0]), &(ExtraPid[1]), &(ExtraPid[2]), &(ExtraPid[3]), &(ExtraPid[4]), &(ExtraPid[5]), &(ExtraPid[6]), &(ExtraPid[7]), &(ExtraPid[8]) ); if ( RetVal < 4 || RetVal > 12 || Send.Port <= 1023 ) { fprintf(stderr, "ERROR: main() - illegal arguments\nEXIT\n"); fflush(stderr); exit(-1); } ExtraPidNum = RetVal-6; // -1 => keine zus. PID's (wg. AVString) if ( BufNum > MAX_SPKT_BUF_NUM || BufNum < 5 ) { fprintf(stderr, "ERROR: main() - BufNum too large/small\nEXIT\n"); fflush(stderr); exit(-1); } for (u=0; u<BufNum-1; u++) NextSPktBuf[u] = u+1; NextSPktBuf[BufNum-1] = 0; if (!strcmp(CmdString, "VIDEO")) { RadioMode = 0; TSMode = 0; } else if (!strcmp(CmdString, "VIDEOTS")) { RadioMode = 0; TSMode = 1; } else if (!strcmp(CmdString, "AUDIO")) { RadioMode = 1; TSMode = 0; } else if (!strcmp(CmdString, "AUDIOTS")) { RadioMode = 1; TSMode = 1; } else { fprintf(stderr, "ERROR: main() - illegal command\nEXIT\n"); fflush(stderr); exit(-1); } StreamNum = 0; if ( Bouquet != 0 ) { CZapitClient zapit; // Programm umschalten CZapitClient::responseGetPIDs pids; if (RadioMode) { zapit.setMode(CZapitClient::MODE_RADIO); } else { zapit.setMode(CZapitClient::MODE_TV); } zapit.zapTo(Bouquet-1,Channel); zapit.getPIDS(pids); // Pid's ermitteln if (pids.PIDs.vpid) { Stream[StreamNum].Filter.pid = pids.PIDs.vpid; AVString[StreamNum] = 'v'; Stream[StreamNum++].BufPacketNum = AV_BUF_FACTOR * AUDIO_BUF_PACKET_NUM; } for ( u=0; u<pids.APIDs.size(); u++) { Stream[StreamNum].Filter.pid = pids.APIDs[u].pid; AVString[StreamNum] = 'a'; Stream[StreamNum++].BufPacketNum = AUDIO_BUF_PACKET_NUM; } /* if (TSMode) { // PMT-Pid wird benotigt nicht ServiceID!! //Stream[StreamNum].Filter.pid = zapit.getCurrentServiceID(); //AVString[StreamNum] = 'a'; //Stream[StreamNum++].BufPacketNum = AUDIO_BUF_PACKET_NUM; //zapit.stopPlayBack(); // TS-Streaming geht nur im SPTS-Mode mit Playback! // sonst ist der Stream "nicht richtig gemuxt" }*/ } //if (TSMode) { // Stream[StreamNum].Filter.pid = 0; // AVString[StreamNum] = 'a'; // Stream[StreamNum++].BufPacketNum = AUDIO_BUF_PACKET_NUM; //} for ( i=0; i<ExtraPidNum; i++) { Stream[StreamNum].Filter.pid = ExtraPid[i]; switch( ExtraAVString[i] ) { case 'v': AVString[StreamNum] = 'v'; Stream[StreamNum++].BufPacketNum = AV_BUF_FACTOR * AUDIO_BUF_PACKET_NUM; break; case 'a': AVString[StreamNum] = 'a'; Stream[StreamNum++].BufPacketNum = AUDIO_BUF_PACKET_NUM; break; default: fprintf(stderr, "ERROR: main() - illegal extra AV string \n"); fflush(stderr); break; } } if (StreamNum == 0) { fprintf(stderr, "ERROR: main() - no pids to record\nEXIT\n"); fflush(stderr); exit(-1); } AVString[StreamNum] = 0; if (TSMode) { StreamThreadNum = 1; Stream[0].BufPacketNum = 188; } else { StreamThreadNum = StreamNum; } // Adresse fuer Send.Socket ermitteln Send.AddrLen = sizeof(struct sockaddr_in); if ( -1 == getpeername(STDIN_FILENO, (struct sockaddr *)&(Send.Addr), &(Send.AddrLen)) ) { perror("ERROR: main() - getpeername"); fprintf(stderr, "EXIT\n"); fflush(stderr); exit(-1); } Send.Addr.sin_family = AF_INET; Send.Addr.sin_port = htons( (unsigned short)(Send.Port) ); printf("INFO: IP %x Port %u\n", Send.Addr.sin_addr.s_addr, Send.Port); fflush(stdout); // Antwort an Client printf("PID %s %i", AVString, StreamThreadNum); for (u=0; u<StreamNum; u++) printf(" %x", Stream[u].Filter.pid); printf("\n"); fflush(stdout); // START-Befehl abwarten ReadLine( TcpString ); if ( !strncmp(TcpString, "STOP", 4) ) { // ZapMode printf("INFO: zap mode\nEXIT\n" ); fflush(stdout); exit(0); } else if ( strncmp(TcpString, "START", 5) ) { fprintf(stderr, "ERROR: main() - START command expected\nEXIT\n"); fflush(stderr); exit(-1); } // ***************************************************** // * Start streaming // ***************************************************** // Super Packet Buffer initialisieren for (u=0; u<BufNum; u++) { SPkt.ReSendStatus[u] = 0; SPkt.Buf[u] = (unsigned char*) malloc( SPKT_BUF_SIZE ); if ( SPkt.Buf[u] == 0 ) { fprintf(stderr, "ERROR: main() - malloc SPkt.Buf\nEXIT\n"); fflush(stderr); exit(-1); } } SPkt.WritePkt = 0; SPkt.WriteBuf = 0; SPkt.ReadPkt = 0; SPkt.ReadBuf = 0; // UdpSender einrichten Send.Socket = -1; Send.Packet = 0; RestartUdpSender(); // DmxReader vorbereiten StreamStop = 0; for (u=0; u<StreamThreadNum; u++) { Stream[u].ReadBuf = 0; Stream[u].WriteBuf = 0; Stream[u].ReadPkt = 0; Stream[u].Stopped = 0; Stream[u].Ptr = (void*)&(Stream[u]); for( v=0; v<2; v++) { Stream[u].Buf[v] = (unsigned char*)malloc( Stream[u].BufPacketNum * NET_DATA_PER_PACKET ); if ( Stream[u].Buf[v] == 0 ) { fprintf(stderr, "ERROR: main() - malloc Stream.Buf\nEXIT\n"); fflush(stderr); exit(-1); } } } // Tcp Receiver starten -> STOP, RESEND Befehle auswerten if ( pthread_create(&TcpReceiverThread, 0, TcpReceiver, 0 ) ) { perror("ERROR: main() - TcpReceiver pthread_create"); fprintf(stderr, "EXIT\n"); fflush(stderr); exit(-1); } //SchedParam.sched_priority = 10; //pthread_attr_init(&ThreadAttr); //pthread_attr_setschedpolicy(&ThreadAttr, SCHED_FIFO ); //pthread_attr_setschedparam(&ThreadAttr, &SchedParam); // DmxReader Thread's starten if (TSMode) { if ( pthread_create(&(Stream[u].Thread), 0, //&ThreadAttr, DmxTSReader, 0 ) ) { perror("ERROR: main() - DmxReader pthread_create"); fprintf(stderr, "EXIT\n"); fflush(stderr); exit(-1); } } else { for (u=0; u<StreamThreadNum; u++) { if ( pthread_create(&(Stream[u].Thread), 0, //&ThreadAttr, DmxReader, Stream[u].Ptr ) ) { perror("ERROR: main() - DmxReader pthread_create"); fprintf(stderr, "EXIT\n"); fflush(stderr); exit(-1); } } } // **************************************************************** // Hauptschleife // ============================================================== // Pakete von den DmxBuf's in SPktBuf's umkopieren und // Headern versehen // **************************************************************** StoppedDmxReaders = 0; do { WritePtr = SPkt.Buf[SPkt.WriteBuf] + SPkt.WritePkt * DATA_PER_PACKET; for (u=0; u<BufNum; u++) { if ( SPkt.ReSendStatus) { for (v=0; v<SPKT_BUF_PACKET_NUM; v++) { if ( SPkt.ReSend[u][v] ) { ReadPtr = SPkt.Buf[u] + v * DATA_PER_PACKET; memmove ( WritePtr, ReadPtr, DATA_PER_PACKET ); PacketHeader = (PacketHeaderType*)WritePtr; PacketHeader->Packet = SPkt.WritePkt++; PacketHeader->Status = 0; PacketHeader->SPktBuf = SPkt.WriteBuf; WritePtr += DATA_PER_PACKET; CheckNextSPktWriteBuf( ); } SPkt.ReSend[u][v] = 0; } } } EmptyStreamBuffers = 0; do { for(u=0; u<StreamThreadNum; u++) { if ( Stream[u].Stopped ) { StoppedDmxReaders++; EmptyStreamBuffers++; continue; } if ( Stream[u].WriteBuf != Stream[u].ReadBuf ) { ReadPtr = Stream[u].Buf[Stream[u].ReadBuf]; for (v=0; v<Stream[u].BufPacketNum; v++) { PacketHeader = (PacketHeaderType*)WritePtr; PacketHeader->Packet = SPkt.WritePkt++; PacketHeader->Status = 0; PacketHeader->SPktBuf = SPkt.WriteBuf; PacketHeader->Stream = u; PacketHeader->StreamPacket = Stream[u].ReadPkt++; WritePtr += sizeof(PacketHeaderType); memmove ( WritePtr, ReadPtr, NET_DATA_PER_PACKET ); ReadPtr += NET_DATA_PER_PACKET; WritePtr += NET_DATA_PER_PACKET; CheckNextSPktWriteBuf( ); } if ( Stream[u].ReadBuf == 0 ) Stream[u].ReadBuf = 1; else Stream[u].ReadBuf = 0; } else { EmptyStreamBuffers++; } } } while ( EmptyStreamBuffers < StreamThreadNum ); usleep(15000); // 10% * 128 * 1468 * 8 / 10 MBit/s } while (StoppedDmxReaders < StreamThreadNum ); PacketHeader->Status = 2; SPkt.WriteBuf = NextSPktBuf[SPkt.WriteBuf]; StreamStop = 0; for (i=0; i<200; i++) { if ( StreamStop ) break; usleep(15000); } printf("EXIT\n" ); fflush(stdout); /* siehe stopPlayBack if (Bouquet != 0 && TSMode) { zapit.startPlayBack(); } */ exit(0); }
int main (int argc, char** argv) { int i; uint32_t j; uint32_t k; int bouquet = -1; unsigned int channel = 0; unsigned int count; int diseqcRepeats = -1; int diseqcType = -1; int satmask = 0; int audio = 0; int mute = -1; int volume = -1; int nvod = -1; int fastzap = -1; t_channel_id zapsid = 0; const char * channelName = NULL; bool playback = false; bool recordmode = false; bool radio = false; bool reload = false; bool register_neutrino = false; bool savebouquets = false; bool show_satellites = false; bool set_pal = false; bool set_ntsc = false; bool scan = false; bool zapByName = false; bool rezap = false; bool killzapit = false; bool savezapit = false; bool enterStandby = false; bool leaveStandby = false; bool sendMotorCommand = false; #ifdef HAVE_DBOX_HARDWARE bool Iecon = false; bool Iecoff = false; bool Iecstate = false; bool pes = false; bool spts = false; bool decmode = false; #endif #ifdef HAVE_TRIPLEDRAGON bool zoom = false; int zoomlevel = 0; bool pig = false; bool avinfo = false; int pig_x = 0; int pig_y = 0; int pig_w = 0; int pig_h = 0; int pig_a = 0; #endif bool getchannel = false; bool getmode = false; bool getpids = false; bool includeBouquetOthers = false; bool getserviceinfo = false; uint8_t motorCmdType = 0; uint8_t motorCmd = 0; uint8_t motorNumParameters = 0; uint8_t motorParam1 = 0; uint8_t motorParam2 = 0; uint8_t motorAddr = 0; uint32_t diseqc[5]; unsigned int tmp; /* command line */ for (i = 1; i < argc; i++) { if (!strncmp(argv[i], "-a", 2)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &audio); continue; } } else if (!strncmp(argv[i], "-dr", 3)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &diseqcRepeats); continue; } } else if (!strncmp(argv[i], "-dt", 3)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &diseqcType); continue; } } else if (!strncmp(argv[i], "-c", 2)) { reload = true; continue; } else if (!strncmp(argv[i], "-gm", 3)) { getmode = true; continue; } else if (!strncmp(argv[i], "-gi", 3)) { getchannel = true; continue; } else if (!strncmp(argv[i], "-rz", 3)) { rezap = true; continue; } else if (!strncmp(argv[i], "-zi", 3)) { if (i < argc - 1) { sscanf(argv[++i], "%llx", &zapsid); continue; } } else if (!strncmp(argv[i], "-esb", 4)) { enterStandby = true; continue; } else if (!strncmp(argv[i], "-kill", 5)) { killzapit = true; continue; } else if (!strncmp(argv[i], "-lsb", 4)) { leaveStandby = true; continue; } else if (!strncmp(argv[i], "-motor", 6)) { if (i < argc - 6) { sscanf(argv[++i], "%x", &tmp); motorCmdType = tmp; sscanf(argv[++i], "%x", &tmp); motorAddr = tmp; sscanf(argv[++i], "%x", &tmp); motorCmd = tmp; sscanf(argv[++i], "%x", &tmp); motorNumParameters = tmp; sscanf(argv[++i], "%x", &tmp); motorParam1 = tmp; sscanf(argv[++i], "%x", &tmp); motorParam2 = tmp; printf("[pzapit] motor command = %x %x %x %x %x %x\n", motorCmdType, motorAddr, motorCmd, motorNumParameters, motorParam1, motorParam2); sendMotorCommand = true; continue; } } else if (!strncmp(argv[i], "-rn", 3)) { register_neutrino = true; continue; } else if (!strncmp(argv[i], "-mute", 5)) { mute = 1; continue; } else if (!strncmp(argv[i], "-nvod", 5)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &nvod); continue; } } else if (!strncmp(argv[i], "-n", 2)) { if (i < argc - 1) { zapByName = true; channelName = argv[++i]; continue; } } else if (!strncmp(argv[i], "-p", 2)) { playback = true; continue; } else if (!strncmp(argv[i], "-ra", 3)) { radio = true; continue; } else if (!strncmp(argv[i], "-re", 3)) { recordmode = true; continue; } // don't change order with "-sb" or the other will always be found first else if (!strncmp(argv[i], "-sbo", 4)) { savebouquets = true; includeBouquetOthers = true; continue; } else if (!strncmp(argv[i], "-sb", 3)) { savebouquets = true; continue; } else if (!strncmp(argv[i], "-se", 3)) { if (i < argc - 2) { sscanf(argv[++i], "%d", &satmask); diseqc[0] = strlen(argv[i+1]); for (i++, j = 0; j <= diseqc[0]; j++) { diseqc[j+1] = argv[i][j] - 48; } continue; } } else if (!strncmp(argv[i], "-sh", 3)) { show_satellites = true; continue; } else if (!strncmp(argv[i], "-st", 3)) { scan = true; continue; } else if (!strncmp(argv[i], "--pal", 4)) { set_pal = true; continue; } else if (!strncmp(argv[i], "--ntsc", 5)) { set_ntsc = true; continue; } else if (!strncmp(argv[i], "-unmute", 7)) { mute = 0; continue; } #ifdef HAVE_DBOX_HARDWARE else if (!strncmp(argv[i], "--iecon", 7)) { Iecon = true; continue; } else if (!strncmp(argv[i], "--iecoff", 8)) { Iecoff = true; continue; } else if (!strncmp(argv[i], "--iecstate", 10)) { Iecstate = true; continue; } else if (!strncmp(argv[i], "--pes", 5)) { pes = true; continue; } else if (!strncmp(argv[i], "--spts", 6)) { spts = true; continue; } else if (!strncmp(argv[i], "--decmode", 9)) { decmode = true; continue; } #endif #ifdef HAVE_TRIPLEDRAGON else if (!strncmp(argv[i], "--zoom", 6)) { zoom = true; if (i < argc - 1) { sscanf(argv[++i], "%d", &zoomlevel); } continue; } else if (!strncmp(argv[i], "--pig", 5)) { pig = true; if (i < argc - 1) { sscanf(argv[++i], "%d", &pig_x); } if (i < argc - 1) { sscanf(argv[++i], "%d", &pig_y); } if (i < argc - 1) { sscanf(argv[++i], "%d", &pig_w); } if (i < argc - 1) { sscanf(argv[++i], "%d", &pig_h); } if (i < argc - 1) { sscanf(argv[++i], "%d", &pig_a); } continue; } else if (!strncmp(argv[i], "--avinfo", 6)) { avinfo = true; continue; } #endif else if (!strncmp(argv[i], "-vol", 4)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &volume); continue; } } else if (!strncmp(argv[i], "--fastzap", 9)) { if (i < argc - 1) { sscanf(argv[++i], "%d", &fastzap); continue; } } else if (!strncmp(argv[i], "--getpids", 9)) { getpids = true; continue; } else if (!strncmp(argv[i], "-gsi", 4)) { getserviceinfo = true; continue; } else if (!strncmp(argv[i], "-save", 5)) { savezapit = true; continue; } else if (i < argc - 1) { if ((sscanf(argv[i], "%d", &bouquet) > 0) && (sscanf(argv[++i], "%u", &channel) > 0)) continue; } else if (sscanf(argv[i], "%d", &bouquet) > 0) continue; return usage(argv[0]); } /* create zapit client */ CZapitClient zapit; /* send diseqc 1.2 motor command */ if (sendMotorCommand) { zapit.sendMotorCommand(motorCmdType, motorAddr, motorCmd, motorNumParameters, motorParam1, motorParam2); } /* kill zapit*/ if (killzapit) { zapit.shutdown(); std::cout << "zapit shot down :)" << std::endl; return 0; } if (enterStandby) { zapit.setStandby(true); return 0; } if (leaveStandby) { zapit.setStandby(false); return 0; } if (fastzap > -1) { zapit.setFastZap(fastzap != 0); return 0; } if (getmode) { int mode = zapit.getMode(); // 1 = TV, 2 = Radio std::cout << "Mode: " << mode; if (mode == CZapitClient::MODE_TV) std::cout << " (TV)" << std::endl; else if (mode == CZapitClient::MODE_RADIO) std::cout << " (Radio)" << std::endl; else std::cout << " (unknown!)" << std::endl; return mode; } if (getchannel) { int mode = zapit.getMode(); if (mode == CZapitClient::MODE_STANDBY) { std::cerr << "zapit is in standby mode, no channel active." << std::endl; return 1; } t_channel_id c = zapit.getCurrentServiceID(); printf("%llx (%s)\n", c, (zapit.getChannelName(c)).c_str()); return 0; } if (rezap) { zapit.ReZap(); return 0; } /* audio mute */ if (mute != -1) { std::cout << "mute/unmute" << std::endl; zapit.muteAudio(mute); return 0; } if (volume != -1) { std::cout << "set volume" << std::endl; zapit.setVolume(volume, volume); return 0; } #ifdef HAVE_DBOX_HARDWARE if (Iecon) { std::cout << "Iec on" << std::endl; zapit.IecOn(); return 0; } if (Iecoff) { std::cout << "Iec off" << std::endl; zapit.IecOff(); return 0; } if (Iecstate) { std::cout << "Iec state = " << zapit.IecState() << std::endl; return 0; } if (pes) { std::cout << "set decoder to PES mode" << std::endl; zapit.PlaybackPES(); return 0; } if (spts) { std::cout << "set decoder to SPTS mode" << std::endl; zapit.PlaybackSPTS(); return 0; } if (decmode) { std::cout << "decoder mode = " << zapit.PlaybackState() << std::endl; return 0; } #endif #ifdef HAVE_TRIPLEDRAGON if (zoom) { if (zoomlevel > 0) zapit.setZoom(zoomlevel); std::cout << "zoom = " << zapit.getZoom() << "%" << std::endl; return 0; } if (pig) { zapit.setPIG(pig_x, pig_y, pig_w, pig_h, !!pig_a); std::cout << "pig = " << pig_x << "." << pig_y << "." << pig_w << "." << pig_h << ":" << pig_a << std::endl; return 0; } if (avinfo) { AVInfo v = zapit.getAVInfo(); std::cout << "h_size = " << v.vinfo.h_size << " v_size = " << v.vinfo.v_size << " ar = " << v.vinfo.pel_aspect_ratio << " rate = " << v.vinfo.frame_rate << std::endl; printf("atype = %d astatus0 = 0x%08x astatus1 = 0x%08x\n", v.atype, v.astatus.word00, v.astatus.word01); return 0; } #endif /* reload services */ if (reload) { std::cout << "reloading channels" << std::endl; zapit.reinitChannels(); return 0; } if (register_neutrino) { #define NEUTRINO_UDS_NAME "/tmp/neutrino.sock" std::cout << "registering neutrino" << std::endl; for (i = CZapitClient::FIRST_EVENT_MARKER; i < CZapitClient::LAST_EVENT_MARKER; i++) zapit.registerEvent(i, 222, NEUTRINO_UDS_NAME); return 0; } if (diseqcType != -1) { zapit.setDiseqcType((diseqc_t) diseqcType); if (diseqcRepeats == -1) return 0; } if (diseqcRepeats != -1) { zapit.setDiseqcRepeat(diseqcRepeats); return 0; } if (playback) { if (zapit.isPlayBackActive()) zapit.stopPlayBack(); else zapit.startPlayBack(); if (!recordmode) return 0; } if (recordmode) { zapit.setRecordMode(!zapit.isRecordModeActive()); return 0; } if (savebouquets) { zapit.saveBouquets(includeBouquetOthers); return 0; } if (show_satellites) { std::vector<CZapitClient::responseGetSatelliteList> satelliteList; zapit.getScanSatelliteList(satelliteList); std::vector<CZapitClient::responseGetSatelliteList>::const_iterator rI; for (i = 0, rI = satelliteList.begin(); rI != satelliteList.end(); i++, rI++) std::cout << (1 + i) << ": " << rI->satName << std::endl; return 0; } else if (satmask != 0) { std::vector<CZapitClient::responseGetSatelliteList> satelliteList; zapit.getScanSatelliteList(satelliteList); std::vector<CZapitClient::commandSetScanSatelliteList> newSatelliteList; CZapitClient::commandSetScanSatelliteList item; for (i = 1, j = 0, k = 0; j < satelliteList.size(); i = (i << 1), k++) { if (satmask & i) { j++; std::cout << "diseqc " << diseqc[j] << ": " << satelliteList[k].satName << std::endl; strcpy(item.satName, satelliteList[k].satName); item.diseqc = diseqc[j]; newSatelliteList.push_back(item); } if ((j >= diseqc[0]) || (k >= satelliteList.size())) { break; } } zapit.setScanSatelliteList(newSatelliteList); return 0; } /* transponderscan */ if (scan) { unsigned int satellite; unsigned int processed_transponder; unsigned int transponder; unsigned int services; zapit.startScan(1); while (zapit.isScanReady(satellite, processed_transponder, transponder, services) == false) { std::cout << "satellite: " << satellite << ", transponder: " << processed_transponder <<", of: " << transponder << ", services: " << services << std::endl; sleep(1); } return 0; } if (set_pal) { zapit.stopPlayBack(); zapit.setVideoSystem_a(PAL); zapit.startPlayBack(); return 0; } if (set_ntsc) { zapit.stopPlayBack(); zapit.setVideoSystem_a(NTSC); zapit.startPlayBack(); return 0; } /* set audio channel */ if (audio) { zapit.setAudioChannel(audio - 1); return 0; } if (nvod != -1) { zapit.zaptoNvodSubService(nvod); return 0; } if (getpids) { CZapitClient::responseGetPIDs pids; zapit.getPIDS(pids); if (pids.PIDs.vpid) std::cout << " video: 0x" << std::hex << pids.PIDs.vpid << std::endl; if (pids.PIDs.ecmpid) std::cout << " ecmpid: 0x" << std::hex << pids.PIDs.ecmpid << std::endl; if (pids.PIDs.vtxtpid) std::cout << "teletext: 0x" << std::hex << pids.PIDs.vtxtpid << std::endl; if (pids.PIDs.pcrpid) std::cout << " pcr: 0x" << std::hex << pids.PIDs.pcrpid << std::endl; if (pids.PIDs.pmtpid) std::cout << " pmt: 0x" << std::hex << pids.PIDs.pmtpid << std::endl; if (pids.PIDs.privatepid) std::cout << " private: 0x" << std::hex << pids.PIDs.privatepid << std::endl; for (count = 0; count < pids.APIDs.size(); count++) { if (count == pids.PIDs.selected_apid) std::cout << "*"; else std::cout << " "; std::cout << "audio " << std::dec << count + 1 << ": 0x" << std::hex << pids.APIDs[count].pid << " (" << pids.APIDs[count].desc; if (pids.APIDs[count].is_ac3) std::cout << ", ac3"; std::cout << ")" << std::endl; } for (count = 0 ; count < pids.SubPIDs.size() ; count++) { if (pids.SubPIDs[count].pid != pids.PIDs.vtxtpid) { std::cout << "DVB-Sub " << std::dec << count + 1 << ": 0x" << std::hex << pids.SubPIDs[count].pid << " (" << pids.SubPIDs[count].desc << ")" << std::endl; } else { std::cout << "TTX-Sub " << std::dec << count + 1 << ": " << pids.SubPIDs[count].composition_page << " (" << pids.SubPIDs[count].desc << ")" << std::endl; } } return 0; } if (getserviceinfo) { CZapitClient::CCurrentServiceInfo si; si = zapit.getCurrentServiceInfo(); printf("frequency = %d.%d MHz", si.tsfrequency/1000, si.tsfrequency%1000); if (si.polarisation != 2) /* only satellite has polarisation */ { printf(" (%c)\n", (si.polarisation == HORIZONTAL) ? 'h' : 'v'); //satellite printf("diseqc = %d\n", si.diseqc); } else { printf("\n"); } printf("onid = 0x%04x\n", si.onid); printf("sid = 0x%04x\n", si.sid); printf("tsid = 0x%04x\n", si.tsid); printf("pmtpid = 0x%04x\n", si.pmtpid); printf("vpid = 0x%04x\n", si.vpid); printf("apid = 0x%04x\n", si.apid); printf("spid = 0x%04x\n", si.spid); printf("spage = 0x%04x\n", si.spage); printf("pcrpid = 0x%04x\n", si.pcrpid); printf("vtxtpid = 0x%04x\n", si.vtxtpid); return 0; } /* save zapit*/ if (savezapit) { zapit.saveSettings(); std::cout << "zapit settings saved" << std::endl; return 0; } /* if we got here, we want to zap by name, bouquet / number or onidsid */ /* choose source mode */ zapit.setMode(radio ? CZapitClient::MODE_RADIO : CZapitClient::MODE_TV); if (zapsid > 0) { printf("Zapping to: %llx (%s) ", zapsid, (zapit.getChannelName(zapsid)).c_str()); tmp = zapit.zapTo_serviceID(zapsid); if (!tmp) printf("failed"); printf("\n"); return tmp; } std::vector<CZapitClient::responseGetBouquetChannels> channels; if (zapByName) { zapit.getChannels(channels); std::vector<CZapitClient::responseGetBouquetChannels>::const_iterator ch_resp; for (ch_resp = channels.begin(), channel = 1; ch_resp != channels.end(); ch_resp++, channel++) { if (!strcasecmp(ch_resp->name, channelName)) { std::cout << "found channel number: " << channel << std::endl; goto channel_found; } } std::cout << "channel not found." << std::endl; return 0; } else /* zap by bouquet number and channel number */ { /* read channel list */ if (bouquet != -1) zapit.getBouquetChannels(bouquet - 1, channels); /* display bouquet list */ else { std::vector<CZapitClient::responseGetBouquets> bouquets; std::vector<CZapitClient::responseGetBouquets>::const_iterator b_resp; zapit.getBouquets(bouquets, false); for (b_resp = bouquets.begin(); b_resp != bouquets.end(); b_resp++) std::cout << (b_resp->bouquet_nr + 1) << ": " << b_resp->name << std::endl; return 0; } /* display channel list */ if (!channel) { std::vector<CZapitClient::responseGetBouquetChannels>::const_iterator ch_resp; for (ch_resp = channels.begin(), channel = 1; ch_resp != channels.end(); ch_resp++, channel++) std::cout << channel << ": " << ch_resp->name << std::endl; return 0; } } /* zap */ if (channel > channels.size()) { std::cout << "Only " << channels.size() << " channels in bouquet " << bouquet << std::endl; return 0; } channel_found: zapit.zapTo(channels[channel-1].nr); std::cout << "zapped to " << channels[channel-1].name << std::endl; return 0; }