|
MythTV
0.26-pre
|
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 // set buf to the startdate 00030 const uint8_t *buf = _date_ptrs[index]; 00031 uint mjd = (buf[0] << 8) | buf[1]; 00032 // reset buf two bytes before the startime 00033 buf = _time_ptrs[index]-2; 00034 if (mjd >= 40587) 00035 { 00036 QDateTime result; 00037 // Modified Julian date as number of days since 17th November 1858. 00038 // 1st Jan 1970 was date 40587. 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 // Original function taken from dvbdate.c in linuxtv-apps code 00048 // Use the routine specified in ETSI EN 300 468 V1.4.1, 00049 // "Specification for Service Information in Digital Video Broadcasting" 00050 // to convert from Modified Julian Date to Year, Month, Day. 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 }
1.7.6.1