root/OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp @ 9885

Revision 9885, 2.7 kB (checked in by robert, 5 years ago)

Added copyright + fixed typo

RevLine 
[9885]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
[9816]13
14#include <osgDB/Registry>
15#include <osgDB/FileNameUtils>
16#include <osgDB/FileUtils>
17
18#include "FFmpegHeaders.hpp"
19#include "FFmpegImageStream.hpp"
20
21
22
23/** Implementation heavily inspired by http://www.dranger.com/ffmpeg/ */
24
25class ReaderWriterFFmpeg : public osgDB::ReaderWriter
26{
27public:
28
29    ReaderWriterFFmpeg()
30    {
[9885]31        supportsProtocol("http","Read video/audio from http using ffmpeg.");
32
[9816]33        supportsExtension("avi", "");
34        supportsExtension("flv", "");
35        supportsExtension("mov", "");
[9838]36        supportsExtension("ogg", "Theora movie format");
[9816]37        supportsExtension("mpg", "Mpeg movie format");
38        supportsExtension("mpv", "Mpeg movie format");
39        supportsExtension("wmv", "");
40
41        // Register all FFmpeg formats/codecs
42        av_register_all();
43    }
44
45    virtual ~ReaderWriterFFmpeg()
46    {
47
48    }
49
50    virtual const char * className() const
51    {
52        return "ReaderWriterFFmpeg";
53    }
54
55    virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options * options) const
56    {
[9865]57        if (filename.compare(0, 5, "/dev/")==0)
58        {
59            return readImageStream(filename, options);
60        }
61   
[9816]62        const std::string ext = osgDB::getLowerCaseFileExtension(filename);
63        if (! acceptsExtension(ext))
64            return ReadResult::FILE_NOT_HANDLED;
65
[9854]66        const std::string path = osgDB::containsServerAddress(filename) ?
67            filename :
68            osgDB::findDataFile(filename, options);
[9816]69
70        if (path.empty())
71            return ReadResult::FILE_NOT_FOUND;
72
[9865]73        return readImageStream(filename, options);
74    }
75   
76    ReadResult readImageStream(const std::string& filename, const osgDB::ReaderWriter::Options * options) const
77    {
78        osg::notify(osg::INFO) << "ReaderWriterFFmpeg::readImage " << filename << std::endl;
[9816]79
80        osg::ref_ptr<osgFFmpeg::FFmpegImageStream> image_stream(new osgFFmpeg::FFmpegImageStream);
81
[9865]82        if (! image_stream->open(filename))
[9816]83            return ReadResult::FILE_NOT_HANDLED;
84
85        return image_stream.release();
86    }
87
88private:
89
90};
91
92
93
94REGISTER_OSGPLUGIN(ffmpeg, ReaderWriterFFmpeg)
Note: See TracBrowser for help on using the browser.