2014-02-09 Carl Hetherington <cth@carlh.net>
+ * Some small bits of increased low-memory stability.
+
* Version 1.64.7 released.
2014-02-08 Carl Hetherington <cth@carlh.net>
#include "ffmpeg.h"
#include "ffmpeg_content.h"
#include "exceptions.h"
+#include "util.h"
#include "i18n.h"
av_register_all ();
_file_group.set_paths (_ffmpeg_content->paths ());
- _avio_buffer = static_cast<uint8_t*> (av_malloc (_avio_buffer_size));
+ _avio_buffer = static_cast<uint8_t*> (wrapped_av_malloc (_avio_buffer_size));
_avio_context = avio_alloc_context (_avio_buffer, _avio_buffer_size, 0, this, avio_read_wrapper, 0, avio_seek_wrapper);
_format_context = avformat_alloc_context ();
_format_context->pb = _avio_context;
void
Image::allocate ()
{
- _data = (uint8_t **) av_malloc (4 * sizeof (uint8_t *));
+ _data = (uint8_t **) wrapped_av_malloc (4 * sizeof (uint8_t *));
_data[0] = _data[1] = _data[2] = _data[3] = 0;
- _line_size = (int *) av_malloc (4 * sizeof (int));
+ _line_size = (int *) wrapped_av_malloc (4 * sizeof (int));
_line_size[0] = _line_size[1] = _line_size[2] = _line_size[3] = 0;
- _stride = (int *) av_malloc (4 * sizeof (int));
+ _stride = (int *) wrapped_av_malloc (4 * sizeof (int));
_stride[0] = _stride[1] = _stride[2] = _stride[3] = 0;
for (int i = 0; i < components(); ++i) {
seem to mind. The nasty + 1 in this malloc makes sure there is always a byte
for that instruction to read safely.
*/
- _data[i] = (uint8_t *) av_malloc (_stride[i] * lines (i) + 1);
+ _data[i] = (uint8_t *) wrapped_av_malloc (_stride[i] * lines (i) + 1);
}
}
#include <iostream>
#include <fstream>
#include <climits>
+#include <stdexcept>
#ifdef DCPOMATIC_POSIX
#include <execinfo.h>
#include <cxxabi.h>
using std::numeric_limits;
using std::pair;
using std::cout;
+using std::bad_alloc;
using std::streampos;
using boost::shared_ptr;
using boost::thread;
return libdcp::Size (full_frame.width, rint (full_frame.width / ratio));
}
+
+void *
+wrapped_av_malloc (size_t s)
+{
+ void* p = av_malloc (s);
+ if (!p) {
+ throw bad_alloc ();
+ }
+ return p;
+}
+
extern std::string get_required_string (std::multimap<std::string, std::string> const & kv, std::string k);
extern int get_optional_int (std::multimap<std::string, std::string> const & kv, std::string k);
extern std::string get_optional_string (std::multimap<std::string, std::string> const & kv, std::string k);
+extern void* wrapped_av_malloc (size_t);
/** @class Socket
* @brief A class to wrap a boost::asio::ip::tcp::socket with some things
using std::max;
using std::cout;
using std::list;
+using std::bad_alloc;
using std::make_pair;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
return;
}
- _player = f->make_player ();
+ try {
+ _player = f->make_player ();
+ } catch (bad_alloc) {
+ error_dialog (this, _("There is not enough free memory to do that."));
+ _film.reset ();
+ return;
+ }
+
_player->disable_audio ();
_player->Video.connect (boost::bind (&FilmViewer::process_video, this, _1, _2, _5));
_player->Changed.connect (boost::bind (&FilmViewer::player_changed, this, _1));