comparison rv10.c @ 713:e74a563eb643 libavcodec

rv10 cleanup (de)muxer still needs to be cleaned up (still searching volunteer for that ;) )
author michaelni
date Tue, 01 Oct 2002 19:29:10 +0000
parents e55b91623e09
children 25d7fb7c89be
comparison
equal deleted inserted replaced
712:e55b91623e09 713:e74a563eb643
263 } 263 }
264 264
265 /* read RV 1.0 compatible frame header */ 265 /* read RV 1.0 compatible frame header */
266 static int rv10_decode_picture_header(MpegEncContext *s) 266 static int rv10_decode_picture_header(MpegEncContext *s)
267 { 267 {
268 int mb_count, pb_frame, marker, h, full_frame; 268 int mb_count, pb_frame, marker, full_frame, unk;
269 int pic_num, unk; 269
270 270 full_frame= s->avctx->slice_count==1;
271 //XXX/FIXME this should be done in the demuxer not here 271 //printf("ff:%d\n", full_frame);
272 /* skip packet header */
273 h = get_bits(&s->gb, 8);
274 if ((h & 0xc0) == 0xc0) {
275 int len, pos;
276 full_frame = 1;
277 len = get_num(&s->gb);
278 pos = get_num(&s->gb);
279 //printf("pos:%d\n",len);
280 } else {
281 int seq, frame_size, pos;
282 full_frame = 0;
283 seq = get_bits(&s->gb, 8);
284 frame_size = get_num(&s->gb);
285 pos = get_num(&s->gb);
286 //printf("seq:%d, size:%d, pos:%d\n",seq,frame_size,pos);
287 }
288 /* picture number */
289 pic_num= get_bits(&s->gb, 8);
290
291 marker = get_bits(&s->gb, 1); 272 marker = get_bits(&s->gb, 1);
292 273
293 if (get_bits(&s->gb, 1)) 274 if (get_bits(&s->gb, 1))
294 s->pict_type = P_TYPE; 275 s->pict_type = P_TYPE;
295 else 276 else
296 s->pict_type = I_TYPE; 277 s->pict_type = I_TYPE;
297 //printf("h:%d ver:%d\n",h,s->rv10_version); 278 //printf("h:%X ver:%d\n",h,s->rv10_version);
298 if(!marker) printf("marker missing\n"); 279 if(!marker) printf("marker missing\n");
299 pb_frame = get_bits(&s->gb, 1); 280 pb_frame = get_bits(&s->gb, 1);
300 281
301 #ifdef DEBUG 282 #ifdef DEBUG
302 printf("pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame); 283 printf("pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame);
327 #endif 308 #endif
328 } 309 }
329 } 310 }
330 /* if multiple packets per frame are sent, the position at which 311 /* if multiple packets per frame are sent, the position at which
331 to display the macro blocks is coded here */ 312 to display the macro blocks is coded here */
332 if (!full_frame) { 313 if ((!full_frame) || show_bits(&s->gb, 12)==0) {
333 s->mb_x = get_bits(&s->gb, 6); /* mb_x */ 314 s->mb_x = get_bits(&s->gb, 6); /* mb_x */
334 s->mb_y = get_bits(&s->gb, 6); /* mb_y */ 315 s->mb_y = get_bits(&s->gb, 6); /* mb_y */
335 mb_count = get_bits(&s->gb, 12); 316 mb_count = get_bits(&s->gb, 12);
336 } else { 317 } else {
337 s->mb_x = 0; 318 s->mb_x = 0;
356 337
357 s->width = avctx->width; 338 s->width = avctx->width;
358 s->height = avctx->height; 339 s->height = avctx->height;
359 340
360 s->h263_rv10 = 1; 341 s->h263_rv10 = 1;
361 if(avctx->extradata_size >= 8){ 342 switch(avctx->sub_id){
362 switch(((uint32_t*)avctx->extradata)[1]){ 343 case 0x10000000:
363 case 0x10000000: 344 s->rv10_version= 0;
364 s->rv10_version= 0; 345 s->h263_long_vectors=0;
365 s->h263_long_vectors=0; 346 break;
366 break; 347 case 0x10003000:
367 case 0x10003000: 348 s->rv10_version= 3;
368 s->rv10_version= 3; 349 s->h263_long_vectors=1;
369 s->h263_long_vectors=1; 350 break;
370 break; 351 case 0x10003001:
371 case 0x10003001: 352 s->rv10_version= 3;
372 s->rv10_version= 3; 353 s->h263_long_vectors=0;
373 s->h263_long_vectors=0; 354 break;
374 break; 355 default:
375 default: 356 fprintf(stderr, "unknown header %X\n", avctx->sub_id);
376 fprintf(stderr, "unknown header %X\n", ((uint32_t*)avctx->extradata)[1]); 357 }
377 } 358 //printf("ver:%X\n", avctx->sub_id);
378 }else{
379 // for backward compatibility
380 s->rv10_version= avctx->sub_id;
381 }
382
383 s->flags= avctx->flags; 359 s->flags= avctx->flags;
384 360
385 if (MPV_common_init(s) < 0) 361 if (MPV_common_init(s) < 0)
386 return -1; 362 return -1;
387 363
410 386
411 MPV_common_end(s); 387 MPV_common_end(s);
412 return 0; 388 return 0;
413 } 389 }
414 390
415 static int rv10_decode_frame(AVCodecContext *avctx, 391 static int rv10_decode_packet(AVCodecContext *avctx,
416 void *data, int *data_size,
417 UINT8 *buf, int buf_size) 392 UINT8 *buf, int buf_size)
418 { 393 {
419 MpegEncContext *s = avctx->priv_data; 394 MpegEncContext *s = avctx->priv_data;
420 int i, mb_count, mb_pos, left; 395 int i, mb_count, mb_pos, left;
421 DCTELEM block[6][64]; 396 DCTELEM block[6][64];
422 AVPicture *pict = data;
423
424 #ifdef DEBUG
425 printf("*****frame %d size=%d\n", avctx->frame_number, buf_size);
426 #endif
427
428 /* no supplementary picture */
429 if (buf_size == 0) {
430 *data_size = 0;
431 return 0;
432 }
433 397
434 init_get_bits(&s->gb, buf, buf_size); 398 init_get_bits(&s->gb, buf, buf_size);
435 399
436 mb_count = rv10_decode_picture_header(s); 400 mb_count = rv10_decode_picture_header(s);
437 if (mb_count < 0) { 401 if (mb_count < 0) {
438 fprintf(stderr, "HEADER ERROR\n"); 402 fprintf(stderr, "HEADER ERROR\n");
439 return -1; 403 return -1;
440 } 404 }
508 s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); 472 s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2);
509 s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2); 473 s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2);
510 } 474 }
511 } 475 }
512 476
513 if (s->mb_x == 0 && 477 return buf_size;
514 s->mb_y == s->mb_height) { 478 }
479
480 static int rv10_decode_frame(AVCodecContext *avctx,
481 void *data, int *data_size,
482 UINT8 *buf, int buf_size)
483 {
484 MpegEncContext *s = avctx->priv_data;
485 int i;
486 AVPicture *pict = data;
487
488 #ifdef DEBUG
489 printf("*****frame %d size=%d\n", avctx->frame_number, buf_size);
490 #endif
491
492 /* no supplementary picture */
493 if (buf_size == 0) {
494 *data_size = 0;
495 return 0;
496 }
497
498 if(avctx->slice_count){
499 for(i=0; i<avctx->slice_count; i++){
500 int offset= avctx->slice_offset[i];
501 int size;
502
503 if(i+1 == avctx->slice_count)
504 size= buf_size - offset;
505 else
506 size= avctx->slice_offset[i+1] - offset;
507
508 if( rv10_decode_packet(avctx, buf+offset, size) < 0 )
509 return -1;
510 }
511 }else{
512 if( rv10_decode_packet(avctx, buf, buf_size) < 0 )
513 return -1;
514 }
515
516 if(s->mb_y>=s->mb_height){
515 MPV_frame_end(s); 517 MPV_frame_end(s);
516 518
517 pict->data[0] = s->current_picture[0]; 519 pict->data[0] = s->current_picture[0];
518 pict->data[1] = s->current_picture[1]; 520 pict->data[1] = s->current_picture[1];
519 pict->data[2] = s->current_picture[2]; 521 pict->data[2] = s->current_picture[2];
520 pict->linesize[0] = s->linesize; 522 pict->linesize[0] = s->linesize;
521 pict->linesize[1] = s->uvlinesize; 523 pict->linesize[1] = s->uvlinesize;
522 pict->linesize[2] = s->uvlinesize; 524 pict->linesize[2] = s->uvlinesize;
523 525
524 avctx->quality = s->qscale; 526 avctx->quality = s->qscale;
525 *data_size = sizeof(AVPicture); 527 *data_size = sizeof(AVPicture);
526 } else { 528 }else{
527 *data_size = 0; 529 *data_size = 0;
528 } 530 }
531
529 return buf_size; 532 return buf_size;
530 } 533 }
531 534
532 AVCodec rv10_decoder = { 535 AVCodec rv10_decoder = {
533 "rv10", 536 "rv10",