Fix test for bug #32625
[gnash.git] / libmedia / ffmpeg / MediaHandlerFfmpeg.cpp
blob035d55be5158a6092c66f949f5a3e814efb662d4
1 // MediaHandlerFfmpeg.cpp: FFMPEG media handler, 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 #include "MediaHandlerFfmpeg.h"
23 #include <sstream>
25 #include "MediaParser.h"
26 #include "MediaParserFfmpeg.h"
27 #include "VideoDecoderFfmpeg.h"
28 #include "AudioDecoderFfmpeg.h"
29 #include "GnashException.h"
30 #include "FLVParser.h"
31 #include "VideoConverterFfmpeg.h"
32 #include "VideoInputFfmpeg.h"
33 #include "AudioInputFfmpeg.h"
34 #include "IOChannel.h"
36 namespace gnash {
37 namespace media {
38 namespace ffmpeg {
40 std::string
41 MediaHandlerFfmpeg::description() const
43 std::ostringstream ss;
44 const boost::uint32_t ver = avcodec_version();
45 ss << "FFmpeg (avcodec version: " << (ver >> 16) << "."
46 << (ver & 0xff00 >> 8) << "."
47 << (ver & 0xff) << ")";
48 return ss.str();
51 std::auto_ptr<MediaParser>
52 MediaHandlerFfmpeg::createMediaParser(std::auto_ptr<IOChannel> stream)
54 std::auto_ptr<MediaParser> parser;
56 try {
57 if (isFLV(*stream))
59 parser.reset(new FLVParser(stream));
61 else
63 parser.reset(new MediaParserFfmpeg(stream));
66 catch (GnashException& ex)
68 log_error("Could not create FFMPEG based media parser for "
69 "input stream: %s", ex.what());
70 assert(!parser.get());
73 return parser;
76 std::auto_ptr<VideoDecoder>
77 MediaHandlerFfmpeg::createVideoDecoder(const VideoInfo& info)
79 std::auto_ptr<VideoDecoder> ret(new VideoDecoderFfmpeg(info));
80 return ret;
83 std::auto_ptr<VideoConverter>
84 MediaHandlerFfmpeg::createVideoConverter(ImgBuf::Type4CC srcFormat,
85 ImgBuf::Type4CC dstFormat)
87 std::auto_ptr<VideoConverter> converter;
89 try
91 converter.reset(new VideoConverterFfmpeg(srcFormat, dstFormat));
93 catch (GnashException& ex)
95 log_error("Could not create Ffmpeg based video converter parser for "
96 "input format: %s", ex.what());
99 return converter;
103 std::auto_ptr<AudioDecoder>
104 MediaHandlerFfmpeg::createAudioDecoder(const AudioInfo& info)
107 std::auto_ptr<AudioDecoder> ret;
109 try {
110 ret.reset(new AudioDecoderFfmpeg(info));
112 catch (const MediaException& ex) {
114 if (info.type != CODEC_TYPE_FLASH) throw;
116 try {
117 ret = createFlashAudioDecoder(info);
119 catch (const MediaException& ex2) {
120 boost::format err = boost::format(
121 _("MediaHandlerFfmpeg::createAudioDecoder: %s "
122 "-- %s")) % ex.what() % ex2.what();
123 throw MediaException(err.str());
127 return ret;
130 AudioInput*
131 MediaHandlerFfmpeg::getAudioInput(size_t /*index*/)
133 return new AudioInputFfmpeg();
136 VideoInput*
137 MediaHandlerFfmpeg::getVideoInput(size_t /*index*/)
139 return new VideoInputFfmpeg();
142 void
143 MediaHandlerFfmpeg::cameraNames(std::vector<std::string>& /*names*/) const
145 log_unimpl("FFmpeg: camera names");
148 size_t
149 MediaHandlerFfmpeg::getInputPaddingSize() const
151 return FF_INPUT_BUFFER_PADDING_SIZE;
154 } // gnash.media.ffmpeg namespace
155 } // gnash.media namespace
156 } // gnash namespace