filter.cpp 3.23 KB
/*
 * Filter.cpp
 *
 *  Created on: 08/10/2008
 *      Author: lacet
 */

#include "filter.h"
#include "packet.h"
#include "section_hal.h"

#include <stdio.h>
#include <string.h>
#include "util.h"

int sectionSizee;

Filter::Filter(int FilterPID, int FilterTID, int FilterTIDx) {
	// TODO Auto-generated constructor stub
	this->setFilterPid(FilterPID);
	this->setFilterTid(FilterTID);
	this->setFilterTidx(FilterTIDx);
	this->setLastSectionCRC(0);
	this->setCrcErrorCount(0);
}

Filter::Filter() {

}

Filter::~Filter() {
	// TODO Auto-generated destructor stub
}

int Filter::isValid(unsigned char *section, Packet* myPacket, DemuxListener* listener) {
	static utils::Util util;

	if (getFilterTidx() == -1) {
		//printf("->2\n");
		if (section[0] == this->getFilterTid()) {
			//printf("->3\n");
			if (checkCRC32(section)) {
				if (getSectionCRC(section) != this->getLastSectionCRC()) {
					this->setLastSectionCRC(getSectionCRC(section));
					return 1;
				} else {
					//Old Version Of Section
					/*analisadorSI*/listener->notifyOldSection(myPacket->getPid(), getTid(
							section), getTidX(section));
					if (getTid(section) == 80) {
						int a = util.getBits(section, 0, 48, 8);
						if (a == 48) {
							//printf("\nOld Section\n");
						}
					}
					return 0;
				}
			} else {
				//return 0;
				this->setCrcErrorCount(this->getCrcErrorCount() + 1);
				cout << "\nERRO DE CRC no PID " << myPacket->getPid() << endl;

      				sectionSizee = getSectionSize(section);
     
				listener->notifyErroCRC(this->getCrcErrorCount(),
						myPacket->getPid(), getTid(section), getTidX(section),
						section, sectionSizee);

				//return 1;
				return 0;
			}

		} else {
	
			return 0;
		}
	} else {
	
		if ((section[0] == this->getFilterTid()) && (getIntAtBits(section, 24,
				16) == this->getFilterTidx())) {
			if (checkCRC32(section)) {
				if (getSectionCRC(section) != this->getLastSectionCRC()) {
					this->setLastSectionCRC(getSectionCRC(section));
					return 1;
				} else {
					//Old Version Of Section
					/*analisadorSI*/listener->notifyOldSection(myPacket->getPid(), getTid(
							section), getTidX(section));
					return 0;
				}
			} else {
				this->setCrcErrorCount(this->getCrcErrorCount() + 1);
				sectionSizee = getSectionSize(section);
				/*analisadorSI*/listener->notifyErroCRC(this->getCrcErrorCount(),
						myPacket->getPid(), getTid(section), getTidX(section),
						section, sectionSizee);
				cout << "\nERRO DE CRC no PID " << myPacket->getPid() << endl;
                              
				return 0;
			}
		} else {
			//printf("->6");
			return 0;
		}
	}
}

void Filter::setLastSectionCRC(int lastSectionCRC) {
	this->lastSectionCRC = lastSectionCRC;
}

void Filter::setFilterPid(int FilterPID) {
	this->FilterPID = FilterPID;
}

void Filter::setFilterTid(int FilterTID) {
	this->FilterTID = FilterTID;
}

void Filter::setFilterTidx(int FilterTIDx) {
	this->FilterTIDx = FilterTIDx;
}

void Filter::setCrcErrorCount(int crcErrorCount) {
	this->crcErrorCount = crcErrorCount;
}

int Filter::getCrcErrorCount() {
	return crcErrorCount;
}

int Filter::getLastSectionCRC() {
	return lastSectionCRC;
}

int Filter::getFilterPid() {
	return FilterPID;
}

int Filter::getFilterTid() {
	return FilterTID;
}

int Filter::getFilterTidx() {
	return FilterTIDx;
}