~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to libmedia/ffmpeg/MediaParserFfmpeg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "MediaParserFfmpeg.h"
22
22
#include "GnashException.h"
23
23
#include "log.h"
24
 
#include "IOChannel.h" 
 
24
#include "IOChannel.h"
 
25
 
 
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 
25
32
 
26
33
namespace gnash {
27
34
namespace media {
55
62
AVInputFormat*
56
63
MediaParserFfmpeg::probeStream()
57
64
{
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;
59
67
 
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]);
65
69
 
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);
 
72
    
 
73
    // Fill any padding with 0s.
 
74
    std::fill(buffer.get() + actuallyRead, buffer.get() + bufSize, 0);
 
75
 
68
76
        _stream->seek(0);
69
77
 
70
78
        if (actuallyRead < 1)
71
79
        {
72
80
                throw IOException(_("MediaParserFfmpeg could not read probe data "
73
81
                    "from input"));
74
 
                return 0;
75
82
        }
76
83
 
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;
 
89
        
 
90
    AVInputFormat* ret = av_probe_input_format(&probe_data, 1);
79
91
        return ret;
80
92
}
81
93
 
323
335
        _byteIOCxt.buffer = NULL;
324
336
 
325
337
        _inputFmt = probeStream();
 
338
#ifdef GNASH_ALLOW_VCODEC_ENV   
 
339
        if ( ! _inputFmt )
 
340
        {
 
341
          char* defcodec = getenv("GNASH_DEFAULT_VCODEC");
 
342
          if (defcodec && strlen(defcodec))
 
343
      _inputFmt = av_find_input_format(defcodec);       
 
344
 
 
345
  }
 
346
#endif  
326
347
        if ( ! _inputFmt )
327
348
        {
328
349
                throw MediaException("MediaParserFfmpeg couldn't figure out input "
520
541
        }
521
542
        else if (whence == SEEK_CUR)
522
543
        {
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
525
546
        }
526
547
        else if (whence == SEEK_END)