1 // MediaHandlerFfmpeg.cpp: FFMPEG media handler, for Gnash
3 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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.
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"
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"
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) << ")";
51 std::auto_ptr
<MediaParser
>
52 MediaHandlerFfmpeg::createMediaParser(std::auto_ptr
<IOChannel
> stream
)
54 std::auto_ptr
<MediaParser
> parser
;
59 parser
.reset(new FLVParser(stream
));
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());
76 std::auto_ptr
<VideoDecoder
>
77 MediaHandlerFfmpeg::createVideoDecoder(const VideoInfo
& info
)
79 std::auto_ptr
<VideoDecoder
> ret(new VideoDecoderFfmpeg(info
));
83 std::auto_ptr
<VideoConverter
>
84 MediaHandlerFfmpeg::createVideoConverter(ImgBuf::Type4CC srcFormat
,
85 ImgBuf::Type4CC dstFormat
)
87 std::auto_ptr
<VideoConverter
> converter
;
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());
103 std::auto_ptr
<AudioDecoder
>
104 MediaHandlerFfmpeg::createAudioDecoder(const AudioInfo
& info
)
107 std::auto_ptr
<AudioDecoder
> ret
;
110 ret
.reset(new AudioDecoderFfmpeg(info
));
112 catch (const MediaException
& ex
) {
114 if (info
.type
!= CODEC_TYPE_FLASH
) throw;
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());
131 MediaHandlerFfmpeg::getAudioInput(size_t /*index*/)
133 return new AudioInputFfmpeg();
137 MediaHandlerFfmpeg::getVideoInput(size_t /*index*/)
139 return new VideoInputFfmpeg();
143 MediaHandlerFfmpeg::cameraNames(std::vector
<std::string
>& /*names*/) const
145 log_unimpl("FFmpeg: camera names");
149 MediaHandlerFfmpeg::getInputPaddingSize() const
151 return FF_INPUT_BUFFER_PADDING_SIZE
;
154 } // gnash.media.ffmpeg namespace
155 } // gnash.media namespace