fix autodetection of the graphics driver.
[gnash.git] / libmedia / MediaHandler.cpp
blob73d46d81e4913cc8bd383b9a054a79240a935fca
1 // MediaHandler.cpp: Default MediaHandler implementation, for Gnash.
2 //
3 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifdef HAVE_CONFIG_H
22 #include "gnashconfig.h"
23 #endif
25 #include "MediaHandler.h"
26 #include "FLVParser.h"
27 #include "IOChannel.h"
28 #include "AudioDecoderSimple.h"
29 #include "log.h"
31 #ifdef DECODING_SPEEX
32 # include "AudioDecoderSpeex.h"
33 #endif
35 namespace gnash {
36 namespace media {
38 std::auto_ptr<MediaHandler> MediaHandler::_handler;
40 bool
41 MediaHandler::isFLV(IOChannel& stream) throw (IOException)
43 char head[4] = {0, 0, 0, 0};
44 stream.seek(0);
45 size_t actuallyRead = stream.read(head, 3);
46 stream.seek(0);
48 if (actuallyRead < 3)
50 throw IOException(_("MediaHandler::isFLV: Could not read 3 bytes "
51 "from input stream"));
54 if (!std::equal(head, head + 3, "FLV")) return false;
55 return true;
58 std::auto_ptr<MediaParser>
59 MediaHandler::createMediaParser(std::auto_ptr<IOChannel> stream)
61 std::auto_ptr<MediaParser> parser;
63 try {
64 if (!isFLV(*stream))
66 log_error(_("MediaHandler::createMediaParser: only FLV input is "
67 "supported by this MediaHandler"));
68 return parser;
71 catch (IOException& m) {
72 log_error(_("Exception while reading from stream: %s"), m.what());
73 return parser;
76 parser.reset( new FLVParser(stream) );
77 assert(!stream.get()); // TODO: when ownership will be transferred...
79 return parser;
82 std::auto_ptr<AudioDecoder>
83 MediaHandler::createFlashAudioDecoder(const AudioInfo& info)
85 assert ( info.type == FLASH );
87 audioCodecType codec = static_cast<audioCodecType>(info.codec);
88 switch (codec)
90 case media::AUDIO_CODEC_ADPCM:
91 case media::AUDIO_CODEC_RAW:
93 std::auto_ptr<AudioDecoder> ret(new AudioDecoderSimple(info));
94 return ret;
97 #ifdef DECODING_SPEEX
98 case AUDIO_CODEC_SPEEX:
100 std::auto_ptr<AudioDecoder> ret(new AudioDecoderSpeex);
101 return ret;
103 #endif
105 default:
107 boost::format err = boost::format(
108 _("MediaHandler::createFlashAudioDecoder:"
109 " no available FLASH decoders for codec %d (%s)")) %
110 (int)codec % codec;
111 throw MediaException(err.str());
117 } // end of gnash::media namespace
118 } // end of gnash namespace