monitor_pcr.cpp
2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <string.h>
#include <locale>
#include "monitor_pcr.h"
#define PCRBASE_PADRAO 1000000
using namespace std;
MonitorPCR::MonitorPCR(){
pcr_base = 0;
find = false;
extvideo = (char*) "";
listeners = new list<ListenerMonitorPCRBase*>();
DPRINTF("Done!\n");
}
MonitorPCR::~MonitorPCR(){
DDDPRINTF("Monitor PCR finalized!\n");
}
uint64_t MonitorPCR::getPCRBase(){
return pcr_base;
}
void MonitorPCR::setFormatVideo(char* format) {
extvideo = format;
}
void MonitorPCR::chegouInput(unsigned char* packet) {
if (!find) { // verifica se o PCRBase já foi encontrado
*extvideo = tolower(*extvideo);
if (strcmp(extvideo, (char*) "ts") == 0) { // se for TS procura nos pacotes
readPCRBase(packet);
} else { // outros formatos de vídeo, define o PCR padrão = 1000000
notifyListenersWithPCRBase((uint64_t) PCRBASE_PADRAO);
find = true;
}
}
}
void MonitorPCR::readPCRBase(unsigned char* packet){
if (packet[0] == 0x47 && !find){
if((((packet[1] & 0x1F) << 8) | packet[2]) != 0xFF) {
int adaptation_field_control = ((packet[3] & 0x30) >> 4);
if (adaptation_field_control == 2 || adaptation_field_control == 3) {
int adaptation_field_length = packet[4];
if (adaptation_field_length > 0) {
if (((packet[5] & 0x10) >> 4) == 1) {
uint64_t program_clock_reference_base = (uint64_t) packet[6] << 25 | packet[7] << 17 | packet[8] << 9
| packet[9] << 1 | (packet[10] & 0x80) >> 7;
notifyListenersWithPCRBase(program_clock_reference_base);
find = true;
}
}
}
}
}
}
void MonitorPCR::addListenerPCRBase(ListenerMonitorPCRBase * listener){
this->listeners->push_back(listener);
}
void MonitorPCR::notifyListenersWithPCRBase(uint64_t pcrbase){
for(list<ListenerMonitorPCRBase*>::iterator it = this->listeners->begin(); it != this->listeners->end(); it++){
(*it)->notifyPCRBase(pcrbase);
}
}