comparison sv/videoio/SDL_ffmpeg.cpp @ 170:caaddda5477c

- window size limited to a multiple of 4 - allow to have a bigger image than original, - add several cleans on pointers
author lbarthelemy
date Tue, 20 Nov 2007 09:14:57 +0000
parents 269562a2b89c
children f0e9330bee36
comparison
equal deleted inserted replaced
169:269562a2b89c 170:caaddda5477c
476 // create a packet for our data 476 // create a packet for our data
477 AVPacket pack; 477 AVPacket pack;
478 478
479 // reserve some pointers for use in loop 479 // reserve some pointers for use in loop
480 AVFrame *inFrame, *inFrameRGB; 480 AVFrame *inFrame, *inFrameRGB;
481 uint8_t *inVideoBuffer = NULL;
481 482
482 // allocate a frame 483 // allocate a frame
483 inFrame = avcodec_alloc_frame(); 484 inFrame = avcodec_alloc_frame();
484 485
485 // allocate another frame for unknown->RGB conversion 486 // allocate another frame for unknown->RGB conversion
486 inFrameRGB = avcodec_alloc_frame(); 487 inFrameRGB = avcodec_alloc_frame();
487 488
488 if(SDL_ffmpegValidVideo(file)) { 489 if(SDL_ffmpegValidVideo(file)) {
489 // allocate buffer 490 // allocate buffer
490 uint8_t *inVideoBuffer = (uint8_t*)malloc( avpicture_get_size(file->vs[file->videoStream]->pixFmt, 491 inVideoBuffer = (uint8_t*)malloc( avpicture_get_size(file->vs[file->videoStream]->pixFmt,
491 file->vs[file->videoStream]->width, 492 file->vs[file->videoStream]->width,
492 file->vs[file->videoStream]->height) ); 493 file->vs[file->videoStream]->height) );
493 494
494 // put buffer into our reserved frame 495 // put buffer into our reserved frame
495 avpicture_fill( (AVPicture*)inFrameRGB, 496 avpicture_fill( (AVPicture*)inFrameRGB,
609 // if new timestamp is from future, we proceed 610 // if new timestamp is from future, we proceed
610 // if(buf->timestamp >= SDL_ffmpegGetPosition(file)) 611 // if(buf->timestamp >= SDL_ffmpegGetPosition(file))
611 // { 612 // {
612 int w=(int)(zoomFivan*320+0.5); 613 int w=(int)(zoomFivan*320+0.5);
613 int h=(int)(zoomFivan*240+0.5); 614 int h=(int)(zoomFivan*240+0.5);
614 if ((w>file->vs[file->videoStream]->width)||(h>file->vs[file->videoStream]->height)){ 615 //if ((w>file->vs[file->videoStream]->width)||(h>file->vs[file->videoStream]->height)){
615 w=file->vs[file->videoStream]->width; 616 // w=file->vs[file->videoStream]->width;
616 h=file->vs[file->videoStream]->height; 617 // h=file->vs[file->videoStream]->height;
617 } 618 //}
618 // Be sure we have a multiple of 4 619 // Be sure we have a multiple of 4
619 w &= 0xFFFFFFFC; 620 w &= 0xFFFFFFFC;
620 h &= 0xFFFFFFFC; 621 h &= 0xFFFFFFFC;
621 if (img_convert_ctx == NULL) { 622 if (img_convert_ctx == NULL) {
622 623
628 if (img_convert_ctx == NULL) { 629 if (img_convert_ctx == NULL) {
629 fprintf(stderr, "Cannot initialize the conversion context\n"); 630 fprintf(stderr, "Cannot initialize the conversion context\n");
630 exit(1); 631 exit(1);
631 } 632 }
632 } 633 }
633 634
635 // check to see if buffer is at the same size than the screen
636 if (inFrameRGB->linesize[0]/3 != w ) {
637 av_free(inFrameRGB);
638 free(inVideoBuffer);
639 //avcodec_default_release_buffer(img_convert_ctx , inFrameRGB);
640 inFrameRGB = avcodec_alloc_frame();
641 // allocate buffer
642 inVideoBuffer = (uint8_t*)malloc( avpicture_get_size(file->vs[file->videoStream]->pixFmt,
643 w,
644 h) );
645
646 // put buffer into our reserved frame
647 avpicture_fill( (AVPicture*)inFrameRGB,
648 inVideoBuffer,
649 file->vs[file->videoStream]->pixFmt,
650 w,
651 h);
652
653 }
654
634 ((AVPicture*)inFrameRGB)->linesize[0]=(int)w*3; 655 ((AVPicture*)inFrameRGB)->linesize[0]=(int)w*3;
635 sws_scale(img_convert_ctx, ((AVPicture*)inFrame)->data, ((AVPicture*)inFrame)->linesize, 656 sws_scale(img_convert_ctx,
636 0, file->vs[file->videoStream]->height, ((AVPicture*)inFrameRGB)->data, ((AVPicture*)inFrameRGB)->linesize); 657 ((AVPicture*)inFrame)->data, ((AVPicture*)inFrame)->linesize, 0, file->vs[file->videoStream]->height,
637 sws_freeContext(img_convert_ctx); 658 ((AVPicture*)inFrameRGB)->data, ((AVPicture*)inFrameRGB)->linesize);
638 img_convert_ctx=NULL; 659
639 // we convert whatever type of data we got to RGB24 660 sws_freeContext(img_convert_ctx);
661 img_convert_ctx=NULL;
662
663 // we convert whatever type of data we got to RGB24
640 /* img_convert((AVPicture*)inFrameRGB, 664 /* img_convert((AVPicture*)inFrameRGB,
641 file->vs[file->videoStream]->pixFmt, 665 file->vs[file->videoStream]->pixFmt,
642 (AVPicture*)inFrame, 666 (AVPicture*)inFrame,
643 ((AVCodecContext*)file->vs[file->videoStream]->_ffmpeg)->pix_fmt, 667 ((AVCodecContext*)file->vs[file->videoStream]->_ffmpeg)->pix_fmt,
644 file->vs[file->videoStream]->width, 668 file->vs[file->videoStream]->width,
645 file->vs[file->videoStream]->height); 669 file->vs[file->videoStream]->height);
646 */ 670 */
671
647 // allocate image room 672 // allocate image room
648 buf->img = SDL_CreateRGBSurface(SDL_SWSURFACE, 673 buf->img = SDL_CreateRGBSurface(SDL_SWSURFACE,
649 w, 674 w,
650 h, 675 h,
651 24, 0x0000FF, 0x00FF00, 0xFF0000, 0); 676 24, 0x0000FF, 0x00FF00, 0xFF0000, 0);
652
653 // copy image data to image room 677 // copy image data to image room
654 memcpy(buf->img->pixels, inFrameRGB->data[0], 678 memcpy(buf->img->pixels, inFrameRGB->data[0],
655 w*h* 3); 679 w*h* 3);
656 file->timebase=buf->timestamp-file->vs[file->videoStream]->lastTimeStamp; 680 file->timebase=buf->timestamp-file->vs[file->videoStream]->lastTimeStamp;
657 // we write the lastTimestamp we got 681 // we write the lastTimestamp we got
704 // we leave the decode semaphore 728 // we leave the decode semaphore
705 SDL_SemPost(file->decode); 729 SDL_SemPost(file->decode);
706 if ((file->skipAudio)&&(file->delay)) 730 if ((file->skipAudio)&&(file->delay))
707 SDL_Delay(3); 731 SDL_Delay(3);
708 } 732 }
733
734 if (inVideoBuffer)
735 {
736 free(inVideoBuffer);
737 inVideoBuffer = NULL;
738 }
739
709 // if we stop this thread, we can release the packet we reserved 740 // if we stop this thread, we can release the packet we reserved
710 av_free_packet(&pack); 741 av_free_packet(&pack);
742 free(samples);
743 av_free(inFrameRGB);
744 av_free(inFrame);
711 745
712 return 0; 746 return 0;
713 } 747 }
714 748
715 int SDL_ffmpegSeek(SDL_ffmpegFile* file, int64_t timestamp) { 749 int SDL_ffmpegSeek(SDL_ffmpegFile* file, int64_t timestamp) {