Ticket #2420: replex.patch
| File replex.patch, 10.8 KB (added by , 19 years ago) |
|---|
-
programs/mythtranscode/replex/ringbuffer.h
97 97 98 98 static inline unsigned int ring_free(ringbuffer *rbuf){ 99 99 int free; 100 free = rbuf->read_pos - rbuf->write_pos -1;100 free = rbuf->read_pos - rbuf->write_pos; 101 101 if (free <= 0) free += rbuf->size; 102 103 return free ;102 //Note: free is gauranteed to be >=1 from the above 103 return free - 1; 104 104 } 105 105 106 106 static inline unsigned int ring_avail(ringbuffer *rbuf){ -
programs/mythtranscode/replex/multiplex.c
31 31 { 32 32 int i; 33 33 int started = 0; 34 int pos = 0;34 int pos = -1; 35 35 uint64_t tmppts; 36 36 for(i=0; i < n; i++) 37 37 if(aok[i]){ -
programs/mythtranscode/replex/pes.c
157 157 158 158 int l; 159 159 unsigned short *pl; 160 int c=0;160 int done; 161 161 162 162 uint8_t headr[3] = { 0x00, 0x00, 0x01} ; 163 164 while (c < count && (!p->mpeg || 165 (p->mpeg == 2 && p->found < 9)) 166 && (p->found < 5 || !p->done)){ 167 switch ( p->found ){ 168 case 0: 169 case 1: 170 if (buf[c] == 0x00) p->found++; 171 else p->found = 0; 172 c++; 173 break; 174 case 2: 175 if (buf[c] == 0x01) p->found++; 176 else if (buf[c] == 0){ 177 p->found = 2; 178 } else p->found = 0; 179 c++; 180 break; 181 case 3: 182 p->cid = 0; 183 switch (buf[c]){ 184 case PROG_STREAM_MAP: 185 case PRIVATE_STREAM2: 186 case PROG_STREAM_DIR: 187 case ECM_STREAM : 188 case EMM_STREAM : 189 case PADDING_STREAM : 190 case DSM_CC_STREAM : 191 case ISO13522_STREAM: 192 p->done = 1; 193 case PRIVATE_STREAM1: 194 case VIDEO_STREAM_S ... VIDEO_STREAM_E: 195 case AUDIO_STREAM_S ... AUDIO_STREAM_E: 196 p->found++; 197 p->cid = buf[c]; 163 do { 164 int c=0; 165 done = 1; 166 while (c < count && (!p->mpeg || 167 (p->mpeg == 2 && p->found < 9)) 168 && (p->found < 5 || !p->done)){ 169 switch ( p->found ){ 170 case 0: 171 case 1: 172 if (buf[c] == 0x00) p->found++; 173 else p->found = 0; 198 174 c++; 199 175 break; 200 default: 201 case PACK_START: 202 case SYS_START: 203 p->found = 0; 176 case 2: 177 if (buf[c] == 0x01) p->found++; 178 else if (buf[c] == 0){ 179 p->found = 2; 180 } else p->found = 0; 204 181 c++; 205 182 break; 206 } 207 break; 183 case 3: 184 p->cid = 0; 185 switch (buf[c]){ 186 case PROG_STREAM_MAP: 187 case PRIVATE_STREAM2: 188 case PROG_STREAM_DIR: 189 case ECM_STREAM : 190 case EMM_STREAM : 191 case PADDING_STREAM : 192 case DSM_CC_STREAM : 193 case ISO13522_STREAM: 194 p->done = 1; 195 case PRIVATE_STREAM1: 196 case VIDEO_STREAM_S ... VIDEO_STREAM_E: 197 case AUDIO_STREAM_S ... AUDIO_STREAM_E: 198 p->found++; 199 p->cid = buf[c]; 200 c++; 201 break; 202 default: 203 case PACK_START: 204 case SYS_START: 205 p->found = 0; 206 c++; 207 break; 208 } 209 break; 208 210 209 211 210 case 4: 211 if (count-c > 1){ 212 pl = (unsigned short *) (buf+c); 213 p->plength = ntohs(*pl); 214 p->plen[0] = buf[c]; 215 c++; 212 case 4: 213 if (count-c > 1){ 214 pl = (unsigned short *) (buf+c); 215 p->plength = ntohs(*pl); 216 p->plen[0] = buf[c]; 217 c++; 218 p->plen[1] = buf[c]; 219 c++; 220 p->found+=2; 221 } else { 222 p->plen[0] = buf[c]; 223 p->found++; 224 return; 225 } 226 break; 227 case 5: 216 228 p->plen[1] = buf[c]; 217 229 c++; 218 p->found+=2; 219 } else { 220 p->plen[0] = buf[c]; 230 pl = (unsigned short *) p->plen; 231 p->plength = ntohs(*pl); 221 232 p->found++; 222 return; 223 } 224 break; 225 case 5: 226 p->plen[1] = buf[c]; 227 c++; 228 pl = (unsigned short *) p->plen; 229 p->plength = ntohs(*pl); 230 p->found++; 231 break; 233 break; 232 234 233 235 234 case 6: 235 if (!p->done){ 236 p->flag1 = buf[c]; 237 c++; 238 p->found++; 239 if ( (p->flag1 & 0xC0) == 0x80 ) p->mpeg = 2; 240 else { 241 fprintf(stderr, 242 "Error: THIS IS AN MPEG1 FILE\n"); 243 exit(1); 236 case 6: 237 if (!p->done){ 238 p->flag1 = buf[c]; 239 c++; 240 p->found++; 241 if ( (p->flag1 & 0xC0) == 0x80 ) p->mpeg = 2; 242 else { 243 fprintf(stderr, 244 "Error: THIS IS AN MPEG1 FILE\n"); 245 exit(1); 246 } 244 247 } 245 } 246 break; 248 break; 247 249 248 case 7:249 if ( !p->done && p->mpeg == 2){250 p->flag2 = buf[c];251 c++;252 p->found++;253 }254 break;250 case 7: 251 if ( !p->done && p->mpeg == 2){ 252 p->flag2 = buf[c]; 253 c++; 254 p->found++; 255 } 256 break; 255 257 256 case 8:257 if ( !p->done && p->mpeg == 2){258 p->hlength = buf[c];259 c++;260 p->found++;261 }262 break;258 case 8: 259 if ( !p->done && p->mpeg == 2){ 260 p->hlength = buf[c]; 261 c++; 262 p->found++; 263 } 264 break; 263 265 264 default:266 default: 265 267 266 break; 268 break; 269 } 267 270 } 268 }269 271 270 if (!p->plength) p->plength = MMAX_PLENGTH-6;272 if (!p->plength) p->plength = MMAX_PLENGTH-6; 271 273 272 274 273 if ( p->done || (p->mpeg == 2 && p->found >= 9) ){274 switch (p->cid){275 if ( p->done || (p->mpeg == 2 && p->found >= 9) ){ 276 switch (p->cid){ 275 277 276 case AUDIO_STREAM_S ... AUDIO_STREAM_E:277 case VIDEO_STREAM_S ... VIDEO_STREAM_E:278 case PRIVATE_STREAM1:278 case AUDIO_STREAM_S ... AUDIO_STREAM_E: 279 case VIDEO_STREAM_S ... VIDEO_STREAM_E: 280 case PRIVATE_STREAM1: 279 281 280 if (p->withbuf){281 memcpy(p->buf, headr, 3);282 p->buf[3] = p->cid;283 memcpy(p->buf+4,p->plen,2);284 } else {285 memcpy(p->hbuf, headr, 3);286 p->hbuf[3] = p->cid;287 memcpy(p->hbuf+4,p->plen,2);288 }289 290 if (p->found == 9){291 282 if (p->withbuf){ 292 p->buf[6] = p->flag1;293 p->buf[ 7] = p->flag2;294 p->buf[8] = p->hlength;283 memcpy(p->buf, headr, 3); 284 p->buf[3] = p->cid; 285 memcpy(p->buf+4,p->plen,2); 295 286 } else { 296 p->hbuf[6] = p->flag1;297 p->hbuf[ 7] = p->flag2;298 p->hbuf[8] = p->hlength;287 memcpy(p->hbuf, headr, 3); 288 p->hbuf[3] = p->cid; 289 memcpy(p->hbuf+4,p->plen,2); 299 290 } 300 }301 291 302 if ( (p->flag2 & PTS_ONLY) && p->found < 14){ 303 while (c < count && p->found < 14){ 304 p->pts[p->found-9] = buf[c]; 305 if (p->withbuf) 306 p->buf[p->found] = buf[c]; 307 else 308 p->hbuf[p->found] = buf[c]; 309 c++; 310 p->found++; 292 if (p->found == 9){ 293 if (p->withbuf){ 294 p->buf[6] = p->flag1; 295 p->buf[7] = p->flag2; 296 p->buf[8] = p->hlength; 297 } else { 298 p->hbuf[6] = p->flag1; 299 p->hbuf[7] = p->flag2; 300 p->hbuf[8] = p->hlength; 301 } 311 302 } 312 if (c == count) return;313 }314 303 315 if (((p->flag2 & PTS_DTS) == 0xC0) && p->found < 19){ 316 while (c < count && p->found < 19){ 317 p->dts[p->found-14] = buf[c]; 318 if (p->withbuf) 319 p->buf[p->found] = buf[c]; 320 else 321 p->hbuf[p->found] = buf[c]; 322 c++; 323 p->found++; 304 if ( (p->flag2 & PTS_ONLY) && p->found < 14){ 305 while (c < count && p->found < 14){ 306 p->pts[p->found-9] = buf[c]; 307 if (p->withbuf) 308 p->buf[p->found] = buf[c]; 309 else 310 p->hbuf[p->found] = buf[c]; 311 c++; 312 p->found++; 313 } 314 if (c == count) return; 324 315 } 325 if (c == count) return;326 }327 316 317 if (((p->flag2 & PTS_DTS) == 0xC0) && p->found < 19){ 318 while (c < count && p->found < 19){ 319 p->dts[p->found-14] = buf[c]; 320 if (p->withbuf) 321 p->buf[p->found] = buf[c]; 322 else 323 p->hbuf[p->found] = buf[c]; 324 c++; 325 p->found++; 326 } 327 if (c == count) return; 328 } 328 329 329 while (c < count && p->found < p->plength+6){ 330 l = count -c; 331 if (l+p->found > p->plength+6) 332 l = p->plength+6-p->found; 333 if (p->withbuf) 334 memcpy(p->buf+p->found, buf+c, l); 335 else { 336 if ( p->found < 337 (unsigned int)p->hlength+9 ){ 338 int rest = p->hlength+9-p->found; 339 memcpy(p->hbuf+p->found, buf+c, rest); 340 if (ring_write(p->rbuf, buf+c+rest, 341 l-rest) <0){ 342 exit(1); 330 331 while (c < count && p->found < p->plength+6){ 332 l = count -c; 333 if (l+p->found > p->plength+6) 334 l = p->plength+6-p->found; 335 if (p->withbuf) 336 memcpy(p->buf+p->found, buf+c, l); 337 else { 338 if ( p->found < 339 (unsigned int)p->hlength+9 ){ 340 int rest = p->hlength+9-p->found; 341 memcpy(p->hbuf+p->found, buf+c, rest); 342 if (ring_write(p->rbuf, buf+c+rest, 343 l-rest) <0){ 344 exit(1); 345 } 346 } else { 347 if (ring_write(p->rbuf, buf+c, l)<0){ 348 fprintf(stderr, 349 "ring buffer overflow %d\n" 350 ,p->rbuf->size); 351 exit(1); 352 } 343 353 } 344 } else {345 if (ring_write(p->rbuf, buf+c, l)<0){346 fprintf(stderr,347 "ring buffer overflow %d\n"348 ,p->rbuf->size);349 exit(1);350 }351 354 } 355 356 p->found += l; 357 c += l; 358 } 359 if(p->found == p->plength+6){ 360 func(p); 352 361 } 362 break; 363 } 353 364 354 p->found += l; 355 c += l; 356 } 357 if(p->found == p->plength+6){ 358 func(p); 365 if ( p->done ){ 366 if( p->found + count - c < p->plength+6){ 367 p->found += count-c; 368 c = count; 369 } else { 370 c += p->plength+6 - p->found; 371 p->found = p->plength+6; 372 } 359 373 } 360 break;361 }362 374 363 if ( p->done ){364 if( p->found + count - c < p->plength+6){365 p->found += count-c;366 c = count;367 } else {368 c += p->plength+6 - p->found;369 p->found = p->plength+6;375 if (p->plength && p->found == p->plength+6) { 376 init_pes_in(p, p->type, NULL, p->withbuf); 377 if (c < count) { 378 done = 0; 379 count -= c; 380 buf += c; 381 } 370 382 } 371 } 372 373 if (p->plength && p->found == p->plength+6) { 374 init_pes_in(p, p->type, NULL, p->withbuf); 375 if (c < count) 376 get_pes(p, buf+c, count-c, func); 377 } 378 } 383 } 384 } while(!done); 379 385 return; 380 386 } 381 387 -
programs/mythtranscode/replex/ringbuffer.c
423 423 424 424 return dsize; 425 425 } 426 void dummy_print(dummy_buffer *dbuf) 427 { 428 int i; 429 uint64_t rtime; 430 uint32_t size; 431 int avail = ring_avail(&dbuf->time_index) / sizeof(uint64_t); 432 for(i = 0; i < avail; i++) { 433 ring_peek(&dbuf->time_index,(uint8_t *) &rtime, 434 sizeof(uint64_t), i * sizeof(uint64_t)); 435 ring_peek(&dbuf->data_index,(uint8_t *) &size, 436 sizeof(uint32_t), i * sizeof(uint32_t)); 437 printf("%d : %llu %u\n", i, rtime, size); 438 } 439 printf("Used: %d Free: %d data-free: %d\n", avail, 1000-avail, dbuf->size - dbuf->fill); 440 }
