00001 #include <cmath>
00002
00003 #include "premieredescriptors.h"
00004 #include "dvbdescriptors.h"
00005
00006 bool PremiereContentTransmissionDescriptor::Parse(void)
00007 {
00008 _transmission_count = 0;
00009 _date_ptrs.clear();
00010 _time_ptrs.clear();
00011 const uint8_t *dataptr = _data + 8;
00012 while ((dataptr + 6) <= (_data + 2 + DescriptorLength()))
00013 {
00014 uint starttime_no = *(dataptr+2);
00015 for (uint i=0; i < starttime_no; i+=3)
00016 {
00017 _date_ptrs.push_back(dataptr);
00018 _time_ptrs.push_back(dataptr + 3 + i);
00019 _transmission_count++;
00020 }
00021 dataptr += 3 + starttime_no;
00022 }
00023 return true;
00024 }
00025
00026
00027 QDateTime PremiereContentTransmissionDescriptor::StartTimeUTC(uint index) const
00028 {
00029
00030 const uint8_t *buf = _date_ptrs[index];
00031 uint mjd = (buf[0] << 8) | buf[1];
00032
00033 buf = _time_ptrs[index]-2;
00034 if (mjd >= 40587)
00035 {
00036 QDateTime result;
00037
00038
00039 uint secsSince1970 = (mjd - 40587) * 86400;
00040 secsSince1970 += byteBCD2int(buf[2]) * 3600;
00041 secsSince1970 += byteBCD2int(buf[3]) * 60;
00042 secsSince1970 += byteBCD2int(buf[4]);
00043 result.setTime_t(secsSince1970);
00044 return result;
00045 }
00046
00047
00048
00049
00050
00051
00052 const float tmpA = (float)(1.0 / 365.25);
00053 const float tmpB = (float)(1.0 / 30.6001);
00054
00055 float mjdf = mjd;
00056 int year = (int) truncf((mjdf - 15078.2f) * tmpA);
00057 int month = (int) truncf(
00058 (mjdf - 14956.1f - truncf(year * 365.25f)) * tmpB);
00059 int day = (int) truncf(
00060 (mjdf - 14956.0f - truncf(year * 365.25f) - truncf(month * 30.6001f)));
00061 int i = (month == 14 || month == 15) ? 1 : 0;
00062
00063 QDate date(1900 + year + i, month - 1 - i * 12, day);
00064 QTime time(byteBCD2int(buf[2]), byteBCD2int(buf[3]),
00065 byteBCD2int(buf[4]));
00066
00067 return QDateTime(date, time);
00068 }