21
21
#include "MediaParserFfmpeg.h"
22
22
#include "GnashException.h"
24
#include "IOChannel.h"
24
#include "IOChannel.h"
26
//#define GNASH_ALLOW_VCODEC_ENV 1
27
// Set this to enable a special GNASH_DEFAULT_VCODEC environment variable, which
28
// is used as a default when the video codec can't be detected. This is a quick
29
// hack to make MJPEG HTTP videos work (which can't be detected as their MIME
30
// type is just "mixed/multipart"). Perhaps the codec will be configurable via
31
// ActionScript sometime. - Udo
56
63
MediaParserFfmpeg::probeStream()
58
boost::scoped_array<boost::uint8_t> buffer(new boost::uint8_t[2048]);
65
const size_t probeSize = 2048;
66
const size_t bufSize = probeSize + FF_INPUT_BUFFER_PADDING_SIZE;
60
// Probe the file to detect the format
61
AVProbeData probe_data;
62
probe_data.filename = "";
63
probe_data.buf = buffer.get();
64
probe_data.buf_size = 2048;
68
boost::scoped_array<boost::uint8_t> buffer(new boost::uint8_t[bufSize]);
66
70
assert(_stream->tell() == static_cast<std::streampos>(0));
67
size_t actuallyRead = _stream->read(probe_data.buf, probe_data.buf_size);
71
size_t actuallyRead = _stream->read(buffer.get(), probeSize);
73
// Fill any padding with 0s.
74
std::fill(buffer.get() + actuallyRead, buffer.get() + bufSize, 0);
70
78
if (actuallyRead < 1)
72
80
throw IOException(_("MediaParserFfmpeg could not read probe data "
77
probe_data.buf_size = actuallyRead; // right ?
78
AVInputFormat* ret = av_probe_input_format(&probe_data, 1);
84
// Probe the file to detect the format
85
AVProbeData probe_data;
86
probe_data.filename = "";
87
probe_data.buf = buffer.get();
88
probe_data.buf_size = actuallyRead;
90
AVInputFormat* ret = av_probe_input_format(&probe_data, 1);
323
335
_byteIOCxt.buffer = NULL;
325
337
_inputFmt = probeStream();
338
#ifdef GNASH_ALLOW_VCODEC_ENV
341
char* defcodec = getenv("GNASH_DEFAULT_VCODEC");
342
if (defcodec && strlen(defcodec))
343
_inputFmt = av_find_input_format(defcodec);
326
347
if ( ! _inputFmt )
328
349
throw MediaException("MediaParserFfmpeg couldn't figure out input "
521
542
else if (whence == SEEK_CUR)
523
_stream->seek(_stream->tell() + offset);
544
_stream->seek(_stream->tell() + static_cast<std::streamoff>(offset));
524
545
// New position is offset + end of file
526
547
else if (whence == SEEK_END)