mirror of https://github.com/odrling/Aegisub
Fix for lavc audio provider to prevent it from crashing if it cannot load the file (was causing video playback to crash if no audio was loaded)
Originally committed to SVN as r963.
This commit is contained in:
parent
bc1897049b
commit
0dd4f96757
|
@ -110,11 +110,15 @@ LAVCAudioProvider::LAVCAudioProvider(wxString _filename)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (audStream == -1)
|
if (audStream == -1) {
|
||||||
|
codecContext = NULL;
|
||||||
throw _T("Could not find an audio stream");
|
throw _T("Could not find an audio stream");
|
||||||
|
}
|
||||||
AVCodec *codec = avcodec_find_decoder(codecContext->codec_id);
|
AVCodec *codec = avcodec_find_decoder(codecContext->codec_id);
|
||||||
if (!codec)
|
if (!codec) {
|
||||||
|
codecContext = NULL;
|
||||||
throw _T("Could not find a suitable audio decoder");
|
throw _T("Could not find a suitable audio decoder");
|
||||||
|
}
|
||||||
if (avcodec_open(codecContext, codec) < 0)
|
if (avcodec_open(codecContext, codec) < 0)
|
||||||
throw _T("Failed to open audio decoder");
|
throw _T("Failed to open audio decoder");
|
||||||
|
|
||||||
|
|
|
@ -227,72 +227,74 @@ bool LAVCVideoProvider::GetNextFrame() {
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
//// Convert AVFrame to wxBitmap
|
//// Convert AVFrame to wxBitmap
|
||||||
//wxBitmap LAVCVideoProvider::AVFrameToWX(AVFrame *source, int n) {
|
/*
|
||||||
// // Get sizes
|
wxBitmap LAVCVideoProvider::AVFrameToWX(AVFrame *source, int n) {
|
||||||
// int w = codecContext->width;
|
// Get sizes
|
||||||
// int h = codecContext->height;
|
int w = codecContext->width;
|
||||||
////#ifdef __WINDOWS__
|
int h = codecContext->height;
|
||||||
//// PixelFormat format = PIX_FMT_RGBA32;
|
//#ifdef __WINDOWS__
|
||||||
////#else
|
// PixelFormat format = PIX_FMT_RGBA32;
|
||||||
// PixelFormat format = PIX_FMT_RGB24;
|
//#else
|
||||||
////#endif
|
PixelFormat format = PIX_FMT_RGB24;
|
||||||
// unsigned int size1 = avpicture_get_size(codecContext->pix_fmt,display_w,display_h);
|
//#endif
|
||||||
// unsigned int size2 = avpicture_get_size(format,display_w,display_h);
|
unsigned int size1 = avpicture_get_size(codecContext->pix_fmt,display_w,display_h);
|
||||||
//
|
unsigned int size2 = avpicture_get_size(format,display_w,display_h);
|
||||||
// // Prepare buffers
|
|
||||||
// if (!buffer1 || buffer1Size != size1) {
|
// Prepare buffers
|
||||||
// if (buffer1) delete buffer1;
|
if (!buffer1 || buffer1Size != size1) {
|
||||||
// buffer1 = new uint8_t[size1];
|
if (buffer1) delete buffer1;
|
||||||
// buffer1Size = size1;
|
buffer1 = new uint8_t[size1];
|
||||||
// }
|
buffer1Size = size1;
|
||||||
// if (!buffer2 || buffer2Size != size2) {
|
}
|
||||||
// if (buffer2) delete buffer2;
|
if (!buffer2 || buffer2Size != size2) {
|
||||||
// buffer2 = new uint8_t[size2];
|
if (buffer2) delete buffer2;
|
||||||
// buffer2Size = size2;
|
buffer2 = new uint8_t[size2];
|
||||||
// }
|
buffer2Size = size2;
|
||||||
//
|
}
|
||||||
// // Resize
|
|
||||||
// AVFrame *resized;
|
// Resize
|
||||||
// bool resize = w != display_w || h != display_h;
|
AVFrame *resized;
|
||||||
// if (resize) {
|
bool resize = w != display_w || h != display_h;
|
||||||
// // Allocate
|
if (resize) {
|
||||||
// unsigned int resSize = avpicture_get_size(codecContext->pix_fmt,display_w,display_h);
|
// Allocate
|
||||||
// resized = avcodec_alloc_frame();
|
unsigned int resSize = avpicture_get_size(codecContext->pix_fmt,display_w,display_h);
|
||||||
// avpicture_fill((AVPicture*) resized, buffer1, codecContext->pix_fmt, display_w, display_h);
|
resized = avcodec_alloc_frame();
|
||||||
//
|
avpicture_fill((AVPicture*) resized, buffer1, codecContext->pix_fmt, display_w, display_h);
|
||||||
// // Resize
|
|
||||||
// ImgReSampleContext *resampleContext = img_resample_init(display_w,display_h,w,h);
|
// Resize
|
||||||
// img_resample(resampleContext,(AVPicture*) resized,(AVPicture*) source);
|
ImgReSampleContext *resampleContext = img_resample_init(display_w,display_h,w,h);
|
||||||
// img_resample_close(resampleContext);
|
img_resample(resampleContext,(AVPicture*) resized,(AVPicture*) source);
|
||||||
//
|
img_resample_close(resampleContext);
|
||||||
// // Set new w/h
|
|
||||||
// w = display_w;
|
// Set new w/h
|
||||||
// h = display_h;
|
w = display_w;
|
||||||
// }
|
h = display_h;
|
||||||
// else resized = source;
|
}
|
||||||
//
|
else resized = source;
|
||||||
// // Allocate RGB32 buffer
|
|
||||||
// AVFrame *frameRGB = avcodec_alloc_frame();
|
// Allocate RGB32 buffer
|
||||||
// avpicture_fill((AVPicture*) frameRGB, buffer2, format, w, h);
|
AVFrame *frameRGB = avcodec_alloc_frame();
|
||||||
//
|
avpicture_fill((AVPicture*) frameRGB, buffer2, format, w, h);
|
||||||
// // Convert to RGB32
|
|
||||||
// img_convert((AVPicture*) frameRGB, format, (AVPicture*) resized, codecContext->pix_fmt, w, h);
|
// Convert to RGB32
|
||||||
//
|
img_convert((AVPicture*) frameRGB, format, (AVPicture*) resized, codecContext->pix_fmt, w, h);
|
||||||
// // Convert to wxBitmap
|
|
||||||
// wxImage img(w, h, false);
|
// Convert to wxBitmap
|
||||||
// unsigned char *data = (unsigned char *)malloc(w * h * 3);
|
wxImage img(w, h, false);
|
||||||
// memcpy(data, frameRGB->data[0], w * h * 3);
|
unsigned char *data = (unsigned char *)malloc(w * h * 3);
|
||||||
// img.SetData(data);
|
memcpy(data, frameRGB->data[0], w * h * 3);
|
||||||
// if (overlay)
|
img.SetData(data);
|
||||||
// overlay->Render(img, VFR_Input.GetTimeAtFrame(n));
|
if (overlay)
|
||||||
//
|
overlay->Render(img, VFR_Input.GetTimeAtFrame(n));
|
||||||
// wxBitmap bmp(img);
|
|
||||||
//
|
wxBitmap bmp(img);
|
||||||
// av_free(frameRGB);
|
|
||||||
// if (resized != source)
|
av_free(frameRGB);
|
||||||
// av_free(resized);
|
if (resized != source)
|
||||||
// return bmp;
|
av_free(resized);
|
||||||
//}
|
return bmp;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/////////////
|
/////////////
|
||||||
|
|
Loading…
Reference in New Issue