monitor_pcr.cpp
2.38 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
77
78
79
80
81
#include <stdio.h>
#include <string.h>
#include "monitor_pcr.h"
#define PCRBASE_PADRAO 1000000
using namespace std;
MonitorPCR::MonitorPCR(){
pcr_base = 0;
find = false;
extvideo = (char*) "";
listeners = new list<ListenerMonitorPCRBase*>();
}
MonitorPCR::~MonitorPCR(){
}
uint64_t MonitorPCR::getPCRBase(){
return pcr_base;
}
void MonitorPCR::chegouInput(unsigned char* packet) {
//printf("\n\n\n\n\n\nEXTENSAOOO---2: %s\n\n\n\n\n\n", extvideo);
if (!find) { // verifica se o PCRBase já foi encontrado
//printf("\n>>> 2\n");
if (strcmp(extvideo, (char*) "ts") == 0) { // se for TS procura nos pacotes
readPCRBase(packet);
//printf("\n>>> 3\n");
}
else // outros formatos de vídeo, define o PCR padrão = 1000000
notifyListenersWithPCRBase((uint64_t) PCRBASE_PADRAO);
}
}
void MonitorPCR::readPCRBase(unsigned char* packet){
// printf("\n>>> 0\n");
if (packet[0] == 0x47 && !find){
//printf("\n>>> 1\n");
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;
printf("*** PCR Base: %lld\n", program_clock_reference_base);
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);
}
}