00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include "element.h"
00032 #include "pes.h"
00033 #include "ts.h"
00034
00035 #include "mythlogging.h"
00036
00037 void show_buf(uint8_t *buf, int length)
00038 {
00039 int i,j,r;
00040 uint8_t buffer[100];
00041 uint8_t temp[8];
00042 buffer[0] = '\0';
00043
00044 for (i=0; i<length; i+=16){
00045 for (j=0; j < 8 && j+i<length; j++)
00046 {
00047 sprintf(temp,"0x%02x ", (int)(buf[i+j]));
00048 strcat(buffer, temp);
00049 }
00050 for (r=j; r<8; r++)
00051 strcat(buffer, " ");
00052
00053 strcat(buffer, " ");
00054
00055 for (j=8; j < 16 && j+i<length; j++)
00056 {
00057 sprintf(temp, "0x%02x ", (int)(buf[i+j]));
00058 strcat(buffer, temp);
00059 }
00060 for (r=j; r<16; r++)
00061 strcat(buffer, " ");
00062
00063 for (j=0; j < 16 && j+i<length; j++){
00064 switch(buf[i+j]){
00065 case '0'...'Z':
00066 case 'a'...'z':
00067 sprintf(temp, "%c", buf[i+j]);
00068 break;
00069 default:
00070 sprintf(temp, ".");
00071 }
00072 strcat(buffer, temp);
00073 }
00074 LOG(VB_GENERAL, LOG_INFO, buffer);
00075 }
00076 }
00077
00078
00079
00080 int find_mpg_header(uint8_t head, uint8_t *buf, int length)
00081 {
00082
00083 int c = 0;
00084 int found=0;
00085
00086 if (length <0) return -1;
00087
00088 while (found < 4 && c < length){
00089 switch(found){
00090
00091 case 0:
00092 if (buf[c] == 0x00) found = 1;
00093 break;
00094
00095 case 1:
00096 if (buf[c] == 0x00) found = 2;
00097 else found = 0;
00098 break;
00099
00100 case 2:
00101 if (buf[c] == 0x01) found = 3;
00102 else if (buf[c] != 0x00) found = 0;
00103 break;
00104
00105 case 3:
00106 if (buf[c] == head) return c-3;
00107 else found = 0;
00108 break;
00109 }
00110 c++;
00111 }
00112 return -1;
00113 }
00114
00115
00116 int find_any_header(uint8_t *head, uint8_t *buf, int length)
00117 {
00118
00119 int c = 0;
00120 int found=0;
00121
00122 if (length <0) return -1;
00123
00124 while (found < 4 && c < length){
00125 switch(found){
00126
00127 case 0:
00128 if (buf[c] == 0x00) found = 1;
00129 break;
00130
00131 case 1:
00132 if (buf[c] == 0x00) found = 2;
00133 else found = 0;
00134 break;
00135
00136 case 2:
00137 if (buf[c] == 0x01) found = 3;
00138 else if (buf[c] != 0x00) found = 0;
00139 break;
00140
00141 case 3:
00142 *head = buf[c];
00143 return c-3;
00144 break;
00145 }
00146 c++;
00147 }
00148 return -1;
00149 }
00150
00151
00152 uint64_t trans_pts_dts(uint8_t *pts)
00153 {
00154 uint64_t wts;
00155
00156 wts = ((uint64_t)((pts[0] & 0x0E) << 5) |
00157 ((pts[1] & 0xFC) >> 2)) << 24;
00158 wts |= (((pts[1] & 0x03) << 6) |
00159 ((pts[2] & 0xFC) >> 2)) << 16;
00160 wts |= (((pts[2] & 0x02) << 6) |
00161 ((pts[3] & 0xFE) >> 1)) << 8;
00162 wts |= (((pts[3] & 0x01) << 7) |
00163 ((pts[4] & 0xFE) >> 1));
00164
00165 wts = wts*300ULL;
00166 return wts;
00167 }
00168
00169
00170 int mring_peek( ringbuffer *rbuf, uint8_t *buf, unsigned int l, uint32_t off)
00171 {
00172 int c = 0;
00173
00174 if (ring_avail(rbuf)+off <= l)
00175 return -1;
00176
00177 c = ring_peek(rbuf, buf, l, off);
00178 return c+off;
00179 }
00180
00181
00182
00183 int ring_find_mpg_header(ringbuffer *rbuf, uint8_t head, int off, int le)
00184 {
00185
00186 int c = 0;
00187 int found = 0;
00188
00189 c = off;
00190 while ( c-off < le){
00191 uint8_t b;
00192 if ( mring_peek(rbuf, &b, 1, c) <0) return -1;
00193 switch(found){
00194
00195 case 0:
00196 if (b == 0x00) found = 1;
00197 break;
00198
00199 case 1:
00200 if (b == 0x00) found = 2;
00201 else found = 0;
00202 break;
00203
00204 case 2:
00205 if (b == 0x01) found = 3;
00206 else if (b != 0x00) found = 0;
00207 break;
00208
00209 case 3:
00210 if (b == head) return c-3-off;
00211 else found = 0;
00212 break;
00213 }
00214 c++;
00215
00216 }
00217 if (found) return -2;
00218 else return -1;
00219 }
00220
00221
00222 int ring_find_any_header(ringbuffer *rbuf, uint8_t *head, int off, int le)
00223 {
00224
00225 int c = 0;
00226 int found =0;
00227
00228 c = off;
00229 while ( c-off < le){
00230 uint8_t b;
00231 if ( mring_peek(rbuf, &b, 1, c) <0){
00232 return -1;
00233 }
00234 switch(found){
00235
00236 case 0:
00237 if (b == 0x00) found = 1;
00238 break;
00239
00240 case 1:
00241 if (b == 0x00) found = 2;
00242 else found = 0;
00243 break;
00244
00245 case 2:
00246 if (b == 0x01) found = 3;
00247 else if (b != 0x00) found = 0;
00248 break;
00249
00250 case 3:
00251 *head = b;
00252 return c-3-off;
00253 break;
00254 }
00255 c++;
00256 }
00257 if (found) return -2;
00258 else return -1;
00259 }
00260